__init__.py 7.4 KB

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