__init__.py 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. # -*- coding: utf-8 -*-
  2. import pygame
  3. import validators
  4. from UI.constants import Width,Height,ICON_TYPES
  5. from UI.simple_name_space import SimpleNamespace
  6. from UI.page import Page
  7. from UI.label import Label
  8. from UI.fonts import fonts
  9. from UI.icon_item import IconItem
  10. from UI.icon_pool import MyIconPool
  11. from UI.keys_def import CurKeys
  12. from UI.skin_manager import SkinManager
  13. from libs.DBUS import is_wifi_connected_now,get_wifi_ip
  14. class TinyCloudPage(Page):
  15. _FootMsg = ["Nav.","","","Back",""]
  16. _MyList = []
  17. _ListFontObj = fonts["varela13"]
  18. _AList = {}
  19. _Labels = {}
  20. _Coords = {}
  21. _URLColor = SkinManager().GiveColor('URL')
  22. _TextColor = SkinManager().GiveColor('Text')
  23. _Scrolled = 0
  24. _PngSize = {}
  25. _DrawOnce = False
  26. _Scroller = None
  27. _Scrolled = 0
  28. def __init__(self):
  29. Page.__init__(self)
  30. self._Icons = {}
  31. def OnLoadCb(self):
  32. self._Scrolled = 0
  33. self._PosY = 0
  34. self._DrawOnce = False
  35. def SetCoords(self):
  36. self._Coords["forID"] = SimpleNamespace()
  37. self._Coords["forID"].x = 15
  38. self._Coords["forID"].y = 11
  39. self._Coords["forKey"] = SimpleNamespace()
  40. self._Coords["forKey"].x = 71
  41. self._Coords["forKey"].y = self._Coords["forID"].y
  42. self._Coords["key_and_pass"] = SimpleNamespace()
  43. self._Coords["key_and_pass"].x = 36 # 141
  44. self._Coords["key_and_pass"].y = self._Coords["forID"].y
  45. self._Coords["forssh"] = SimpleNamespace()
  46. self._Coords["forssh"].x = self._Coords["forID"].x
  47. self._Coords["forssh"].y = 47
  48. self._Coords["ssh_addr"] = SimpleNamespace()
  49. self._Coords["ssh_addr"].x = self._Coords["forID"].x
  50. self._Coords["ssh_addr"].y = 65
  51. self._Coords["forwin"] = SimpleNamespace()
  52. self._Coords["forwin"].x = self._Coords["forID"].x
  53. self._Coords["forwin"].y = 101
  54. self._Coords["samba_games"] = SimpleNamespace()
  55. self._Coords["samba_games"].x = self._Coords["forID"].x
  56. self._Coords["samba_games"].y = 118
  57. self._Coords["samba_music"] = SimpleNamespace()
  58. self._Coords["samba_music"].x = self._Coords["samba_games"].x
  59. self._Coords["samba_music"].y = 136
  60. self._Coords["for_airplay"] = SimpleNamespace()
  61. self._Coords["for_airplay"].x = self._Coords["forID"].x
  62. self._Coords["for_airplay"].y = 173
  63. self._Coords["airplay_name"] = SimpleNamespace()
  64. self._Coords["airplay_name"].x = 68
  65. self._Coords["airplay_name"].y = self._Coords["for_airplay"].y
  66. self._Coords["bg"] = SimpleNamespace()
  67. self._Coords["bg"].x = self._Width/2
  68. self._Coords["bg"].y = self._Height/2
  69. self._Coords["online"] = SimpleNamespace()
  70. self._Coords["online"].x = 266
  71. self._Coords["online"].y = 99
  72. def SetLabels(self):
  73. if is_wifi_connected_now():
  74. self._IP = get_wifi_ip()
  75. print("TinyCould : %s" % self._IP)
  76. try:
  77. if validators.ip_address.ipv4(self._IP) == False:
  78. self._IP = "xxx.xxx.xxx.xxx"
  79. except:
  80. print("ip error %s " % self._IP)
  81. self._IP = "xxx.xxx.xxx.xxx"
  82. else:
  83. self._IP = "xxx.xxx.xxx.xxx"
  84. labels = \
  85. [["forssh","For ssh and scp:",self._ListFontObj,self._TextColor],
  86. ["ssh_addr","ssh cpi@%s" % self._IP, self._ListFontObj,self._URLColor],
  87. ["forwin", "For Windows network:", self._ListFontObj, self._TextColor],
  88. ["samba_games", "\\\\%s\games" % self._IP, self._ListFontObj,self._URLColor],
  89. ["samba_music", "\\\\%s\music" % self._IP, self._ListFontObj,self._URLColor],
  90. ["forID", "ID:", self._ListFontObj, self._TextColor],
  91. ["forKey", "Key:", self._ListFontObj, self._TextColor],
  92. ["key_and_pass", "cpi", self._ListFontObj, self._URLColor],
  93. ["for_airplay", "Airplay:", self._ListFontObj, self._TextColor],
  94. ["airplay_name","clockworkpi", self._ListFontObj, self._URLColor]]
  95. for i in labels:
  96. l = Label()
  97. l.SetCanvasHWND(self._CanvasHWND)
  98. l.Init(i[1],i[2])
  99. l.SetColor(i[3])
  100. self._Labels[ i[0] ] = l
  101. self.SetCoords() ##
  102. def Init(self):
  103. if self._Screen != None:
  104. if self._Screen._CanvasHWND != None and self._CanvasHWND == None:
  105. self._HWND = self._Screen._CanvasHWND
  106. self._CanvasHWND = pygame.Surface( (self._Screen._Width,self._Screen._Height) )
  107. self._PosX = self._Index*self._Screen._Width
  108. self._Width = self._Screen._Width ## equal to screen width
  109. self._Height = self._Screen._Height
  110. self._PngSize["bg"] = (253,132)
  111. self._PngSize["online"] = (75,122)
  112. bgpng = IconItem()
  113. bgpng._ImgSurf = MyIconPool._Icons["needwifi_bg"]
  114. bgpng._MyType = ICON_TYPES["STAT"]
  115. bgpng._Parent = self
  116. bgpng.Adjust(0,0,self._PngSize["bg"][0],self._PngSize["bg"][1],0)
  117. self._Icons["bg"] = bgpng
  118. onlinepng = IconItem()
  119. onlinepng._ImgSurf = MyIconPool._Icons["online"]
  120. onlinepng._MyType = ICON_TYPES["STAT"]
  121. onlinepng._Parent = self
  122. onlinepng.Adjust(0,0,self._PngSize["online"][0], self._PngSize["online"][1],0)
  123. self._Icons["online"] = onlinepng
  124. self.SetLabels()
  125. def KeyDown(self,event):
  126. if event.key == CurKeys["A"] or event.key == CurKeys["Menu"]:
  127. if self._FootMsg[3] == "Back":
  128. self.ReturnToUpLevelPage()
  129. self._Screen.Draw()
  130. self._Screen.SwapAndShow()
  131. return
  132. def Draw(self):
  133. if self._DrawOnce == False:
  134. self.ClearCanvas()
  135. if is_wifi_connected_now():
  136. self._Icons["online"].NewCoord(self._Coords["online"].x, self._Coords["online"].y)
  137. self._Icons["online"].Draw()
  138. self.SetLabels()
  139. for i in self._Labels:
  140. if i in self._Coords:
  141. self._Labels[i].NewCoord( self._Coords[i].x, self._Coords[i].y)
  142. self._Labels[i].Draw()
  143. self._Labels["key_and_pass"].NewCoord( 103,self._Coords["key_and_pass"].y)
  144. self._Labels["key_and_pass"].Draw()
  145. else:
  146. self._Icons["bg"].NewCoord(self._Coords["bg"].x, self._Coords["bg"].y)
  147. self._Icons["bg"].Draw()
  148. self._DrawOnce = True
  149. if self._HWND != None:
  150. self._HWND.fill(SkinManager().GiveColor('White'))
  151. self._HWND.blit(self._CanvasHWND,(self._PosX,self._PosY,self._Width, self._Height ) )
  152. class APIOBJ(object):
  153. _Page = None
  154. def __init__(self):
  155. pass
  156. def Init(self,main_screen):
  157. self._Page = TinyCloudPage()
  158. self._Page._Screen = main_screen
  159. self._Page._Name ="Tiny cloud"
  160. self._Page.Init()
  161. def API(self,main_screen):
  162. if main_screen !=None:
  163. main_screen.PushPage(self._Page)
  164. main_screen.Draw()
  165. main_screen.SwapAndShow()
  166. OBJ = APIOBJ()
  167. def Init(main_screen):
  168. OBJ.Init(main_screen)
  169. def API(main_screen):
  170. OBJ.API(main_screen)