Browse Source

Reverse set of file to their upstream version

Godzil 5 years ago
parent
commit
91ac4bb81e
100 changed files with 2971 additions and 2624 deletions
  1. 3 17
      Menu/GameShell/10_Settings/About/__init__.py
  2. 4 4
      Menu/GameShell/10_Settings/Brightness/__init__.py
  3. 65 51
      Menu/GameShell/10_Settings/Brightness/brightness_page.py
  4. 3 0
      Menu/GameShell/10_Settings/Brightness/myvars.py
  5. 3 2
      Menu/GameShell/10_Settings/Brightness/pages.py
  6. 29 28
      Menu/GameShell/10_Settings/PowerOFF/__init__.py
  7. 4 4
      Menu/GameShell/10_Settings/Sound/__init__.py
  8. 3 0
      Menu/GameShell/10_Settings/Sound/myvars.py
  9. 3 2
      Menu/GameShell/10_Settings/Sound/pages.py
  10. 63 46
      Menu/GameShell/10_Settings/Sound/sound_page.py
  11. 65 60
      Menu/GameShell/10_Settings/Storage/__init__.py
  12. 119 109
      Menu/GameShell/10_Settings/Update/__init__.py
  13. 4 6
      Menu/GameShell/10_Settings/Wifi/__init__.py
  14. 126 122
      Menu/GameShell/10_Settings/Wifi/keyboard.py
  15. 76 69
      Menu/GameShell/10_Settings/Wifi/net_item.py
  16. 1 0
      Menu/GameShell/10_Settings/Wifi/pages.py
  17. 9 10
      Menu/GameShell/10_Settings/Wifi/text_item.py
  18. 1 0
      Menu/GameShell/10_Settings/Wifi/textarea.py
  19. 253 238
      Menu/GameShell/10_Settings/Wifi/wifi_list.py
  20. 17 6
      Menu/GameShell/10_Settings/__init__.py
  21. 25 13
      Menu/GameShell/10_Settings/list_item.py
  22. 64 55
      Menu/GameShell/10_Settings/list_page.py
  23. 4 1
      Menu/GameShell/10_Settings/myvars.py
  24. 4 4
      Menu/GameShell/10_Settings/pages.py
  25. 0 1
      Menu/GameShell/CaveStory.sh
  26. 9 6
      Menu/GameShell/Music Player/__init__.py
  27. 57 51
      Menu/GameShell/Music Player/list_item.py
  28. 106 88
      Menu/GameShell/Music Player/mpd_spectrum_page.py
  29. 105 93
      Menu/GameShell/Music Player/music_lib_list_page.py
  30. 4 1
      Menu/GameShell/Music Player/myvars.py
  31. 16 17
      Menu/GameShell/Music Player/pages.py
  32. 85 74
      Menu/GameShell/Music Player/play_list_page.py
  33. 29 28
      Menu/GameShell/PowerOFF/__init__.py
  34. 1 2
      Menu/GameShell/RetroArch.sh
  35. 74 74
      Menu/GameShell/TinyCloud/__init__.py
  36. 0 1
      Menu/GameShell/freeDM.sh
  37. 0 0
      skin/default/Menu/GameShell/20_Retro Games/MAME.png
  38. 0 0
      skin/default/Menu/GameShell/20_Retro Games/MGBA.png
  39. 0 0
      skin/default/Menu/GameShell/20_Retro Games/NESTOPIA.png
  40. 0 0
      skin/default/Menu/GameShell/CaveStory.png
  41. 0 0
      skin/default/Menu/GameShell/Music Player.png
  42. 0 0
      skin/default/Menu/GameShell/PowerOFF.png
  43. 0 0
      skin/default/Menu/GameShell/Retro Games.png
  44. 0 0
      skin/default/Menu/GameShell/RetroArch.png
  45. 0 0
      skin/default/Menu/GameShell/Settings.png
  46. 0 0
      skin/default/Menu/GameShell/Sleep.png
  47. 0 0
      skin/default/Menu/GameShell/TinyCloud.png
  48. 0 0
      skin/default/Menu/GameShell/freeDM.png
  49. 2 12
      skin/default/config.cfg
  50. 0 0
      skin/default/sys.py/gameshell/blank.png
  51. 0 0
      skin/default/sys.py/gameshell/footbar_icons/footbar.png
  52. 0 0
      skin/default/sys.py/gameshell/icons/_L.png
  53. 0 0
      skin/default/sys.py/gameshell/icons/_R.png
  54. 0 0
      skin/default/sys.py/gameshell/icons/about_bg.png
  55. 0 0
      skin/default/sys.py/gameshell/icons/blueselector.png
  56. 0 0
      skin/default/sys.py/gameshell/icons/done.png
  57. 0 0
      skin/default/sys.py/gameshell/icons/empty.png
  58. 0 0
      skin/default/sys.py/gameshell/icons/heart.png
  59. 0 0
      skin/default/sys.py/gameshell/icons/icon_sd.png
  60. 0 0
      skin/default/sys.py/gameshell/icons/light.png
  61. 0 0
      skin/default/sys.py/gameshell/icons/lock.png
  62. 0 0
      skin/default/sys.py/gameshell/icons/needwifi_bg.png
  63. 0 0
      skin/default/sys.py/gameshell/icons/online.png
  64. 0 0
      skin/default/sys.py/gameshell/icons/rom_download.png
  65. 0 0
      skin/default/sys.py/gameshell/icons/roundcorners.png
  66. 0 0
      skin/default/sys.py/gameshell/icons/scale.png
  67. 0 0
      skin/default/sys.py/gameshell/icons/star.png
  68. 0 0
      skin/default/sys.py/gameshell/icons/sys.png
  69. 0 0
      skin/default/sys.py/gameshell/icons/vol.png
  70. 0 0
      skin/default/sys.py/gameshell/titlebar_icons/battery_unknown.png
  71. 0 0
      skin/default/sys.py/gameshell/titlebar_icons/soundvolume.png
  72. 0 0
      skin/default/sys.py/gameshell/titlebar_icons/wifi.png
  73. 0 0
      skin/default/sys.py/gameshell/titlebar_icons/withcharging.png
  74. 0 0
      skin/default/sys.py/gameshell/titlebar_icons/without_charging.png
  75. 39 32
      sys.py/UI/Emulator/__init__.py
  76. 138 125
      sys.py/UI/Emulator/fav_list_page.py
  77. 3 9
      sys.py/UI/Emulator/list_item.py
  78. 156 139
      sys.py/UI/Emulator/rom_list_page.py
  79. 37 28
      sys.py/UI/Emulator/rom_so_confirm_page.py
  80. 0 0
      sys.py/UI/__init__.py
  81. 57 45
      sys.py/UI/above_all_patch.py
  82. 76 68
      sys.py/UI/confirm_page.py
  83. 28 14
      sys.py/UI/constants.py
  84. 33 24
      sys.py/UI/delete_confirm_page.py
  85. 48 50
      sys.py/UI/download.py
  86. 18 12
      sys.py/UI/download_process_page.py
  87. 52 44
      sys.py/UI/fonts.py
  88. 89 87
      sys.py/UI/foot_bar.py
  89. 49 49
      sys.py/UI/icon_item.py
  90. 12 11
      sys.py/UI/icon_pool.py
  91. 39 18
      sys.py/UI/keys_def.py
  92. 57 0
      sys.py/UI/label.py
  93. 205 194
      sys.py/UI/main_screen.py
  94. 25 25
      sys.py/UI/multi_icon_item.py
  95. 37 36
      sys.py/UI/multilabel.py
  96. 260 247
      sys.py/UI/page.py
  97. 31 32
      sys.py/UI/scroller.py
  98. 1 0
      sys.py/UI/simple_name_space.py
  99. 30 30
      sys.py/UI/skin_manager.py
  100. 15 10
      sys.py/UI/slider.py

+ 3 - 17
Menu/GameShell/10_Settings/About/__init__.py

@@ -5,35 +5,21 @@ import pygame
 import subprocess
 
 #from beeprint import pp
+from libs.roundrects import aa_round_rect
 #import gobject
 #from wicd import misc 
 ## local UI import
 from UI.constants import Width,Height,ICON_TYPES
-from UI.page   import Page
+from UI.page   import Page,PageSelector
 from UI.label  import Label
 from UI.fonts  import fonts
+from UI.util_funcs import midRect
 from UI.keys_def   import CurKeys
 from UI.scroller   import ListScroller
 from UI.icon_pool  import MyIconPool
 from UI.icon_item  import IconItem
 from UI.multilabel import MultiLabel
-# import math
-import subprocess
 
-import pygame
-# from beeprint import pp
-# import gobject
-# from wicd import misc
-## local UI import
-from UI.constants import Width, Height, ICON_TYPES
-from UI.fonts import fonts
-from UI.icon_item import IconItem
-from UI.icon_pool import MyIconPool
-from UI.keys_def import CurKeys
-from UI.label import Label
-from UI.multilabel import MultiLabel
-from UI.page import Page
-from UI.scroller import ListScroller
 
 
 class InfoPageListItem(object):

+ 4 - 4
Menu/GameShell/10_Settings/Brightness/__init__.py

@@ -1,17 +1,17 @@
 # -*- coding: utf-8 -*- 
 
-import myvars
 ## local UI import
 import pages
-
+import myvars
 
 def Init(main_screen):
     pages.InitBrightnessPage(main_screen)
 
-
 def API(main_screen):
-    if main_screen != None:
+    
+    if main_screen !=None:
         main_screen.PushCurPage()
         main_screen.SetCurPage(myvars.BrightnessPage)
         main_screen.Draw()
         main_screen.SwapAndShow()
+        

+ 65 - 51
Menu/GameShell/10_Settings/Brightness/brightness_page.py

@@ -1,69 +1,75 @@
-# -*- coding: utf-8 -*-
+# -*- coding: utf-8 -*- 
 
+import pygame
 
-# import math
+
+#import math
 
 ## local UI import
-from UI.constants import ICON_TYPES
+from UI.constants import Width,Height,ICON_TYPES
+from UI.page   import Page,PageSelector
+from UI.label  import Label
 from UI.icon_item import IconItem
-from UI.icon_pool import MyIconPool
-from UI.keys_def import CurKeys
+from UI.fonts  import fonts
+from UI.util_funcs import midRect
+from UI.keys_def   import CurKeys
+from UI.slider     import Slider
+from UI.icon_pool  import MyIconPool
 from UI.multi_icon_item import MultiIconItem
-from UI.page import Page
-from UI.slider import Slider
 from config import BackLight
-
+import myvars
 
 class BSlider(Slider):
+
+    
     OnChangeCB = None
     _BGpng = None
     _BGwidth = 179
     _BGheight = 153
 
     _NeedleSurf = None
-    _Scale = None
-    _Parent = None
-    _Icons = {}
-
+    _Scale      = None
+    _Parent     = None
+    _Icons      = {}
+    
     def __init__(self):
         Slider.__init__(self)
         self._Icons = {}
-
     def Init(self):
         self._Width = self._Parent._Width
         self._Height = self._Parent._Height
-
+        
         bgpng = IconItem()
         bgpng._ImgSurf = MyIconPool._Icons["light"]
         bgpng._MyType = ICON_TYPES["STAT"]
         bgpng._Parent = self
-        bgpng.Adjust(0, 0, self._BGwidth, self._BGheight, 0)
+        bgpng.Adjust(0,0,self._BGwidth,self._BGheight,0)
         self._Icons["bg"] = bgpng
         ##self._NeedleSurf = pygame.Surface( (38,12),pygame.SRCALPHA )
-
+        
         scale = MultiIconItem()
         scale._MyType = ICON_TYPES["STAT"]
         scale._Parent = self
         scale._ImgSurf = MyIconPool._Icons["scale"]
         scale._IconWidth = 82
         scale._IconHeight = 63
-        scale.Adjust(0, 0, 82, 63, 0)
+        scale.Adjust(0,0,82,63,0)
         self._Icons["scale"] = scale
 
-    def SetValue(self, brt):
+    def SetValue(self,brt):
         self._Value = brt
-
+        
     def Further(self):
-        self._Value += 1
+        self._Value+=1
         if self._Value > 9:
             self._Value = 9
             
         if self.OnChangeCB != None:
             if callable(self.OnChangeCB):
                 self.OnChangeCB(self._Value)
-
+                    
     def StepBack(self):
-        self._Value -= 1
+        self._Value-=1
 
         if self._Value < 1:
             self._Value = 1
@@ -71,13 +77,13 @@ class BSlider(Slider):
         if self.OnChangeCB != None:
             if callable(self.OnChangeCB):
                 self.OnChangeCB(self._Value)
-
+    
     def Draw(self):
 
-        self._Icons["bg"].NewCoord(self._Width / 2, self._Height / 2 + 11)
+        self._Icons["bg"].NewCoord(self._Width/2,self._Height/2 +11 )
         self._Icons["bg"].Draw()
 
-        self._Icons["scale"].NewCoord(self._Width / 2, self._Height / 2)
+        self._Icons["scale"].NewCoord(self._Width/2,self._Height/2 )
 
         icon_idx = self._Value - 1
         if icon_idx < 0:
@@ -92,32 +98,35 @@ class BSlider(Slider):
         pygame.draw.circle(self._CanvasHWND,(255,255,255),( posx, self._PosY),7,0)        
         pygame.draw.circle(self._CanvasHWND,(0,0,0)      ,( posx, self._PosY),7,1)## outer border
         """
-
-
+        
+        
+        
 class BrightnessPage(Page):
+
     _MySlider = None
-    _FootMsg = ["Nav", "", "", "Back", "Enter"]
+    _FootMsg = ["Nav","","","Back","Enter"]
 
     
     def Init(self):
         self._CanvasHWND = self._Screen._CanvasHWND
-        self._Width = self._Screen._Width
+        self._Width =  self._Screen._Width
         self._Height = self._Screen._Height
-
+        
         self._MySlider = BSlider()
-        #        self._MySlider._Width = Width - 20
-        #        self._MySlider._Height = 30
-        #        self._MySlider._PosX  = (self._Width - self._MySlider._Width)/2
-        #        self._MySlider._PosY  = 40
+#        self._MySlider._Width = Width - 20
+#        self._MySlider._Height = 30
+#        self._MySlider._PosX  = (self._Width - self._MySlider._Width)/2
+#        self._MySlider._PosY  = 40
         self._MySlider._Parent = self
         self._MySlider.SetCanvasHWND(self._CanvasHWND)
         self._MySlider.OnChangeCB = self.WhenSliderDrag
         self._MySlider.Init()
 
-        brt = self.ReadBackLight()
-
-        self._MySlider.SetValue(brt)
+        brt  = self.ReadBackLight()
+        
+        self._MySlider.SetValue( brt)
 
+    
     def ReadBackLight(self):
         try:
             f = open(BackLight)
@@ -132,13 +141,13 @@ class BrightnessPage(Page):
         return 0
 
     def OnLoadCb(self):
-        brt = self.ReadBackLight()
+         brt  = self.ReadBackLight()
          
-        self._MySlider.SetValue(brt)
-
-    def SetBackLight(self, newbrt):
+         self._MySlider.SetValue( brt)
+         
+    def SetBackLight(self,newbrt):
         try:
-            f = open(BackLight, 'w')
+            f = open(BackLight,'w')
         except IOError:
             print("Open write %s failed %d" % (BackLight,newbrt))
             return False
@@ -146,28 +155,33 @@ class BrightnessPage(Page):
             with f:
                 f.write(str(newbrt))
                 return True
-
-    def WhenSliderDrag(self, value): ##value
+        
+    def WhenSliderDrag(self,value): ##value 
         self.SetBackLight(value)
-
-    def KeyDown(self, event):
-
+        
+    def KeyDown(self,event):
+        
         if event.key == CurKeys["Menu"] or event.key == CurKeys["A"]:
             self.ReturnToUpLevelPage()
             self._Screen.Draw()
             self._Screen.SwapAndShow()
-
+        
         if event.key == CurKeys["Right"]:
             self._MySlider.Further()
             self._Screen.Draw()
             self._Screen.SwapAndShow()
-
+            
         if event.key == CurKeys["Left"]:
             self._MySlider.StepBack()
             self._Screen.Draw()
             self._Screen.SwapAndShow()
-
+        
     def Draw(self):
         self.ClearCanvas()
-
+        
         self._MySlider.Draw()
+
+        
+
+
+    

+ 3 - 0
Menu/GameShell/10_Settings/Brightness/myvars.py

@@ -1,3 +1,6 @@
 # -*- coding: utf-8 -*- 
 
+import os
+import sys
+
 SoundPage = None

+ 3 - 2
Menu/GameShell/10_Settings/Brightness/pages.py

@@ -1,12 +1,13 @@
 # -*- coding: utf-8 -*- 
 
-import myvars
 from brightness_page import BrightnessPage
 
+import myvars
 
 def InitBrightnessPage(main_screen):
-    myvars.BrightnessPage = BrightnessPage()
 
+    myvars.BrightnessPage = BrightnessPage()
+    
     myvars.BrightnessPage._Screen = main_screen
     myvars.BrightnessPage._Name = "Brightness"
     myvars.BrightnessPage.Init()

+ 29 - 28
Menu/GameShell/10_Settings/PowerOFF/__init__.py

@@ -1,21 +1,24 @@
 # -*- coding: utf-8 -*- 
 
-import config
 import pygame
+
+#UI lib
+from UI.constants    import RUNSYS
+from UI.keys_def     import CurKeys
 from UI.confirm_page import ConfirmPage
-# UI lib
-from UI.constants import RUNSYS
-from UI.keys_def import CurKeys
 
+import config
 
 class PowerOffConfirmPage(ConfirmPage):
+    
     _ConfirmText = "Confirm Power OFF?"
+    
 
     def CheckBattery(self):
         try:
             f = open(config.Battery)
         except IOError:
-            print("PowerOFF open %s failed" % config.Battery)
+            print( "PowerOFF open %s failed" % config.Battery)
             return 0
         else:
             with f:
@@ -31,14 +34,15 @@ class PowerOffConfirmPage(ConfirmPage):
                     cur_cap = int(bat_uevent["POWER_SUPPLY_CAPACITY"])
                 else:
                     cur_cap = 0
-
+                
                 return cur_cap
-
+                    
         return 0
-
-    def KeyDown(self, event):
-
+        
+    def KeyDown(self,event):
+        
         if event.key == CurKeys["Menu"] or event.key == CurKeys["A"]:
+            
             self.ReturnToUpLevelPage()
             self._Screen.Draw()
             self._Screen.SwapAndShow()
@@ -48,41 +52,38 @@ class PowerOffConfirmPage(ConfirmPage):
                 cmdpath = "feh --bg-center gameshell/wallpaper/gameover.png;"
             else:
                 cmdpath = "feh --bg-center gameshell/wallpaper/seeyou.png;"
-
+            
             cmdpath += "sleep 3;"
-
-            # cmdpath += "echo 'halt -p' > /tmp/halt_cmd"
-
+            
+            #cmdpath += "echo 'halt -p' > /tmp/halt_cmd"
+            
             cmdpath += "sudo halt -p"
-            pygame.event.post(pygame.event.Event(RUNSYS, message=cmdpath))
+            pygame.event.post( pygame.event.Event(RUNSYS, message=cmdpath))
+
 
 
 class APIOBJ(object):
-    _StoragePage = None
 
+    _StoragePage = None
     def __init__(self):
         pass
-
-    def Init(self, main_screen):
+    def Init(self,main_screen):
         self._Page = PowerOffConfirmPage()
 
         self._Page._Screen = main_screen
-        self._Page._Name = "Power OFF"
+        self._Page._Name ="Power OFF"
         self._Page.Init()
-
-    def API(self, main_screen):
-        if main_screen != None:
+        
+        
+    def API(self,main_screen):
+        if main_screen !=None:
             main_screen.PushPage(self._Page)
             main_screen.Draw()
             main_screen.SwapAndShow()
 
-
 OBJ = APIOBJ()
-
-
-def Init(main_screen):
+def Init(main_screen):    
     OBJ.Init(main_screen)
-
-
 def API(main_screen):
     OBJ.API(main_screen)
+    

+ 4 - 4
Menu/GameShell/10_Settings/Sound/__init__.py

@@ -1,17 +1,17 @@
 # -*- coding: utf-8 -*- 
 
-import myvars
 ## local UI import
 import pages
-
+import myvars
 
 def Init(main_screen):
     pages.InitSoundPage(main_screen)
 
-
 def API(main_screen):
-    if main_screen != None:
+    
+    if main_screen !=None:
         main_screen.PushCurPage()
         main_screen.SetCurPage(myvars.SoundPage)
         main_screen.Draw()
         main_screen.SwapAndShow()
+        

+ 3 - 0
Menu/GameShell/10_Settings/Sound/myvars.py

@@ -1,3 +1,6 @@
 # -*- coding: utf-8 -*- 
 
+import os
+import sys
+
 SoundPage = None

+ 3 - 2
Menu/GameShell/10_Settings/Sound/pages.py

@@ -1,12 +1,13 @@
 # -*- coding: utf-8 -*- 
 
-import myvars
 from sound_page import SoundPage
 
+import myvars
 
 def InitSoundPage(main_screen):
-    myvars.SoundPage = SoundPage()
 
+    myvars.SoundPage = SoundPage()
+    
     myvars.SoundPage._Screen = main_screen
     myvars.SoundPage._Name = "Sound volume"
     myvars.SoundPage.Init()

+ 63 - 46
Menu/GameShell/10_Settings/Sound/sound_page.py

@@ -1,63 +1,72 @@
 # -*- coding: utf-8 -*- 
 
-# from libs.roundrects import aa_round_rect
+import pygame
+
+#from libs.roundrects import aa_round_rect
 
 import alsaaudio
+
 ## local UI import
-from UI.constants import ICON_TYPES
+from UI.constants import Width,Height,ICON_TYPES
+from UI.page   import Page,PageSelector
 from UI.icon_item import IconItem
-from UI.icon_pool import MyIconPool
-from UI.keys_def import CurKeys
+from UI.label  import Label
+from UI.fonts  import fonts
+from UI.util_funcs import midRect
+from UI.keys_def   import CurKeys
+from UI.slider     import Slider
 from UI.multi_icon_item import MultiIconItem
-from UI.page import Page
-from UI.slider import Slider
 
 
+from UI.icon_pool  import MyIconPool
+
+import myvars
+
 class SoundSlider(Slider):
     OnChangeCB = None
-
+    
     _BGpng = None
     _BGwidth = 192
     _BGheight = 173
 
     _NeedleSurf = None
-    _Scale = None
-    _Parent = None
+    _Scale      = None
+    _Parent     = None
     
-    snd_segs = [[0, 20], [21, 40], [41, 50], [51, 60], [61, 70], [71, 85], [86, 90], [91, 95], [96, 100]]
+    snd_segs = [ [0,20],[21,40],[41,50],[51,60],[61,70],[71,85],[86,90],[91,95],[96,100] ]
 
     
     def __init__(self):
         Slider.__init__(self)
-
+        
     def Init(self):
         self._Width = self._Parent._Width
         self._Height = self._Parent._Height
-
+        
         self._BGpng = IconItem()
         self._BGpng._ImgSurf = MyIconPool._Icons["vol"]
         self._BGpng._MyType = ICON_TYPES["STAT"]
         self._BGpng._Parent = self
-        self._BGpng.Adjust(0, 0, self._BGwidth, self._BGheight, 0)
+        self._BGpng.Adjust(0,0,self._BGwidth,self._BGheight,0)
 
         ##self._NeedleSurf = pygame.Surface( (38,12),pygame.SRCALPHA )
-
+        
         self._Scale = MultiIconItem()
         self._Scale._MyType = ICON_TYPES["STAT"]
         self._Scale._Parent = self
         self._Scale._ImgSurf = MyIconPool._Icons["scale"]
         self._Scale._IconWidth = 82
         self._Scale._IconHeight = 63
-        self._Scale.Adjust(0, 0, 82, 63, 0)
-
-    def SetValue(self, vol):
-        for i, v in enumerate(self.snd_segs):
-            if vol >= v[0] and vol <= v[1]:
+        self._Scale.Adjust(0,0,82,63,0)
+        
+    def SetValue(self,vol):#pct 0-100
+        for i,v in enumerate(self.snd_segs):
+            if vol  >= v[0] and vol <= v[1]:
                 self._Value = i # self._Value :  0 - 8
                 break
-
+        
     def Further(self):
-        self._Value += 1
+        self._Value+=1
 
         if self._Value > len(self.snd_segs)-1:
             self._Value = len(self.snd_segs) -1
@@ -66,10 +75,10 @@ class SoundSlider(Slider):
         
         if self.OnChangeCB != None:
             if callable(self.OnChangeCB):
-                    self.OnChangeCB(vol)
-
+                self.OnChangeCB( vol )
+        
     def StepBack(self):
-        self._Value -= 1
+        self._Value-=1
 
         if self._Value < 0:
             self._Value = 0
@@ -78,38 +87,41 @@ class SoundSlider(Slider):
         
         if self.OnChangeCB != None:
             if callable(self.OnChangeCB):
-                self.OnChangeCB(vol)
-
+                self.OnChangeCB( vol )
+    
     def Draw(self):
-
-        self._BGpng.NewCoord(self._Width / 2, self._Height / 2)
+        
+        self._BGpng.NewCoord(self._Width/2,self._Height/2 )
         self._BGpng.Draw()
 
-        self._Scale.NewCoord(self._Width / 2, self._Height / 2)
+        self._Scale.NewCoord(self._Width/2,self._Height/2)
 
         self._Scale._IconIndex = self._Value
-
+        
         self._Scale.Draw()
-
-
+        
+        
+        
 class SoundPage(Page):
+
     _MySlider = None
-    _FootMsg = ["Nav", "", "", "Back", "Enter"]
+    _FootMsg = ["Nav","","","Back","Enter"]
 
     def Init(self):
         self._CanvasHWND = self._Screen._CanvasHWND
-        self._Width = self._Screen._Width
+        self._Width =  self._Screen._Width
         self._Height = self._Screen._Height
-
+        
         self._MySlider = SoundSlider()
+        
 
-        self._MySlider._Parent = self
+        self._MySlider._Parent = self        
         self._MySlider.SetCanvasHWND(self._CanvasHWND)
 
         self._MySlider.OnChangeCB = self.WhenSliderDrag
 
         self._MySlider.Init()
-
+        
         m = alsaaudio.Mixer()
         self._MySlider.SetValue(m.getvolume()[0])
 
@@ -117,31 +129,36 @@ class SoundPage(Page):
         m = alsaaudio.Mixer()
         self._MySlider.SetValue(m.getvolume()[0])
                 
-    def WhenSliderDrag(self, value):  ##value 0-100
+    def WhenSliderDrag(self,value): ##value 0-100
         if value < 0 or value > 100:
             return
-
+        
         m = alsaaudio.Mixer()
         m.setvolume(int(value))
-
-    def KeyDown(self, event):
-
+        
+    def KeyDown(self,event):
+        
         if event.key == CurKeys["Menu"] or event.key == CurKeys["A"]:
             self.ReturnToUpLevelPage()
             self._Screen.Draw()
             self._Screen.SwapAndShow()
-
+        
         if event.key == CurKeys["Right"]:
             self._MySlider.Further()
             self._Screen.Draw()
             self._Screen.SwapAndShow()
-
+            
         if event.key == CurKeys["Left"]:
             self._MySlider.StepBack()
             self._Screen.Draw()
             self._Screen.SwapAndShow()
-
+        
     def Draw(self):
         self.ClearCanvas()
-
+        
         self._MySlider.Draw()
+
+        
+
+
+    

+ 65 - 60
Menu/GameShell/10_Settings/Storage/__init__.py

@@ -1,133 +1,138 @@
 # -*- coding: utf-8 -*- 
 
+import pygame
 import os
 
-import pygame
-from UI.constants import ICON_TYPES, Width, Height
-from UI.fonts import fonts
+
+## local UI import
+from UI.page  import Page
+from UI.constants import ICON_TYPES,Width,Height
 from UI.icon_item import IconItem
 from UI.icon_pool import MyIconPool
-from UI.label import Label
-## local UI import
-from UI.page import Page
+from UI.label  import Label
+from UI.fonts  import fonts
 from UI.util_funcs import midRect
-from libs.roundrects import aa_round_rect
 
+from libs.roundrects import aa_round_rect
 
 class StoragePage(Page):
+
     _Icons = {}
-    _BGpng = None
+    _BGpng  = None
     _BGwidth = 96
     _BGheight = 73
-    _BGlabel = None
+    _BGlabel  = None
     _FreeLabel = None
+    
+    _BGmsg    = "%.1fGB of %.1fGB Used"
+    _DskUsg   = None
 
-    _BGmsg = "%.1fGB of %.1fGB Used"
-    _DskUsg = None
-
-    _HighColor = pygame.Color(51, 166, 255)
-    _FootMsg = ["Nav.", "", "", "Back", ""]
-
+    _HighColor = pygame.Color(51,166,255)
+    _FootMsg    = ["Nav.","","","Back",""]
+    
     def __init__(self):
         Page.__init__(self)
-
+        
         self._Icons = {}
 
+
     def DiskUsage(self):
         statvfs = os.statvfs('/')
 
-        total_space = (statvfs.f_frsize * statvfs.f_blocks) / 1024.0 / 1024.0 / 1024.0
+        total_space = (statvfs.f_frsize * statvfs.f_blocks)/1024.0/1024.0/1024.0
 
-        avail_space = (statvfs.f_frsize * statvfs.f_bavail) / 1024.0 / 1024.0 / 1024.0
-
-        return avail_space, total_space
+        avail_space = ( statvfs.f_frsize * statvfs.f_bavail) / 1024.0 / 1024.0/ 1024.0
 
+        return avail_space,total_space
+        
     def Init(self):
-        self._DskUsg = self.DiskUsage()
 
+        self._DskUsg = self.DiskUsage()
+        
         self._CanvasHWND = self._Screen._CanvasHWND
-        self._Width = self._Screen._Width
+        self._Width =  self._Screen._Width
         self._Height = self._Screen._Height
-
+        
         self._BGpng = IconItem()
         self._BGpng._ImgSurf = MyIconPool._Icons["icon_sd"]
         self._BGpng._MyType = ICON_TYPES["STAT"]
         self._BGpng._Parent = self
+        
+        self._BGpng.AddLabel(self._BGmsg % (self._DskUsg[1]-self._DskUsg[0], self._DskUsg[1]), fonts["varela15"])
+        self._BGpng.Adjust(0,0,self._BGwidth,self._BGheight,0)
 
-        self._BGpng.AddLabel(self._BGmsg % (self._DskUsg[1] - self._DskUsg[0], self._DskUsg[1]), fonts["varela15"])
-        self._BGpng.Adjust(0, 0, self._BGwidth, self._BGheight, 0)
-
+        
         self._BGlabel = Label()
         self._BGlabel.SetCanvasHWND(self._CanvasHWND)
 
-        usage_percent = (self._DskUsg[0] / self._DskUsg[1]) * 100.0
-
-        self._BGlabel.Init("%d%%" % int(usage_percent), fonts["varela25"])
-        self._BGlabel.SetColor(self._HighColor)
-
+        usage_percent = (self._DskUsg[0]/self._DskUsg[1] )*100.0
+        
+        self._BGlabel.Init("%d%%"% int(usage_percent),fonts["varela25"])
+        self._BGlabel.SetColor( self._HighColor )
+        
         self._FreeLabel = Label()
         self._FreeLabel.SetCanvasHWND(self._CanvasHWND)
-        self._FreeLabel.Init("Free", fonts["varela13"])
+        self._FreeLabel.Init("Free",fonts["varela13"])
         self._FreeLabel.SetColor(self._BGlabel._Color)
 
+        
     def OnLoadCb(self):
         pass
-
+    
     def Draw(self):
         self.ClearCanvas()
-
-        self._BGpng.NewCoord(self._Width / 2, self._Height / 2 - 10)
+        
+        self._BGpng.NewCoord(self._Width/2,self._Height/2-10)
         self._BGpng.Draw()
-        self._BGlabel.NewCoord(self._Width / 2 - 28, self._Height / 2 - 30)
+        self._BGlabel.NewCoord(self._Width/2-28,self._Height/2-30)
         self._BGlabel.Draw()
 
-        self._FreeLabel.NewCoord(self._BGlabel._PosX + 10, self._Height / 2)
+        self._FreeLabel.NewCoord(self._BGlabel._PosX+10   ,self._Height/2)
         self._FreeLabel.Draw()
 
-        # bgcolor = (238,238,238), fgcolor = (126,206,244)
-        # aa_round_rect
-        usage_percent = (self._DskUsg[0] / self._DskUsg[1])
+        #bgcolor = (238,238,238), fgcolor = (126,206,244)
+        #aa_round_rect
+        usage_percent = (self._DskUsg[0]/self._DskUsg[1] )
         if usage_percent < 0.1:
             usage_percent = 0.1
 
-        rect_ = midRect(self._Width / 2, self._Height - 30, 170, 17, Width, Height)
+        rect_ = midRect(self._Width/2,self._Height-30,170,17, Width,Height)
 
-        aa_round_rect(self._CanvasHWND, rect_, (193, 193, 193), 5, 0, (193, 193, 193))
+        aa_round_rect(self._CanvasHWND,rect_, (193,193,193),5,0,(193,193,193))
 
-        rect2 = midRect(self._Width / 2, self._Height - 30, int(170 * (1.0 - usage_percent)), 17, Width, Height)
+        
+        rect2 = midRect(self._Width/2,self._Height-30,int(170*(1.0-usage_percent)),17, Width,Height)
 
         rect2.left = rect_.left
-        rect2.top = rect_.top
-
-        aa_round_rect(self._CanvasHWND, rect2, (126, 206, 244), 5, 0, (126, 206, 244))
-
-
+        rect2.top  = rect_.top
+        
+        aa_round_rect(self._CanvasHWND,rect2, (126,206,244),5,0,(126,206,244))        
+        
 class APIOBJ(object):
-    _StoragePage = None
 
+    _StoragePage = None
     def __init__(self):
         pass
-
-    def Init(self, main_screen):
+    def Init(self,main_screen):
         self._StoragePage = StoragePage()
 
         self._StoragePage._Screen = main_screen
-        self._StoragePage._Name = "Storage"
+        self._StoragePage._Name ="Storage"
         self._StoragePage.Init()
-
-    def API(self, main_screen):
-        if main_screen != None:
+        
+        
+    def API(self,main_screen):
+        if main_screen !=None:
             main_screen.PushPage(self._StoragePage)
             main_screen.Draw()
             main_screen.SwapAndShow()
+    
 
 
 OBJ = APIOBJ()
-
-
-def Init(main_screen):
+def Init(main_screen):    
     OBJ.Init(main_screen)
-
-
 def API(main_screen):
     OBJ.API(main_screen)
+    
+        

+ 119 - 109
Menu/GameShell/10_Settings/Update/__init__.py

@@ -1,23 +1,29 @@
 # -*- coding: utf-8 -*- 
 
-import os
-
-import config
-import gobject
 import pygame
+import os
 import requests
 import validators
+import gobject
+
+
+## local UI import
+from UI.page  import Page
+from UI.constants import ICON_TYPES,Width,Height,RUNEVT
+from UI.icon_item import IconItem
+from UI.icon_pool import MyIconPool
+from UI.label  import Label
+from UI.fonts  import fonts
+from UI.util_funcs import midRect,CmdClean,get_git_revision_short_hash
+from UI.keys_def import CurKeys
 from UI.confirm_page import ConfirmPage
-from UI.constants import Width, RUNEVT
-from UI.download import Download
+from UI.download     import Download
 from UI.download_process_page import DownloadProcessPage
-from UI.fonts import fonts
-from UI.keys_def import CurKeys
-from UI.label import Label
-from UI.page import Page
-from UI.util_funcs import CmdClean, get_git_revision_short_hash
-from libs.DBUS import is_wifi_connected_now
 
+from libs.roundrects import aa_round_rect
+from libs.DBUS       import is_wifi_connected_now
+
+import config
 
 class UpdateDownloadPage(DownloadProcessPage):
     _MD5 = ""
@@ -29,16 +35,16 @@ class UpdateDownloadPage(DownloadProcessPage):
                     print("Success!")
                     # Do something with obj.get_dest()
                     filename = self._Downloader.get_dest()
-
-                    if filename.endswith(".tar.gz"):
-                        # /home/cpi/apps/[launcher]
-                        cmdpath = "tar zxf " + CmdClean(filename) + " -C /home/cpi/apps ;rm -rf " + filename
-                        pygame.event.post(pygame.event.Event(RUNEVT, message=cmdpath))
-
+                    
+                    if filename.endswith(".tar.gz"):                    
+                        #/home/cpi/apps/[launcher]
+                        cmdpath = "tar zxf " + CmdClean(filename) + " -C /home/cpi/apps ;rm -rf "+ filename
+                        pygame.event.post( pygame.event.Event(RUNEVT, message=cmdpath))
+                        
                     self.ReturnToUpLevelPage()
                     self._Screen.Draw()
                     self._Screen.SwapAndShow()
-
+                    
                 else:
                     print("Download failed with the following exceptions:")
                     for e in self._Downloader.get_errors():
@@ -52,67 +58,68 @@ class UpdateDownloadPage(DownloadProcessPage):
                     filename = self._Downloader.get_dest()
                     print(filename)
                     os.system("rm -rf %s" % CmdClean(filename))
-
+                    
                     self._Screen._MsgBox.SetText("Download failed")
                     self._Screen._MsgBox.Draw()
                     self._Screen.SwapAndShow()
                     return False
             else:
-                self._Value = self._Downloader.get_progress()
+                self._Value =  self._Downloader.get_progress()
                 print("Progress: %d%%" % (self._Value))
                 self._Screen.Draw()
                 self._Screen.SwapAndShow()
                 return True
         else:
             return False
-
-    def StartDownload(self, url, dst_dir):
+    
+    def StartDownload(self,url,dst_dir):
         if validators.url(url) and os.path.isdir(dst_dir):
             self._URL = url
             self._DST_DIR = dst_dir
         else:
             self._Screen._MsgBox.SetText("Invaid")
             self._Screen._MsgBox.Draw()
-            self._Screen.SwapAndShow()
+            self._Screen.SwapAndShow()            
             return
-
-        self._Downloader = Download(url, dst_dir, None)
+        
+        self._Downloader = Download(url,dst_dir,None)
         if self._MD5 != None:
             if len(self._MD5) == 32:
-                self._Downloader.add_hash_verification('md5', self._MD5)  ## hashlib provide algorithms
+                self._Downloader.add_hash_verification('md5' ,self._MD5) ## hashlib provide algorithms
 
         self._Downloader.start()
-
+        
         self._DownloaderTimer = gobject.timeout_add(100, self.GObjectUpdateProcessInterval)
 
+    
 
 class UpdateConfirmPage(ConfirmPage):
     _ConfirmText = "Confirm Update ?"
-
+    
     _DownloadPage = None
 
     _URL = ""
     _MD5 = ""
     _Version = ""
     _GIT = False
-
-    def KeyDown(self, event):
+    
+    def KeyDown(self,event):
         if event.key == CurKeys["Menu"] or event.key == CurKeys["A"]:
             self.ReturnToUpLevelPage()
             self._Screen.Draw()
             self._Screen.SwapAndShow()
-
+            
         if event.key == CurKeys["B"]:
             if self._GIT == True:
                 cmdpath = "feh --bg-center /home/cpi/apps/launcher/sys.py/gameshell/wallpaper/updating.png; cd /home/cpi/apps/launcher ;git pull; git reset --hard %s ; feh --bg-center /home/cpi/apps/launcher/sys.py/gameshell/wallpaper/loading.png " % self._Version
-                pygame.event.post(pygame.event.Event(RUNEVT, message=cmdpath))
+                pygame.event.post( pygame.event.Event(RUNEVT, message=cmdpath))
                 self._GIT = False
                 return
-
+            
             if self._DownloadPage == None:
                 self._DownloadPage = UpdateDownloadPage()
                 self._DownloadPage._Screen = self._Screen
-                self._DownloadPage._Name = "Downloading..."
+                self._DownloadPage._Name   = "Downloading..."                
                 self._DownloadPage.Init()
 
             self._DownloadPage._MD5 = self._MD5
@@ -123,19 +130,20 @@ class UpdateConfirmPage(ConfirmPage):
             if self._URL != None and validators.url(self._URL):
                 self._DownloadPage.StartDownload(self._URL, "/tmp")
             else:
-                print("error url  %s " % self._URL)
+                print "error url  %s " % self._URL
+            
 
     def OnReturnBackCb(self):
         self.ReturnToUpLevelPage()
         self._Screen.Draw()
         self._Screen.SwapAndShow()
-
+            
     def Draw(self):
         self.ClearCanvas()
         self.DrawBG()
         for i in self._MyList:
             i.Draw()
-
+        
         self.Reset()
 
 
@@ -146,93 +154,95 @@ class InfoPageListItem(object):
     _Height = 30
 
     _Labels = {}
-    _Icons = {}
-    _Fonts = {}
+    _Icons  = {}
+    _Fonts  = {}
 
     _LinkObj = None
-
+    
     def __init__(self):
         self._Labels = {}
-        self._Icons = {}
-        self._Fonts = {}
+        self._Icons  = {}
+        self._Fonts  = {}
 
-    def SetSmallText(self, text):
+    def SetSmallText(self,text):
+        
         l = Label()
         l._PosX = 40
         l.SetCanvasHWND(self._Parent._CanvasHWND)
-        l.Init(text, self._Fonts["small"])
+        l.Init(text,self._Fonts["small"])
         self._Labels["Small"] = l
+        
+    def Init(self,text):
 
-    def Init(self, text):
-        # self._Fonts["normal"] = fonts["veramono12"]
-
+        #self._Fonts["normal"] = fonts["veramono12"]
+        
         l = Label()
         l._PosX = 10
         l.SetCanvasHWND(self._Parent._CanvasHWND)
 
-        l.Init(text, self._Fonts["normal"])
+        l.Init(text,self._Fonts["normal"])
         self._Labels["Text"] = l
 
     def Draw(self):
-        self._Labels["Text"]._PosY = self._PosY + (self._Height - self._Labels["Text"]._Height) / 2
+        
+        self._Labels["Text"]._PosY = self._PosY + (self._Height - self._Labels["Text"]._Height)/2
         self._Labels["Text"].Draw()
 
         if "Small" in self._Labels:
-            self._Labels["Small"]._PosX = self._Width - self._Labels["Small"]._Width - 5
-
-            self._Labels["Small"]._PosY = self._PosY + (self._Height - self._Labels["Small"]._Height) / 2
+            self._Labels["Small"]._PosX = self._Width - self._Labels["Small"]._Width-5
+            
+            self._Labels["Small"]._PosY = self._PosY + (self._Height - self._Labels["Small"]._Height)/2
             self._Labels["Small"].Draw()
-
-        pygame.draw.line(self._Parent._CanvasHWND, (169, 169, 169), (self._PosX, self._PosY + self._Height - 1),
-                         (self._PosX + self._Width, self._PosY + self._Height - 1), 1)
-
+        
+        pygame.draw.line(self._Parent._CanvasHWND,(169,169,169),(self._PosX,self._PosY+self._Height-1),(self._PosX+self._Width,self._PosY+self._Height-1),1)
+        
 
 class UpdatePage(Page):
     _Icons = {}
-    _FootMsg = ["Nav.", "Check Update", "", "Back", ""]
+    _FootMsg = ["Nav.","Check Update","","Back",""]
 
-    _ListFontObj = fonts["varela15"]
+    _ListFontObj = fonts["varela15"]    
     _ConfirmPage = None
-    _AList = {}
-    _MyList = []
-
+    _AList    = {}
+    _MyList   = []
+    
     def __init__(self):
         Page.__init__(self)
-        self._Icons = {}
+        self._Icons = {}    
 
     def GenList(self):
-
-        start_x = 0
-        start_y = 0
-
-        for i, v in enumerate(self._AList):
+        
+        start_x  = 0
+        start_y  = 0
+        
+        for i,v in enumerate( self._AList):
             li = InfoPageListItem()
             li._Parent = self
-            li._PosX = start_x
-            li._PosY = start_y + i * InfoPageListItem._Height
-            li._Width = Width
+            li._PosX   = start_x
+            li._PosY   = start_y + i*InfoPageListItem._Height
+            li._Width  = Width
             li._Fonts["normal"] = self._ListFontObj
             li._Fonts["small"] = fonts["varela12"]
-
+            
             if self._AList[v]["label"] != "":
-                li.Init(self._AList[v]["label"])
+                li.Init(  self._AList[v]["label"] )
             else:
-                li.Init(self._AList[v]["key"])
+                li.Init( self._AList[v]["key"] )
 
             li._Flag = self._AList[v]["key"]
 
-            li.SetSmallText(self._AList[v]["value"])
-
+            li.SetSmallText( self._AList[v]["value"] )
+            
             self._MyList.append(li)
-
+        
     def Init(self):
         self._CanvasHWND = self._Screen._CanvasHWND
-        self._Width = self._Screen._Width
+        self._Width =  self._Screen._Width
         self._Height = self._Screen._Height
 
         self._ConfirmPage = UpdateConfirmPage()
         self._ConfirmPage._Screen = self._Screen
-        self._ConfirmPage._Name = "Update Confirm"
+        self._ConfirmPage._Name  = "Update Confirm"
         self._ConfirmPage._Parent = self
         self._ConfirmPage.Init()
 
@@ -241,9 +251,9 @@ class UpdatePage(Page):
         it["label"] = "Version"
         it["value"] = config.VERSION
         self._AList["version"] = it
-
+        
         self.GenList()
-
+        
     def CheckUpdate(self):
         self._Screen._MsgBox.SetText("Checking update...")
         self._Screen._MsgBox.Draw()
@@ -261,17 +271,18 @@ class UpdatePage(Page):
 
                     if "version" in json_ and "updatepath" in json_ and "md5sum" in json_:
                         if config.VERSION != json_["version"]:
+                            
                             self._ConfirmPage._URL = json_["updatepath"]
                             self._ConfirmPage._MD5 = json_["md5sum"]
                             self._ConfirmPage._GIT = False
-
+                            
                             self._Screen.PushPage(self._ConfirmPage)
-
+                            
                             self._Screen.Draw()
-                            self._ConfirmPage.SnapMsg("Confirm Update to %s ?" % json_["version"])
+                            self._ConfirmPage.SnapMsg("Confirm Update to %s ?" % json_["version"] )
                             self._Screen.SwapAndShow()
-
-                    elif "gitversion" in json_:  ### just use git to  run update
+                            
+                    elif "gitversion" in json_: ### just use git to  run update
                         cur_dir = os.getcwd()
                         os.chdir("/home/cpi/apps/launcher")
                         current_git_version = get_git_revision_short_hash()
@@ -283,11 +294,11 @@ class UpdatePage(Page):
                             self._ConfirmPage._MD5 = None
                             self._ConfirmPage._GIT = True
                             self._ConfirmPage._Version = json_["gitversion"]
-
+                            
                             self._Screen.PushPage(self._ConfirmPage)
-
+                            
                             self._Screen.Draw()
-                            self._ConfirmPage.SnapMsg("Update to %s ?" % json_["gitversion"])
+                            self._ConfirmPage.SnapMsg("Update to %s ?" % json_["gitversion"] )
                             self._Screen.SwapAndShow()
                         else:
                             self._Screen.Draw()
@@ -295,20 +306,21 @@ class UpdatePage(Page):
                             self._Screen._MsgBox.Draw()
                             self._Screen.SwapAndShow()
                             pygame.time.delay(765)
-
+                            
                     return True
-                except Exception as e:
+                except Exception, e:
                     print("r.json() error %s" % str(e))
-
+                
             else:
                 print(" requests get error %d ", r.status_code)
+                    
 
         return False
-
+    
     def OnLoadCb(self):
         pass
 
-    def KeyDown(self, event):
+    def KeyDown(self,event):
         if event.key == CurKeys["Menu"] or event.key == CurKeys["A"]:
             self.ReturnToUpLevelPage()
             self._Screen.Draw()
@@ -332,38 +344,36 @@ class UpdatePage(Page):
 
     def Draw(self):
         self.ClearCanvas()
-        #        self._Ps.Draw()
+#        self._Ps.Draw()
 
         for i in self._MyList:
             i.Draw()
-
-
+        
+    
 class APIOBJ(object):
-    _UpdatePage = None
 
+    _UpdatePage = None
     def __init__(self):
         pass
-
-    def Init(self, main_screen):
+    def Init(self,main_screen):
         self._UpdatePage = UpdatePage()
 
         self._UpdatePage._Screen = main_screen
-        self._UpdatePage._Name = "Update"
+        self._UpdatePage._Name ="Update"
         self._UpdatePage.Init()
-
-    def API(self, main_screen):
-        if main_screen != None:
+        
+    def API(self,main_screen):
+        if main_screen !=None:
             main_screen.PushPage(self._UpdatePage)
             main_screen.Draw()
             main_screen.SwapAndShow()
+    
 
 
 OBJ = APIOBJ()
-
-
-def Init(main_screen):
+def Init(main_screen):    
     OBJ.Init(main_screen)
-
-
 def API(main_screen):
     OBJ.API(main_screen)
+    
+        

+ 4 - 6
Menu/GameShell/10_Settings/Wifi/__init__.py

@@ -1,27 +1,25 @@
 # -*- coding: utf-8 -*- 
 
-import myvars
 ## local UI import
 import pages
-
+import myvars
 """
 try:
     from icons import preload
 except:
     print("No icons package")
 """
-from icons import preload
-
 
 def Init(main_screen):
-    preload.load_icons()
     pages.InitPasswordPage(main_screen)
     pages.InitScanPage(main_screen)
 
-
 def API(main_screen):
+    
     if main_screen != None:
         main_screen.PushCurPage()
         main_screen.SetCurPage(myvars.ScanPage)
         main_screen.Draw()
         main_screen.SwapAndShow()
+
+

+ 126 - 122
Menu/GameShell/10_Settings/Wifi/keyboard.py

@@ -1,57 +1,58 @@
 # -*- coding: utf-8 -*- 
 
-import myvars
 import pygame
+
+from libs import easing
+
 ## local UI import
-from UI.constants import Width, Height, ICON_TYPES
-from UI.fonts import fonts
-from UI.icon_item import IconItem
-from UI.icon_pool import MyIconPool
-from UI.keys_def import CurKeys
-from UI.page import Page, PageSelector
+from UI.constants  import Width,Height,ICON_TYPES
+from UI.page   import Page,PageSelector
+from UI.label  import Label
+from UI.fonts  import fonts
 from UI.util_funcs import midRect
-from icons import preload
-from libs import easing
+from UI.keys_def import CurKeys
+from UI.icon_item import IconItem
+from UI.icon_pool    import MyIconPool
+
 from libs.roundrects import aa_round_rect
-from text_item import TextItem
-from textarea import Textarea
 
+from textarea  import Textarea
+from text_item import TextItem
 
+import myvars
 
 class KeyboardIcon(IconItem):
     _PosX = 0
     _PosY = 0
     _Width = 0
     _Height = 0
-    _Color = pygame.Color(83, 83, 83)
-    _MyType = ICON_TYPES["NAV"]
-    _Parent = None
-    _Str = ""
-
+    _Color = pygame.Color(83,83,83)
+    _MyType  = ICON_TYPES["NAV"] 
+    _Parent  = None
+    _Str     = ""
+    
     def Draw(self):
         self._Parent._CanvasHWND.blit(self._ImgSurf, \
-                                      midRect(self._PosX, self._PosY, self._Width, self._Height, Width, Height))
+            midRect(self._PosX,self._PosY,self._Width,self._Height,Width,Height))
 
 
 class KeyboardSelector(PageSelector):
-
+    
     def Draw(self):
         sec_idx = self._Parent._SectionIndex
         row_idx = self._Parent._RowIndex
-        idx = self._Parent._PsIndex
-
-        x = self._Parent._SecsKeys[sec_idx][row_idx][idx]._PosX
-        y = self._Parent._SecsKeys[sec_idx][row_idx][idx]._PosY
-        w = self._Parent._SecsKeys[sec_idx][row_idx][idx]._Width + 6
-        h = self._Parent._SecsKeys[sec_idx][row_idx][idx]._Height + 1
-
-        rect = midRect(x, y, w, h, self._Parent._Width, self._Parent._Height)
-        if rect.width <= 0 or rect.height <= 0:
+        idx     = self._Parent._PsIndex
+        
+        x       = self._Parent._SecsKeys[sec_idx][row_idx][idx]._PosX
+        y       = self._Parent._SecsKeys[sec_idx][row_idx][idx]._PosY
+        w       = self._Parent._SecsKeys[sec_idx][row_idx][idx]._Width+6
+        h       = self._Parent._SecsKeys[sec_idx][row_idx][idx]._Height+1
+
+        rect    = midRect(x,y,w,h,self._Parent._Width,self._Parent._Height)
+        if rect.width <=0 or rect.height <= 0 :
             return
 
-        aa_round_rect(self._Parent._CanvasHWND, rect, (126, 206, 244), 3, 0, (126, 206, 244))
-
-
+        aa_round_rect(self._Parent._CanvasHWND,rect, (126,206,244),3,0,(126,206,244))
 #        pygame.draw.rect(self._Parent._CanvasHWND,(0,0,0),rect,1)
 
 class Keyboard(Page):
@@ -69,25 +70,25 @@ class Keyboard(Page):
     _Textarea = None
     _Selector = None
     _LeftOrRight = 1
-    _FootMsg = ["Nav.", "ABC", "Done", "Backspace", "Enter"]
-
-    _RowIndex = 0
+    _FootMsg           = ["Nav.","ABC","Done","Backspace","Enter"]
 
+    _RowIndex    = 0
+    
     def __init__(self):
-        self._Secs = {}
+        self._Secs     = {}
         self._SecsKeys = {}
-        self._Icons = {}
+        self._Icons    = {}
 
-    def ReadLayoutFile(self, fname):
+    def ReadLayoutFile(self,fname):
         LayoutIndex = 0
         with open(fname) as f:
             content = f.readlines()
 
-        content = [x.strip() for x in content]
-        content = [x.split(" ") for x in content]
+        content = [ x.strip() for x in content]
+        content = [ x.split(" ") for x in content]
 
         for i in content:
-            i = [x.strip() for x in i]
+            i = [ x.strip() for x in i]
             if len(i) > 2:
                 if LayoutIndex in self._Secs:
                     self._Secs[LayoutIndex].append(i)
@@ -95,148 +96,147 @@ class Keyboard(Page):
                     self._Secs[LayoutIndex] = []
                     self._Secs[LayoutIndex].append(i)
             else:
-                LayoutIndex += 1
-
-    def SetPassword(self, pwd):
+                LayoutIndex+=1
 
+    def SetPassword(self,pwd):
+        
         pwd_list = list(pwd)
         self._Textarea.ResetMyWords()
         for i in pwd_list:
             self._Textarea.AppendText(i)
-            # self._Textarea.BlitText()
-
+            #self._Textarea.BlitText()
+        
     def Init(self):
         self._CanvasHWND = self._Screen._CanvasHWND
-        self.ReadLayoutFile(self._KeyboardLayoutFile)  ## assign to _Secs
+        self.ReadLayoutFile(self._KeyboardLayoutFile) ## assign to _Secs
         self._SectionNumbers = len(self._Secs)
-        self._PosX = self._Index * self._Screen._Width
+        self._PosX = self._Index*self._Screen._Width
         self._Width = self._Screen._Width
         self._Height = self._Screen._Height
-
+        
         fontobj = fonts["veramono24"]
         word_margin = 15
 
-        start_x = (self._Width - fontobj.size("".join(self._Secs[0][0]))[0] - len(
-            self._Secs[0][0]) * word_margin) / 2 + word_margin / 2
+        start_x = (self._Width - fontobj.size( "".join(self._Secs[0][0]))[0]-len(self._Secs[0][0])*word_margin)/2+word_margin/2
         start_y = 0
         cnt = 0
-        for i in range(0, self._SectionNumbers):
+        for i in range(0,self._SectionNumbers):
             self._SecsKeys[i] = []
-            for j in range(0, len(self._Secs[i])):
-                self._SecsKeys[i].append([])
-
-                start_x = (self._Width - fontobj.size("".join(self._Secs[i][j]))[0] - len(
-                    self._Secs[i][j]) * word_margin) / 2 + word_margin / 2
-                start_x = start_x + i * Width
-                start_y = 84 + j * (word_margin + 14)
-                for idx, val in enumerate(self._Secs[i][j]):
+            for j in range(0,len(self._Secs[i])):
+                self._SecsKeys[i].append( [] )
+                
+                start_x = (self._Width - fontobj.size( "".join(self._Secs[i][j]))[0]-len(self._Secs[i][j])*word_margin)/2+word_margin/2
+                start_x = start_x + i*Width
+                start_y = 84+j*(word_margin+14)
+                for idx,val in enumerate(self._Secs[i][j]):
                     ti = TextItem()
                     ti._FontObj = fontobj
                     ti._Parent = self
 
                     if val == "_L" or val == "_R":
-                        it = KeyboardIcon()
+                        it  = KeyboardIcon()
                         it._ImgSurf = MyIconPool._Icons[val]
                         it._Parent = self
                         it._Str = val
-                        it.Init(start_x + it._ImgSurf.get_width() / 2, start_y, it._ImgSurf.get_width(),
-                                it._ImgSurf.get_height(), 0)
-                        # self._Icons[val] = it
+                        it.Init(start_x+it._ImgSurf.get_width()/2  ,start_y,it._ImgSurf.get_width(),it._ImgSurf.get_height(),0)
+                        #self._Icons[val] = it
                         self._SecsKeys[i][j].append(it)
-                        self._IconNumbers += 1
-                        start_x = start_x + it._ImgSurf.get_width() + word_margin
-
+                        self._IconNumbers+=1
+                        start_x = start_x + it._ImgSurf.get_width()+word_margin
+                        
                     else:
                         if val == "_S":
                             val = "Space"
                             ti._FontObj = fonts["veramono15"]
                             ti._Bold = True
-
-                        cur_alpha_size = ti._FontObj.size(val)
-                        ti.Init(start_x + cur_alpha_size[0] / 2, start_y, cur_alpha_size[0], cur_alpha_size[1], 0)
+                        
+                        cur_alpha_size  = ti._FontObj.size( val)
+                        ti.Init(start_x + cur_alpha_size[0]/2,start_y,cur_alpha_size[0],cur_alpha_size[1],0)
                         ti._Str = val
-
-                        start_x = start_x + cur_alpha_size[0] + word_margin  # prepare for next alpha
+                    
+                        start_x = start_x + cur_alpha_size[0]+word_margin # prepare for next alpha
                         self._SecsKeys[i][j].append(ti)
-
+    
         self._SectionIndex = 0
 
         self._Textarea = Textarea()
-
+        
         self._Textarea._PosX = 4
         self._Textarea._PosY = 4
-        self._Textarea._Width = self._Width - 4 * 2
+        self._Textarea._Width= self._Width - 4*2
         self._Textarea._Height = 60
         self._Textarea._CanvasHWND = self._CanvasHWND
         self._Textarea.Init()
 
+
         ps = KeyboardSelector()
         ps._Parent = self
-        ps.Init(start_x, start_y, 25, 25, 128)
+        ps.Init(start_x,start_y,25,25,128)
         self._Ps = ps
         self._PsIndex = 0
         self._Ps._OnShow = True
 
     def SelectUpChar(self):
         sec_idx = self._SectionIndex
-        self._RowIndex -= 1
-        if self._RowIndex < 0:
-            self._RowIndex = len(self._SecsKeys[sec_idx]) - 1
+        self._RowIndex-=1
+        if self._RowIndex <0:
+            self._RowIndex = len(self._SecsKeys[sec_idx])-1
+
+        if self._PsIndex >=len(self._SecsKeys[sec_idx][self._RowIndex]):
+            self._PsIndex = len(self._SecsKeys[sec_idx][self._RowIndex])-1
 
-        if self._PsIndex >= len(self._SecsKeys[sec_idx][self._RowIndex]):
-            self._PsIndex = len(self._SecsKeys[sec_idx][self._RowIndex]) - 1
 
         self.ClearCanvas()
         self.Draw()
         self._Screen.SwapAndShow()
-
+            
     def SelectDownChar(self):
         sec_idx = self._SectionIndex
-        self._RowIndex += 1
+        self._RowIndex+=1
         if self._RowIndex >= len(self._SecsKeys[sec_idx]):
             self._RowIndex = 0
 
-        if self._PsIndex >= len(self._SecsKeys[sec_idx][self._RowIndex]):
-            self._PsIndex = len(self._SecsKeys[sec_idx][self._RowIndex]) - 1
+        if self._PsIndex >=len(self._SecsKeys[sec_idx][self._RowIndex]):
+            self._PsIndex = len(self._SecsKeys[sec_idx][self._RowIndex])-1
 
         self.ClearCanvas()
         self.Draw()
         self._Screen.SwapAndShow()
-
+        
     def SelectNextChar(self):
         sec_idx = self._SectionIndex
         row_idx = self._RowIndex
-        self._PsIndex += 1
+        self._PsIndex+=1
         if self._PsIndex >= len(self._SecsKeys[sec_idx][row_idx]):
             self._PsIndex = 0
-            self._RowIndex += 1
+            self._RowIndex+=1
             if self._RowIndex >= len(self._SecsKeys[sec_idx]):
                 self._RowIndex = 0
-
+        
         self.ClearCanvas()
         self.Draw()
         self._Screen.SwapAndShow()
 
     def SelectPrevChar(self):
-        sec_idx = self._SectionIndex
-        self._PsIndex -= 1
+        sec_idx = self._SectionIndex    
+        self._PsIndex-=1
         if self._PsIndex < 0:
-            self._RowIndex -= 1
-            if self._RowIndex <= 0:
-                self._RowIndex = len(self._SecsKeys[sec_idx]) - 1
-            self._PsIndex = len(self._SecsKeys[sec_idx][self._RowIndex]) - 1
+            self._RowIndex-=1
+            if self._RowIndex <=0:
+                self._RowIndex = len(self._SecsKeys[sec_idx])-1
+            self._PsIndex = len(self._SecsKeys[sec_idx][self._RowIndex]) -1
 
         self.ClearCanvas()
         self.Draw()
         self._Screen.SwapAndShow()
-
+      
     def ClickOnChar(self):
-        sec_idx = self._SectionIndex
+        sec_idx = self._SectionIndex        
         alphabet = self._SecsKeys[sec_idx][self._RowIndex][self._PsIndex]._Str
 
         if alphabet == "Space":
             alphabet = " "
-
+        
         if alphabet == "_L" or alphabet == "_R":
             if alphabet == "_L":
                 self._Textarea.SubTextIndex()
@@ -244,50 +244,51 @@ class Keyboard(Page):
                 self._Textarea.AddTextIndex()
         else:
             self._Textarea.AppendText(alphabet)
-
+        
         self._Textarea.Draw()
         self._Screen.SwapAndShow()
 
+
     def KeyboardShift(self):
         current_time = 0.0
-        start_posx = 0.0
+        start_posx   = 0.0
         current_posx = start_posx
-        final_posx = 320.0
-        posx_init = 0.0
-        dur = 30
-        last_posx = 0.0
+        final_posx   = 320.0
+        posx_init    = 0.0
+        dur          = 30
+        last_posx    = 0.0 
         all_last_posx = []
 
-        for i in range(0, Width * dur):
-            current_posx = easing.SineIn(current_time, start_posx, final_posx - start_posx, float(dur))
+        for i in range(0,Width*dur):
+            current_posx = easing.SineIn(current_time,start_posx,final_posx-start_posx,float(dur))
             if current_posx >= final_posx:
                 current_posx = final_posx
 
-            dx = current_posx - last_posx
+            dx  = current_posx - last_posx
             all_last_posx.append(int(dx))
-            current_time += 1
+            current_time +=1
             last_posx = current_posx
             if current_posx >= final_posx:
                 break
-
+        
         c = 0
         for i in all_last_posx:
-            c += i
+            c+=i
         if c < final_posx - start_posx:
             all_last_posx.append(final_posx - c)
 
         for i in all_last_posx:
-            for j in range(0, self._SectionNumbers):
+            for j in range(0,self._SectionNumbers):
                 for u in self._SecsKeys[j]:
-                    for x in u:
-                        x._PosX += self._LeftOrRight * i
-
+                    for x in u: 
+                        x._PosX += self._LeftOrRight*i
+            
             self.ResetPageSelector()
             self.ClearCanvas()
             self.Draw()
             self._Screen.SwapAndShow()
-
-    def KeyDown(self, event):  # event from pygame.event.get()
+        
+    def KeyDown(self,event):# event from pygame.event.get()
         if event.key == CurKeys["Up"]:
             self.SelectUpChar()
         if event.key == CurKeys["Down"]:
@@ -301,27 +302,27 @@ class Keyboard(Page):
         if event.key == CurKeys["X"]:
             if self._SectionIndex <= 0:
                 self._LeftOrRight = -1
-            if self._SectionIndex >= (self._SectionNumbers - 1):
+            if self._SectionIndex >= (self._SectionNumbers -1):
                 self._LeftOrRight = 1
             self.KeyboardShift()
 
             self._SectionIndex -= self._LeftOrRight
 
-            # print(self._SectionIndex) # on which keyboard section now
+            #print(self._SectionIndex) # on which keyboard section now
             self.Draw()
             self._Screen.SwapAndShow()
-
-        if event.key == CurKeys["Menu"]:  # we assume keyboard always be child page
+        
+        if event.key == CurKeys["Menu"]: # we assume keyboard always be child page
             self.ReturnToUpLevelPage()
             self._Screen.Draw()
             self._Screen.SwapAndShow()
-
-        if event.key == CurKeys["Y"]:  # done
+        
+        if event.key == CurKeys["Y"]: #done 
             print("".join(self._Textarea._MyWords))
             self.ReturnToUpLevelPage()
             self._Screen.SwapAndShow()
             ## config and connect now
-            myvars.ScanPage.ConfigWireless("".join(self._Textarea._MyWords))
+            myvars.ScanPage.ConfigWireless( "".join(self._Textarea._MyWords)) 
 
         if event.key == CurKeys["A"]:
             self._Textarea.RemoveFromLastText()
@@ -331,9 +332,12 @@ class Keyboard(Page):
     def Draw(self):
         self.ClearCanvas()
         self._Ps.Draw()
-        for i in range(0, self._SectionNumbers):
+        for i in range(0,self._SectionNumbers):
             for j in self._SecsKeys[i]:
                 for u in j:
                     u.Draw()
 
+        
         self._Textarea.Draw()
+
+

+ 76 - 69
Menu/GameShell/10_Settings/Wifi/net_item.py

@@ -1,84 +1,84 @@
 # -*- coding: utf-8 -*- 
 
 import pygame
-from UI.icon_item import IconItem
+
 ## local UI import
-from UI.label import Label
-from UI.multi_icon_item import MultiIconItem
+from UI.page   import Page
+from UI.label  import Label
+from UI.fonts  import fonts
+from UI.icon_item import IconItem
+from UI.multi_icon_item  import MultiIconItem
 from UI.icon_pool   import MyIconPool
-from icons import preload
 
 
 class NetItemMultiIcon(MultiIconItem):
     _CanvasHWND = None
-    _Parent = None
-    _Width = 18
-    _Height = 18
-
+    _Parent     = None
+    _Width      = 18
+    _Height     = 18
+    
     def Draw(self):
-        self._CanvasHWND.blit(self._ImgSurf, (
-        self._PosX, self._PosY + (self._Parent._Height - self._Height) / 2, self._Width, self._Height),
-                              (0, self._IconIndex * self._IconHeight, self._IconWidth, self._IconHeight))
-
-
+        self._CanvasHWND.blit(self._ImgSurf,(self._PosX,self._PosY+(self._Parent._Height-self._Height)/2,self._Width,self._Height),
+                              (0,self._IconIndex*self._IconHeight,self._IconWidth,self._IconHeight))
+    
 class NetItemIcon(IconItem):
-    _CanvasHWND = None
-    _Parent = None
-    _Width = 18
-    _Height = 18
 
+    _CanvasHWND = None
+    _Parent     = None
+    _Width      = 18
+    _Height     = 18
+    
     def Draw(self):
-        self._CanvasHWND.blit(self._ImgSurf, (
-        self._PosX, self._PosY + (self._Parent._Height - self._Height) / 2, self._Width, self._Height))
-
+        self._CanvasHWND.blit(self._ImgSurf,(self._PosX,self._PosY+(self._Parent._Height-self._Height)/2,self._Width,self._Height))
 
+            
 class NetItem(object):
     _PosX = 0
     _PosY = 0
     _Width = 0
     _Height = 30
 
-    _Bssid = ""  # 50:3A:A0:51:18:3C
-    _Essid = ""  # MERCURY_EB88
+    _Bssid=""    # 50:3A:A0:51:18:3C
+    _Essid=""    # MERCURY_EB88
 
     ## extra infomations
     _dhcphostname = "GameShell"
-    _ip = None  # eg 192.168.31.141
+    _ip   = None      #eg 192.168.31.141
     _dns_domain = None
-    _gateway = None  # eg 192.168.31.1
-    _use_global_dns = 0  ## eg 0 == False, 1 == True
-    _netmask = None  ##eg 255.255.255.0
-    _usedhcphostname = 0
+    _gateway    = None  #eg 192.168.31.1
+    _use_global_dns = 0 ## eg 0 == False, 1 == True
+    _netmask    = None ##eg 255.255.255.0
+    _usedhcphostname= 0
     _bitrate = "auto"
     _allow_lower_bitrates = 0
     _dns3 = None
     _dns2 = None  ## eg 1.1.1.1
     _dns1 = None  ## eg 8.8.8.8
-    _use_settings_globally = 0
-    _use_static_dns = 0  # eg: 1 == True
+    _use_settings_globally = 0 
+    _use_static_dns = 0 # eg: 1 == True
     _search_domain = None
-
-    _Encrypt = ""  # WPA2
-    _Channel = ""  # '10'
+    
+    _Encrypt=""  # WPA2
+    _Channel=""  # '10' 
     _Stren = ""  ## 19%
-    _NetId = 0  ##  0-n
-    _Mode = ""  ## Master or AdHoc
+    _NetId    = 0   ##  0-n
+    _Mode  = ""  ## Master or AdHoc
     _Parent = None
     _IsActive = False
 
-    _Icons = {}  ## wifi strength and security icons
+    _Icons  = {} ## wifi strength and security icons
     _Labels = {}
     _FontObj = None
-
+    
     def __init__(self):
         self._Labels = {}
         self._Icons = {}
 
-    def SetActive(self, act):
+    def SetActive(self,act):
         self._IsActive = act
-
-    def UpdateStrenLabel(self, strenstr):  ## strenstr should be 'number',eg:'90'
-        self._Stren = self._Parent._Daemon.FormatSignalForPrinting(strenstr)
+    
+    def UpdateStrenLabel(self, strenstr): ## strenstr should be 'number',eg:'90'
+        self._Stren = self._Parent._Daemon.FormatSignalForPrinting(strenstr) 
         self._Labels["stren"]._Text = self._Stren
 
     def Init(self, i, is_active):
@@ -93,8 +93,8 @@ class NetItem(object):
         self._NetId = i
         # All of that network property stuff
         self._Stren = self._Parent._Daemon.FormatSignalForPrinting(
-            str(self._Parent._Wireless.GetWirelessProperty(self._NetId, strenstr)))
-
+                str(self._Parent._Wireless.GetWirelessProperty(self._NetId, strenstr)))
+        
         self._Essid = self._Parent._Wireless.GetWirelessProperty(self._NetId, 'essid')
         self._Bssid = self._Parent._Wireless.GetWirelessProperty(self._NetId, 'bssid')
 
@@ -108,47 +108,51 @@ class NetItem(object):
             self._Parent._Wireless.GetWirelessProperty(self._NetId, 'mode')  # Master, Ad-Hoc
         self._Channel = self._Parent._Wireless.GetWirelessProperty(self._NetId, 'channel')
         theString = '  %-*s %25s %9s %17s %6s %4s' % \
-                    (gap, self._Stren, self._Essid, self._Encrypt, self._Bssid, self._Mode,
-                     self._Channel)
-
+            (gap, self._Stren, self._Essid, self._Encrypt, self._Bssid, self._Mode,
+                self._Channel)
+        
         if is_active:
-            theString = ">> " + theString[1:]
+            theString = ">> "+theString[1:]
             self.SetActive(is_active)
+        
+
 
         essid_label = Label()
         essid_label._PosX = 36
-        # essid_label._PosY = self._PosY +  (self._Height - self._FontObj.render(self._Essid,True,(83,83,83)).get_height())/2
+        #essid_label._PosY = self._PosY +  (self._Height - self._FontObj.render(self._Essid,True,(83,83,83)).get_height())/2
         essid_label._CanvasHWND = self._Parent._CanvasHWND
 
         if len(self._Essid) > 19:
             essid_ = self._Essid[:20]
         else:
             essid_ = self._Essid
-
-        essid_label.Init(essid_, self._FontObj)
+        
+        essid_label.Init(essid_,self._FontObj)
         self._Labels["essid"] = essid_label
 
         stren_label = Label()
-        # stren_label._PosY = self._PosY +  (self._Height - self._FontObj.render(self._Stren,True,(83,83,83)).get_height())/2
+        #stren_label._PosY = self._PosY +  (self._Height - self._FontObj.render(self._Stren,True,(83,83,83)).get_height())/2
         stren_label._CanvasHWND = self._Parent._CanvasHWND
 
-        stren_label.Init(self._Stren, self._FontObj)
+        stren_label.Init(self._Stren,self._FontObj)
         stren_label._PosX = self._Width - 23 - stren_label.Width() - 2
         self._Labels["stren"] = stren_label
+        
 
         lock_icon = NetItemIcon()
         lock_icon._ImgSurf = MyIconPool._Icons["lock"]
         lock_icon._CanvasHWND = self._Parent._CanvasHWND
         lock_icon._Parent = self
         self._Icons["lock"] = lock_icon
-
+        
         done_icon = NetItemIcon()
         done_icon._ImgSurf = MyIconPool._Icons["done"]
         done_icon._CanvasHWND = self._Parent._CanvasHWND
         done_icon._Parent = self
-
+        
         self._Icons["done"] = done_icon
 
+
         ## reuse the resource from TitleBar
         nimt = NetItemMultiIcon()
         nimt._ImgSurf = self._Parent._Screen._TitleBar._Icons["wifistatus"]._ImgSurf
@@ -156,37 +160,40 @@ class NetItem(object):
         nimt._Parent = self
         self._Icons["wifistatus"] = nimt
 
-        # pp(theString)
-
-    def Connect(self, notworkentry=None):
+        #pp(theString)
+    
+    
+    def Connect(self,notworkentry=None):
         """ Execute connection. """
         self._Parent._Wireless.ConnectWireless(self._NetId)
 
+    
     def Draw(self):
-        # pygame.draw.line(self._Parent._CanvasHWND,(169,169,169),(self._PosX,self._PosY),(self._PosX+self._Width,self._PosY),1)
+        #pygame.draw.line(self._Parent._CanvasHWND,(169,169,169),(self._PosX,self._PosY),(self._PosX+self._Width,self._PosY),1)        
         for i in self._Labels:
-            self._Labels[i]._PosY = self._PosY + (self._Height - self._Labels[i]._Height) / 2
+            self._Labels[i]._PosY = self._PosY + (self._Height - self._Labels[i]._Height)/2
             self._Labels[i].Draw()
-
+            
         if self._IsActive:
-            self._Icons["done"].NewCoord(14, self._PosY)
+            self._Icons["done"].NewCoord(14,self._PosY)
             self._Icons["done"].Draw()
 
         if self._Encrypt != "Unsecured":
-            self._Icons["lock"].NewCoord(self._Width - 23 - self._Labels["stren"].Width() - 2 - 18, self._PosY)
+            self._Icons["lock"].NewCoord( self._Width -23 - self._Labels["stren"].Width() - 2 - 18, self._PosY)
             self._Icons["lock"].Draw()
-
-        ge = self._Parent._Screen._TitleBar.GetWifiStrength(self._Stren.replace('%', ''))
-
+        
+        ge = self._Parent._Screen._TitleBar.GetWifiStrength( self._Stren.replace('%',''))
+        
         if ge > 0:
             self._Icons["wifistatus"]._IconIndex = ge
-            self._Icons["wifistatus"].NewCoord(self._Width - 23, self._PosY)
+            self._Icons["wifistatus"].NewCoord(self._Width-23,self._PosY)
             self._Icons["wifistatus"].Draw()
-
+            
         else:
             self._Icons["wifistatus"]._IconIndex = 0
-            self._Icons["wifistatus"].NewCoord(self._Width - 23, self._PosY)
+            self._Icons["wifistatus"].NewCoord(self._Width-23,self._PosY)
             self._Icons["wifistatus"].Draw()
+        
+        pygame.draw.line(self._Parent._CanvasHWND,(169,169,169),(self._PosX,self._PosY+self._Height-1),(self._PosX+self._Width,self._PosY+self._Height-1),1)        
+        
 
-        pygame.draw.line(self._Parent._CanvasHWND, (169, 169, 169), (self._PosX, self._PosY + self._Height - 1),
-                         (self._PosX + self._Width, self._PosY + self._Height - 1), 1)

+ 1 - 0
Menu/GameShell/10_Settings/Wifi/pages.py

@@ -14,6 +14,7 @@
 
 
 ## local UI import
+from libs.DBUS      import bus,daemon,wireless,wired
 
 from keyboard import Keyboard
 from wifi_list import WifiList

+ 9 - 10
Menu/GameShell/10_Settings/Wifi/text_item.py

@@ -1,29 +1,28 @@
 # -*- coding: utf-8 -*- 
-# local import
-from UI.constants import Width, Height, ICON_TYPES
+#local import
+from UI.constants import Width,Height,ICON_TYPES
 from UI.icon_item import IconItem
 from UI.util_funcs import midRect
 
-
 class TextItem(IconItem):
     _PosX = 0
     _PosY = 0
     _Width = 0
     _Height = 0
-    _Str = ""
-    _Color = (83, 83, 83)
+    _Str    = ""
+    _Color = (83,83,83)
     _FontObj = None
-    _Bold = False
-    _MyType = ICON_TYPES["LETTER"]
-    _Parent = None
+    _Bold    = False
+    _MyType  = ICON_TYPES["LETTER"] 
+    _Parent  = None
 
     def Draw(self):
         self._FontObj.set_bold(self._Bold)
-        my_text = self._FontObj.render(self._Str, True, self._Color)
+        my_text = self._FontObj.render(self._Str,True,self._Color)
         if my_text.get_width() != self._Width:
             self._Width = my_text.get_width()
         if my_text.get_height() != self._Height:
             self._Height = my_text.get_height()
 
         self._Parent._CanvasHWND.blit(my_text, \
-                                      midRect(self._PosX, self._PosY, self._Width, self._Height, Width, Height))
+            midRect(self._PosX,self._PosY,self._Width,self._Height,Width,Height))

+ 1 - 0
Menu/GameShell/10_Settings/Wifi/textarea.py

@@ -7,6 +7,7 @@ from libs.roundrects import aa_round_rect
 
 
 ## local UI import
+from UI.page         import Page,PageStack,PageSelector
 from UI.label        import Label
 from UI.fonts        import fonts
 

+ 253 - 238
Menu/GameShell/10_Settings/Wifi/wifi_list.py

@@ -1,21 +1,24 @@
 # -*- coding: utf-8 -*- 
 
-import gobject
-import myvars
 import pygame
-from UI.confirm_page import ConfirmPage
-## local UI import
-from UI.constants import Width
-from UI.fonts import fonts
-from UI.keys_def import CurKeys
-from UI.label import Label
-from UI.page import Page, PageSelector
-from UI.scroller import ListScroller
-from UI.util_funcs import SwapAndShow
+
 from beeprint import pp
 from libs.roundrects import aa_round_rect
+import gobject
+from wicd import misc 
+## local UI import
+from UI.constants import Width,Height
+from UI.page   import Page,PageSelector
+from UI.label  import Label
+from UI.fonts  import fonts
+from UI.util_funcs import midRect,SwapAndShow
+from UI.keys_def   import CurKeys
+from UI.scroller   import ListScroller
+from UI.confirm_page import ConfirmPage
+
 from net_item import NetItem
-from wicd import misc
+
+import myvars
 
 
 class InfoPageListItem(object):
@@ -25,160 +28,163 @@ class InfoPageListItem(object):
     _Height = 30
 
     _Labels = {}
-    _Icons = {}
-    _Fonts = {}
+    _Icons  = {}
+    _Fonts  = {}
 
     _LinkObj = None
-
+    
     def __init__(self):
         self._Labels = {}
-        self._Icons = {}
-        self._Fonts = {}
+        self._Icons  = {}
+        self._Fonts  = {}
 
-    def SetSmallText(self, text):
+    def SetSmallText(self,text):
+        
         l = Label()
         l._PosX = 40
         l.SetCanvasHWND(self._Parent._CanvasHWND)
-        l.Init(text, self._Fonts["small"])
+        l.Init(text,self._Fonts["small"])
         self._Labels["Small"] = l
+        
+    def Init(self,text):
 
-    def Init(self, text):
-        # self._Fonts["normal"] = fonts["veramono12"]
-
+        #self._Fonts["normal"] = fonts["veramono12"]
+        
         l = Label()
         l._PosX = 10
         l.SetCanvasHWND(self._Parent._CanvasHWND)
 
-        l.Init(text, self._Fonts["normal"])
+        l.Init(text,self._Fonts["normal"])
         self._Labels["Text"] = l
 
     def Draw(self):
-        self._Labels["Text"]._PosY = self._PosY + (self._Height - self._Labels["Text"]._Height) / 2
+        
+        self._Labels["Text"]._PosY = self._PosY + (self._Height - self._Labels["Text"]._Height)/2
         self._Labels["Text"].Draw()
 
         if "Small" in self._Labels:
-            self._Labels["Small"]._PosX = self._Width - self._Labels["Small"]._Width - 5
-
-            self._Labels["Small"]._PosY = self._PosY + (self._Height - self._Labels["Small"]._Height) / 2
+            self._Labels["Small"]._PosX = self._Width - self._Labels["Small"]._Width-5
+            
+            self._Labels["Small"]._PosY = self._PosY + (self._Height - self._Labels["Small"]._Height)/2
             self._Labels["Small"].Draw()
-
-        pygame.draw.line(self._Parent._CanvasHWND, (169, 169, 169), (self._PosX, self._PosY + self._Height - 1),
-                         (self._PosX + self._Width, self._PosY + self._Height - 1), 1)
+        
+        pygame.draw.line(self._Parent._CanvasHWND,(169,169,169),(self._PosX,self._PosY+self._Height-1),(self._PosX+self._Width,self._PosY+self._Height-1),1)
+    
 
 
 class WifiDisconnectConfirmPage(ConfirmPage):
-    _ConfirmText = "Confirm Disconnect?"
 
-    def KeyDown(self, event):
+    _ConfirmText = "Confirm Disconnect?"
+    
+    def KeyDown(self,event):
         if event.key == CurKeys["Menu"] or event.key == CurKeys["A"]:
             self.ReturnToUpLevelPage()
             self._Screen.Draw()
             self._Screen.SwapAndShow()
-
+            
         if event.key == CurKeys["B"]:
             self.SnapMsg("Disconnecting...")
             self._Screen.Draw()
             self._Screen.SwapAndShow()
-
+            
             self._Parent._Daemon.Disconnect()
-
+            
             pygame.time.delay(400)
-
+            
             self.ReturnToUpLevelPage()
             self._Screen.Draw()
             self._Screen.SwapAndShow()
-
+            
+                    
     def Draw(self):
-        # self.ClearCanvas()
+        #self.ClearCanvas()
         self.DrawBG()
         for i in self._MyList:
             i.Draw()
-
+        
         self.Reset()
-
-
+        
 class WifiInfoPageSelector(PageSelector):
-    _BackgroundColor = pygame.Color(131, 199, 219)
+    _BackgroundColor = pygame.Color(131,199,219)
 
     def __init__(self):
         self._PosX = 0
         self._PosY = 0
         self._Height = 0
-        self._Width = Width
+        self._Width  = Width
 
-    def AnimateDraw(self, x2, y2):
+    def AnimateDraw(self,x2,y2):
         pass
 
     def Draw(self):
         idx = self._Parent._PsIndex
         if idx < len(self._Parent._MyList):
             x = 2
-            y = self._Parent._MyList[idx]._PosY + 1
-            h = self._Parent._MyList[idx]._Height - 3
-
+            y = self._Parent._MyList[idx]._PosY+1
+            h = self._Parent._MyList[idx]._Height -3
+            
             self._PosX = x
             self._PosY = y
             self._Height = h
-
-            aa_round_rect(self._Parent._CanvasHWND,
-                          (x, y, self._Width - 4, h), self._BackgroundColor, 4, 0, self._BackgroundColor)
-
-
+            
+            aa_round_rect(self._Parent._CanvasHWND,  
+                          (x,y,self._Width-4,h),self._BackgroundColor,4,0,self._BackgroundColor)
+            
 class WifiInfoPage(Page):
-    _FootMsg = ["Nav.", "Disconnect", "", "Back", ""]
+    _FootMsg =  ["Nav.","Disconnect","","Back",""]
     _MyList = []
     _ListFontObj = fonts["varela15"]
 
     _Wireless = None
-    _Daemon = None
-
+    _Daemon   = None
+    
     _AList = {}
     _NetworkId = -1
-
+    
     def GenList(self):
-
+        
         self._MyList = []
         if self._NetworkId != -1:
             self._AList["ip"]["value"] = "Not Connected"
-
+            
             if self._Wireless.GetCurrentNetworkID(self._Wireless.GetIwconfig()) == self._NetworkId:
                 ip = self._Wireless.GetWirelessIP('')
-
+            
                 if ip is not None:
                     self._AList["ip"]["value"] = ip
-
-            self._AList["bssid"]["value"] = self._Wireless.GetWirelessProperty(self._NetworkId, "bssid")
-
-        start_x = 0
-        start_y = 0
-
-        for i, v in enumerate(self._AList):
+            
+            self._AList["bssid"]["value"] = self._Wireless.GetWirelessProperty(self._NetworkId,"bssid")
+        
+        start_x  = 0
+        start_y  = 0
+        
+        for i,v in enumerate( self._AList):
             li = InfoPageListItem()
             li._Parent = self
-            li._PosX = start_x
-            li._PosY = start_y + i * InfoPageListItem._Height
-            li._Width = Width
+            li._PosX   = start_x
+            li._PosY   = start_y + i*InfoPageListItem._Height
+            li._Width  = Width
             li._Fonts["normal"] = self._ListFontObj
             li._Fonts["small"] = fonts["varela12"]
-
+            
             if self._AList[v]["label"] != "":
-                li.Init(self._AList[v]["label"])
+                li.Init(  self._AList[v]["label"] )
             else:
-                li.Init(self._AList[v]["key"])
+                li.Init( self._AList[v]["key"] )
 
             li._Flag = self._AList[v]["key"]
 
-            li.SetSmallText(self._AList[v]["value"])
-
+            li.SetSmallText( self._AList[v]["value"] )
+            
             self._MyList.append(li)
-
+            
     def Init(self):
         if self._Screen != None:
             if self._Screen._CanvasHWND != None and self._CanvasHWND == None:
                 self._CanvasHWND = self._Screen._CanvasHWND
 
-        self._PosX = self._Index * self._Screen._Width
-        self._Width = self._Screen._Width  ## equal to screen width
+        self._PosX = self._Index*self._Screen._Width 
+        self._Width = self._Screen._Width ## equal to screen width
         self._Height = self._Screen._Height
 
         ps = WifiInfoPageSelector()
@@ -190,23 +196,23 @@ class WifiInfoPage(Page):
         ip["key"] = "ip"
         ip["label"] = "IP"
         ip["value"] = "Not Connected"
-
+        
         bssid = {}
         bssid["key"] = "bssid"
         bssid["label"] = "BSSID"
         bssid["value"] = ""
-
+        
         self._AList["ip"] = ip
         self._AList["bssid"] = bssid
-
+        
         self.GenList()
 
         self._DisconnectConfirmPage = WifiDisconnectConfirmPage()
         self._DisconnectConfirmPage._Screen = self._Screen
-        self._DisconnectConfirmPage._Name = "Confirm Disconnect"
+        self._DisconnectConfirmPage._Name   = "Confirm Disconnect"
         self._DisconnectConfirmPage._Parent = self
         self._DisconnectConfirmPage.Init()
-
+        
     def ScrollUp(self):
         if len(self._MyList) == 0:
             return
@@ -217,38 +223,39 @@ class WifiInfoPage(Page):
         if cur_li._PosY < 0:
             for i in range(0, len(self._MyList)):
                 self._MyList[i]._PosY += self._MyList[i]._Height
+        
 
     def ScrollDown(self):
         if len(self._MyList) == 0:
             return
-        self._PsIndex += 1
+        self._PsIndex +=1
         if self._PsIndex >= len(self._MyList):
-            self._PsIndex = len(self._MyList) - 1
+            self._PsIndex = len(self._MyList) -1
 
         cur_li = self._MyList[self._PsIndex]
-        if cur_li._PosY + cur_li._Height > self._Height:
-            for i in range(0, len(self._MyList)):
+        if cur_li._PosY +cur_li._Height > self._Height:
+            for i in range(0,len(self._MyList)):
                 self._MyList[i]._PosY -= self._MyList[i]._Height
 
     def Click(self):
         cur_li = self._MyList[self._PsIndex]
-        print(cur_li._Flag)
+        print(cur_li._Flag)        
 
     def TryDisconnect(self):
         if self._Wireless.GetCurrentNetworkID(self._Wireless.GetIwconfig()) == self._NetworkId \
-                and self._Wireless.GetWirelessIP('') is not None:
+           and self._Wireless.GetWirelessIP('') is not None:
             self._Screen.PushPage(self._DisconnectConfirmPage)
             self._Screen.Draw()
             self._Screen.SwapAndShow()
         else:
             return
-
+        
     def OnLoadCb(self):
         if self._Wireless.GetCurrentNetworkID(self._Wireless.GetIwconfig()) == self._NetworkId \
-                and self._Wireless.GetWirelessIP('') is not None:
+           and self._Wireless.GetWirelessIP('') is not None:
             self._FootMsg[1] = "Disconnect"
         else:
-            self._FootMsg[1] = ""
+            self._FootMsg[1] =  ""
 
         self.GenList()
 
@@ -256,13 +263,13 @@ class WifiInfoPage(Page):
         self.ReturnToUpLevelPage()
         self._Screen.Draw()
         self._Screen.SwapAndShow()
-
-    def KeyDown(self, event):
+        
+    def KeyDown(self,event):
         if event.key == CurKeys["A"] or event.key == CurKeys["Menu"]:
             self.ReturnToUpLevelPage()
             self._Screen.Draw()
             self._Screen.SwapAndShow()
-
+        
         if event.key == CurKeys["Up"]:
             self.ScrollUp()
             self._Screen.Draw()
@@ -271,13 +278,14 @@ class WifiInfoPage(Page):
             self.ScrollDown()
             self._Screen.Draw()
             self._Screen.SwapAndShow()
+        
 
         if event.key == CurKeys["Enter"]:
             self.Click()
 
         if event.key == CurKeys["X"]:
             self.TryDisconnect()
-
+                                
     def Draw(self):
         self.ClearCanvas()
         self._Ps.Draw()
@@ -286,90 +294,91 @@ class WifiInfoPage(Page):
             i.Draw()
 
 
+        
+    
 class WifiListSelector(PageSelector):
-    _BackgroundColor = pygame.Color(131, 199, 219)
+    _BackgroundColor = pygame.Color(131,199,219)
 
     def __init__(self):
         self._PosX = 0
         self._PosY = 0
         self._Height = 0
 
-    def AnimateDraw(self, x2, y2):
-        pass
+    def AnimateDraw(self,x2,y2):
+        pass 
+
 
     def Draw(self):
         idx = self._Parent._PsIndex
-        if idx < len(self._Parent._WirelessList):
-            x = self._Parent._WirelessList[idx]._PosX + 11
-            y = self._Parent._WirelessList[idx]._PosY + 1
-            h = self._Parent._WirelessList[idx]._Height - 3
-
+        if idx < len( self._Parent._WirelessList):
+            x = self._Parent._WirelessList[idx]._PosX+11
+            y = self._Parent._WirelessList[idx]._PosY+1
+            h = self._Parent._WirelessList[idx]._Height -3
+        
             self._PosX = x
             self._PosY = y
             self._Height = h
 
-            aa_round_rect(self._Parent._CanvasHWND,
-                          (x, y, self._Width, h), self._BackgroundColor, 4, 0, self._BackgroundColor)
+            aa_round_rect(self._Parent._CanvasHWND,  
+                          (x,y,self._Width,h),self._BackgroundColor,4,0,self._BackgroundColor)
 
 
 class WifiListMessageBox(Label):
     _Parent = None
 
     def Draw(self):
-        my_text = self._FontObj.render(self._Text, True, self._Color)
-        w = my_text.get_width()
-        h = my_text.get_height()
-        x = (self._Parent._Width - w) / 2
-        y = (self._Parent._Height - h) / 2
-        padding = 10
-        pygame.draw.rect(self._CanvasHWND, (255, 255, 255),
-                         (x - padding, y - padding, w + padding * 2, h + padding * 2))
-
-        pygame.draw.rect(self._CanvasHWND, (0, 0, 0), (x - padding, y - padding, w + padding * 2, h + padding * 2), 1)
+        my_text = self._FontObj.render( self._Text,True,self._Color)
+        w  = my_text.get_width()
+        h  = my_text.get_height()
+        x  = (self._Parent._Width - w)/2
+        y =  (self._Parent._Height - h)/2
+        padding = 10 
+        pygame.draw.rect(self._CanvasHWND,(255,255,255),(x-padding,y-padding, w+padding*2,h+padding*2))        
 
-        self._CanvasHWND.blit(my_text, (x, y, w, h))
+        pygame.draw.rect(self._CanvasHWND,(0,0,0),(x-padding,y-padding, w+padding*2,h+padding*2),1)
 
+        self._CanvasHWND.blit(my_text,(x,y,w,h))
 
 class WifiList(Page):
     _WirelessList = []
-    # Wicd dbus part
+    #Wicd dbus part
     _Wireless = None
-    _Daemon = None
-    _Dbus = None
+    _Daemon   = None
+    _Dbus     = None
     _WifiPassword = ""
     _Connecting = False
-    _Scanning = False
-
+    _Scanning   = False 
+    
     _PrevWicdState = None
-
+    
     _Selector = None
-
-    _ShowingMessageBox = False
-    _MsgBox = None
-    _ConnectTry = 0
-    _BlockingUI = False
-    _BlockCb = None
-
-    _LastStatusMsg = ""
-    _FootMsg = ["Nav.", "Scan", "Info", "Back", "Enter"]
-    _EncMethods = None
-    _Scroller = None
-    _ListFontObj = fonts["notosanscjk15"]
-
-    _InfoPage = None
-
+    
+    _ShowingMessageBox = False 
+    _MsgBox            = None
+    _ConnectTry        = 0
+    _BlockingUI        = False
+    _BlockCb           = None
+    
+    _LastStatusMsg     = ""
+    _FootMsg           = ["Nav.","Scan","Info","Back","Enter"]
+    _EncMethods        = None
+    _Scroller          = None
+    _ListFontObj       = fonts["notosanscjk15"]
+
+    _InfoPage          = None
+    
     def __init__(self):
         Page.__init__(self)
         self._WirelessList = []
         self._CanvasHWND = None
-
-    def ShowBox(self, msg):
+    
+    def ShowBox(self,msg):
         self._MsgBox._Text = msg
         self._ShowingMessageBox = True
         self._Screen.Draw()
         self._MsgBox.Draw()
         self._Screen.SwapAndShow()
-
+    
     def HideBox(self):
         self.Draw()
         self._ShowingMessageBox = False
@@ -380,7 +389,7 @@ class WifiList(Page):
         start_x = 0
         start_y = 0
 
-        for network_id in range(0, self._Wireless.GetNumberOfNetworks()):
+        for network_id in range(0,self._Wireless.GetNumberOfNetworks()):
             is_active = \
                 self._Wireless.GetCurrentSignalStrength("") != 0 and \
                 self._Wireless.GetCurrentNetworkID(self._Wireless.GetIwconfig()) == network_id \
@@ -389,39 +398,38 @@ class WifiList(Page):
             ni = NetItem()
             ni._Parent = self
             ni._PosX = start_x
-            ni._PosY = start_y + network_id * NetItem._Height
+            ni._PosY = start_y + network_id* NetItem._Height
             ni._Width = Width
             ni._FontObj = self._ListFontObj
-            # ni._Bssid   = self._Wireless.GetWirelessProperty(network_id,"bssid")
-
-            ni.Init(network_id, is_active)
+            #ni._Bssid   = self._Wireless.GetWirelessProperty(network_id,"bssid")
+            
+            ni.Init(network_id,is_active)
             self._WirelessList.append(ni)
 
         self._PsIndex = 0
-
+        
     def Disconnect(self):
-        self._Connecting = False
+        self._Connecting= False
         self._Daemon.Disconnect()
-
     ## force to disconnect
     def ShutDownConnecting(self):
-        print("Shutdownconnecting...", self._ConnectTry)
+        print("Shutdownconnecting...",self._ConnectTry)
         self._Daemon.CancelConnect()
         self._Daemon.SetForcedDisconnect(True)
         self._Connecting = False
 
-    def Rescan(self, sync=False):
+    def Rescan(self,sync=False):
         print("start Rescan")
         if self._Wireless != None:
             self._Wireless.Scan(sync)
 
-    ## dbus signal functions
+## dbus signal functions
     def DbusScanFinishedSig(self):
 
         if self._Screen._CurrentPage != self:
             return
         self.ResetPageSelector()
-
+        
         self.UpdateNetList(force_check=True)
 
         self._Scanning = False
@@ -430,38 +438,39 @@ class WifiList(Page):
         print("dbus says scan finished")
 
     def DbusScanStarted(self):
-        if self._Screen._CurrentPage != self:
+        if self._Screen._CurrentPage !=self:
             return
-
+        
         self._Scanning = True
         self.ShowBox("Wifi scanning...")
         self._BlockingUI = True
         print("dbus says start scan...")
 
-    def UpdateNetList(self, state=None, info=None, force_check=False, firstrun=False):
+
+    def UpdateNetList(self,state=None,info=None,force_check=False,firstrun=False):
 
         if self._Daemon == None:
             return
-
+        
         if not state:
-            state, trash = self._Daemon.GetConnectionStatus()
+            state,trash = self._Daemon.GetConnectionStatus()
             print("state")
             pp(state)
             print("Trash: ")
             pp(trash)
 
         if force_check or self._PrevWicdState != state:
-            self.GenNetworkList()  ## refresh the network list
-
+            self.GenNetworkList() ## refresh the network list 
+        
         if info != None:
             if len(info) > 3:
-                _id = int(info[3])
+                _id  = int(info[3])
                 if _id < len(self._WirelessList):
-                    self._WirelessList[_id].UpdateStrenLabel(str(info[2]))
+                    self._WirelessList[_id].UpdateStrenLabel( str(info[2]))
 
         self._PrevWicdState = state
-
-    def SetConnectingStatus(self, fast):
+        
+    def SetConnectingStatus(self,fast):
         wireless_connecting = self._Wireless.CheckIfWirelessConnecting()
 
         """
@@ -472,7 +481,7 @@ class WifiList(Page):
             self._BlockingUI = False
             return False
         """
-
+        
         if wireless_connecting:
             if not fast:
                 iwconfig = self._Wireless.GetIwconfig()
@@ -480,15 +489,15 @@ class WifiList(Page):
                 iwconfig = ''
             essid = self._Wireless.GetCurrentNetwork(iwconfig)
             stat = self._Wireless.CheckWirelessConnectingMessage()
-            if self._LastStatusMsg != "%s: %s" % (essid, stat):
-                print("%s: %s" % (essid, stat))
-                self._LastStatusMsg = "%s: %s" % (essid, stat)
+            if self._LastStatusMsg != "%s: %s"%(essid,stat):
+                print("%s: %s" %(essid,stat))
+                self._LastStatusMsg = "%s: %s"%(essid,stat)
                 self.ShowBox(self._LastStatusMsg)
-
+                
                 self._Screen._FootBar.UpdateNavText(self._LastStatusMsg)
                 SwapAndShow()
-
-            # self._ConnectTry+=1
+                
+            #self._ConnectTry+=1
 
             return True
         else:
@@ -499,36 +508,37 @@ class WifiList(Page):
         print("UpdateStatus")
         wireless_connecting = self._Wireless.CheckIfWirelessConnecting()
         fast = not self._Daemon.NeedsExternalCalls()
-
+        
         self._Connecting = wireless_connecting
-
+        
         if self._Connecting:
-            gobject.timeout_add(250, self.SetConnectingStatus, fast)
+            gobject.timeout_add(250,self.SetConnectingStatus,fast)
         else:
             if not fast:
                 iwconfig = self._Wireless.GetIwconfig()
             else:
                 iwconfig = ''
 
-            if self.CheckForWireless(iwconfig, self._Wireless.GetWirelessIP(''), None):
+            if self.CheckForWireless(iwconfig,self._Wireless.GetWirelessIP(''),None):
                 return True
             else:
                 print("Not Connected")
                 return True
 
-    def DbusDaemonStatusChangedSig(self, state=None, info=None):
+    def DbusDaemonStatusChangedSig(self,state=None,info=None):
         print("in DbusDaemonStatusChangedSig")
         """
         dbus.UInt32(2L)
         ['192.168.31.141', 'TP-LINK4G', '88', '0', '72.2 Mb/s']
         """
         pp(info)
-        self.UpdateNetList(state, info)
+        self.UpdateNetList(state,info)
         if info != None:
             self._Screen.Draw()
             self._Screen.SwapAndShow()
+        
 
-    def DbusConnectResultsSent(self, result):
+    def DbusConnectResultsSent(self,result):
         print(" in DbusConnectResultsSent")
         """
          in DbusConnectResultsSent
@@ -538,7 +548,7 @@ class WifiList(Page):
         """
         if result != None:
             print(result)
-
+            
         self._Connecting = False
         self._BlockingUI = False
         if self._BlockCb != None:
@@ -546,8 +556,8 @@ class WifiList(Page):
             self._BlockCb = None
 
         self._Screen._FootBar.ResetNavText()
-
-    def CheckForWireless(self, iwconfig, wireless_ip, set_status):
+    
+    def CheckForWireless(self,iwconfig,wireless_ip,set_status):
         if not wireless_ip:
             return False
         network = self._Wireless.GetCurrentNetwork(iwconfig)
@@ -565,15 +575,15 @@ class WifiList(Page):
         ip = misc.to_unicode(wireless_ip)
 
         print(_('Connected to $A at $B (IP: $C)').replace
-              ('$A', network).replace
-              ('$B', strength).replace
-              ('$C', ip))
-
+                    ('$A', network).replace
+                    ('$B', strength).replace
+                    ('$C', ip))
+        
         return True
 
-    def ConfigWireless(self, password):
+    def ConfigWireless(self,password):
         netid = self._PsIndex
-        print(netid, " ", password)
+        print(netid," ", password)
         """
         self._Wireless.SetWirelessProperty(netid,"dhcphostname","GameShell")
         self._Wireless.SetWirelessProperty(netid,"ip","None")
@@ -591,35 +601,36 @@ class WifiList(Page):
         self._Wireless.SetWirelessProperty(netid,"use_static_dns",0)
         self._Wireless.SetWirelessProperty(netid,"search_domain","None")
         """
-        self._Wireless.SetWirelessProperty(netid, "enctype", "wpa-psk")
-        self._Wireless.SetWirelessProperty(netid, "apsk", password)
-        self._Wireless.SetWirelessProperty(netid, "automatic", 1)
+        self._Wireless.SetWirelessProperty(netid,"enctype","wpa-psk")
+        self._Wireless.SetWirelessProperty(netid,"apsk",password)
+        self._Wireless.SetWirelessProperty(netid,"automatic",1)
 
+        
         self._WirelessList[netid].Connect()
         print("after Connect")
         self.UpdateStatus()
 
-    def GetWirelessEncrypt(self, network_id):
+    def GetWirelessEncrypt(self,network_id):
         results = []
         activeID = -1
-        for x, enc_type in enumerate(self._EncMethods):
-            if enc_type["type"] == self._Wireless.GetWirelessProperty(network_id, "enctype"):
+        for x,enc_type in enumerate(self._EncMethods):
+            if enc_type["type"] == self._Wireless.GetWirelessProperty(network_id,"enctype"):
                 activeID = x
                 break
 
         if activeID == -1:
             return results
-
-        for type_ in ['required', 'optional']:
+        
+        for type_ in ['required','optional']:
             fields = self._EncMethods[activeID][type_]
             for field in fields:
                 try:
-                    text = field[1].lower().replace(' ', '_')
+                    text = field[1].lower().replace(' ','_')
                 except KeyError:
-                    text = field[1].replace(' ', '_')
-
+                    text = field[1].replace(' ','_')
+                
                 value = self._Wireless.GetWirelessProperty(network_id, field[0])
-                results.append({text: value})
+                results.append({text:value})
         """
         [{'preshared_key': 'blah blah blah',},]
 
@@ -632,26 +643,27 @@ class WifiList(Page):
     def ScrollUp(self):
         if len(self._WirelessList) == 0:
             return
-        self._PsIndex -= 1
+        self._PsIndex-=1
         if self._PsIndex < 0:
             self._PsIndex = 0
-
+        
         cur_ni = self._WirelessList[self._PsIndex]
         if cur_ni._PosY < 0:
-            for i in range(0, len(self._WirelessList)):
+            for i in range(0,len(self._WirelessList)):
                 self._WirelessList[i]._PosY += self._WirelessList[i]._Height
-
+            
     def ScrollDown(self):
         if len(self._WirelessList) == 0:
             return
-        self._PsIndex += 1
+        self._PsIndex+=1
         if self._PsIndex >= len(self._WirelessList):
-            self._PsIndex = len(self._WirelessList) - 1
-
+            self._PsIndex = len(self._WirelessList) -1
+       
         cur_ni = self._WirelessList[self._PsIndex]
         if cur_ni._PosY + cur_ni._Height > self._Height:
-            for i in range(0, len(self._WirelessList)):
+            for i in range(0,len(self._WirelessList)):
                 self._WirelessList[i]._PosY -= self._WirelessList[i]._Height
+    
 
     def AbortedAndReturnToUpLevel(self):
         self.HideBox()
@@ -659,20 +671,20 @@ class WifiList(Page):
         self.ReturnToUpLevelPage()
         self._Screen.Draw()
         self._Screen.SwapAndShow()
-
-    def KeyDown(self, event):
+        
+    def KeyDown(self,event):
 
         if self._BlockingUI == True:
             print("UI blocking ...")
             return
-
+        
         if event.key == CurKeys["A"] or event.key == CurKeys["Menu"]:
             if self._Wireless != None:
                 wireless_connecting = self._Wireless.CheckIfWirelessConnecting()
                 if wireless_connecting:
                     self.ShutDownConnecting()
                     self.ShowBox("ShutDownConnecting...")
-                    self._BlockingUI = True
+                    self._BlockingUI=True
                     self._BlockCb = self.AbortedAndReturnToUpLevel
                 else:
                     self.AbortedAndReturnToUpLevel()
@@ -681,7 +693,7 @@ class WifiList(Page):
                 self.ReturnToUpLevelPage()
                 self._Screen.Draw()
                 self._Screen.SwapAndShow()
-
+    
         if event.key == CurKeys["Up"]:
             self.ScrollUp()
             self._Screen.Draw()
@@ -690,19 +702,19 @@ class WifiList(Page):
             self.ScrollDown()
             self._Screen.Draw()
             self._Screen.SwapAndShow()
-
-        if event.key == CurKeys["Enter"]:  ## enter to set password,enter is B on GM
+            
+        if event.key == CurKeys["Enter"]: ## enter to set password,enter is B on GM
             if len(self._WirelessList) == 0:
                 return
-
+            
             wicd_wirelss_encrypt_pwd = self.GetWirelessEncrypt(self._PsIndex)
-
+            
             if self._WirelessList[self._PsIndex]._IsActive:
-                self.ShowBox(self._Wireless.GetWirelessIP(''))
+                self.ShowBox( self._Wireless.GetWirelessIP('')    )
             else:
                 self._Screen.PushCurPage()
-                self._Screen.SetCurPage(myvars.PasswordPage)
-
+                self._Screen.SetCurPage( myvars.PasswordPage )
+                
                 thepass = ""
                 for i in wicd_wirelss_encrypt_pwd:
                     if "preshared_key" in i:
@@ -710,11 +722,11 @@ class WifiList(Page):
                             if len(i["preshared_key"]) > 0:
                                 thepass = i["preshared_key"]
                                 break
-
+                
                 myvars.PasswordPage.SetPassword(thepass)
                 self._Screen.Draw()
                 self._Screen.SwapAndShow()
-
+                
                 """
                 try:
                     self._Screen.Draw()
@@ -725,43 +737,44 @@ class WifiList(Page):
                 """
         if event.key == CurKeys["X"]:
             self.Rescan(False)
-
+            
         if event.key == CurKeys["Y"]:
             if len(self._WirelessList) == 0:
                 return
 
             self._InfoPage._NetworkId = self._PsIndex
-            self._InfoPage._Wireless = self._Wireless
-            self._InfoPage._Daemon = self._Daemon
-
+            self._InfoPage._Wireless  = self._Wireless
+            self._InfoPage._Daemon    = self._Daemon
+            
             self._Screen.PushPage(self._InfoPage)
             self._Screen.Draw()
             self._Screen.SwapAndShow()
+            
 
     def Init(self):
-
+        
         self._PosX = self._Index * self._Screen._Width
         self._Width = self._Screen._Width
         self._Height = self._Screen._Height
 
-        # self._CanvasHWND = pygame.Surface((self._Width,self._Height))
+        #self._CanvasHWND = pygame.Surface((self._Width,self._Height))
         self._CanvasHWND = self._Screen._CanvasHWND
 
         ps = WifiListSelector()
         ps._Parent = self
         ps._Width = Width - 12
-
+        
         self._Ps = ps
         self._PsIndex = 0
-
+        
         msgbox = WifiListMessageBox()
         msgbox._CanvasHWND = self._CanvasHWND
-        msgbox.Init(" ", fonts["veramono12"])
+        msgbox.Init(" ",fonts["veramono12"])
         msgbox._Parent = self
+        
+        self._MsgBox = msgbox 
 
-        self._MsgBox = msgbox
-
-        self._EncMethods = misc.LoadEncryptionMethods()  # load predefined templates from /etc/wicd/...
+        self._EncMethods = misc.LoadEncryptionMethods() # load predefined templates from /etc/wicd/...
 
         """
   {
@@ -777,8 +790,8 @@ class WifiList(Page):
     'type': 'wpa-psk',
   },
         """
-
-        self.UpdateNetList(force_check=True, firstrun=True)
+        
+        self.UpdateNetList(force_check=True,firstrun=True)
 
         self._Scroller = ListScroller()
         self._Scroller._Parent = self
@@ -786,20 +799,22 @@ class WifiList(Page):
         self._Scroller._PosY = 2
         self._Scroller.Init()
 
+
         self._InfoPage = WifiInfoPage()
         self._InfoPage._Screen = self._Screen
-        self._InfoPage._Name = "Wifi info"
+        self._InfoPage._Name   = "Wifi info"
         self._InfoPage.Init()
-
+        
     def Draw(self):
         self.ClearCanvas()
 
         if len(self._WirelessList) == 0:
             return
-
+        
         self._Ps.Draw()
         for i in self._WirelessList:
             i.Draw()
 
-        self._Scroller.UpdateSize(len(self._WirelessList) * NetItem._Height, self._PsIndex * NetItem._Height)
+        
+        self._Scroller.UpdateSize( len(self._WirelessList)*NetItem._Height, self._PsIndex*NetItem._Height)
         self._Scroller.Draw()

+ 17 - 6
Menu/GameShell/10_Settings/__init__.py

@@ -1,18 +1,29 @@
-# -*- coding: utf-8 -*-
+# -*- coding: utf-8 -*- 
 
+import pygame
+from pygame.locals import *
+from sys import exit
+import os
+import sys
 
-from . import myvars
-## local UI import
-from . import pages
+from datetime import datetime
+
+import base64
+from beeprint import pp
 
 
+## local UI import
+import pages
+import myvars
+
 def Init(main_screen):
     pages.InitListPage(main_screen)
 
-
 def API(main_screen):
-    if main_screen != None:
+    
+    if main_screen !=None:
         main_screen.PushCurPage()
         main_screen.SetCurPage(myvars.ListPage)
         main_screen.Draw()
         main_screen.SwapAndShow()
+        

+ 25 - 13
Menu/GameShell/10_Settings/list_item.py

@@ -2,15 +2,20 @@
 
 import pygame
 
-## local UI import
-from UI.label import Label
 
 
+## local UI import
+from UI.page   import Page
+from UI.label  import Label
+from UI.fonts  import fonts
+
 # a item for List
 # - - - - - - - - - - - -- 
 # | Icon  Text.....    > |
 # ------------------------
 
+import myvars # icons_path
+
 
 class ListItem(object):
     _PosX = 0
@@ -19,29 +24,36 @@ class ListItem(object):
     _Height = 30
 
     _Labels = {}
-    _Icons = {}
-    _Fonts = {}
+    _Icons  = {}
+    _Fonts  = {}
 
     _LinkObj = None
-
+    
     def __init__(self):
         self._Labels = {}
-        self._Icons = {}
-        self._Fonts = {}
+        self._Icons  = {}
+        self._Fonts  = {}
 
-    def Init(self, text):
-        # self._Fonts["normal"] = fonts["veramono12"]
 
+    
+    
+    def Init(self,text):
+
+        #self._Fonts["normal"] = fonts["veramono12"]
+        
         l = Label()
         l._PosX = 16
         l.SetCanvasHWND(self._Parent._CanvasHWND)
 
-        l.Init(text, self._Fonts["normal"])
+        l.Init(text,self._Fonts["normal"])
         self._Labels["Text"] = l
 
+
     def Draw(self):
-        self._Labels["Text"]._PosY = self._PosY + (self._Height - self._Labels["Text"]._Height) / 2
+
+        self._Labels["Text"]._PosY = self._PosY + (self._Height - self._Labels["Text"]._Height)/2
         self._Labels["Text"].Draw()
 
-        pygame.draw.line(self._Parent._CanvasHWND, (169, 169, 169), (self._PosX, self._PosY + self._Height - 1),
-                         (self._PosX + self._Width, self._PosY + self._Height - 1), 1)
+        pygame.draw.line(self._Parent._CanvasHWND,(169,169,169),(self._PosX,self._PosY+self._Height-1),(self._PosX+self._Width,self._PosY+self._Height-1),1)
+    
+

+ 64 - 55
Menu/GameShell/10_Settings/list_page.py

@@ -1,63 +1,68 @@
 # -*- coding: utf-8 -*- 
 
+import pygame
 import sys
 
-import pygame
-## local UI import
-from UI.constants import Width
-from UI.fonts import fonts
-from UI.keys_def import CurKeys
-from UI.page import Page, PageSelector
-from UI.scroller import ListScroller
 from libs.roundrects import aa_round_rect
 
-from . import myvars
-from .list_item import ListItem
+## local UI import
+from UI.constants import Width,Height
+from UI.page   import Page,PageSelector
+from UI.label  import Label
+from UI.fonts  import fonts
+from UI.util_funcs import midRect
+from UI.keys_def   import CurKeys
+from UI.scroller   import ListScroller
+
+from list_item  import ListItem
 
+import myvars
 
 class ListPageSelector(PageSelector):
-    _BackgroundColor = pygame.Color(131, 199, 219)
+    _BackgroundColor = pygame.Color(131,199,219)
 
     def __init__(self):
         self._PosX = 0
         self._PosY = 0
         self._Height = 0
-        self._Width = Width
+        self._Width  = Width
 
-    def AnimateDraw(self, x2, y2):
+    def AnimateDraw(self,x2,y2):
         pass
 
     def Draw(self):
         idx = self._Parent._PsIndex
         if idx < len(self._Parent._MyList):
             x = 2
-            y = self._Parent._MyList[idx]._PosY + 1
-            h = self._Parent._MyList[idx]._Height - 3
-
+            y = self._Parent._MyList[idx]._PosY+1
+            h = self._Parent._MyList[idx]._Height -3
+            
             self._PosX = x
             self._PosY = y
             self._Height = h
+            
+            aa_round_rect(self._Parent._CanvasHWND,  
+                          (x,y,self._Width-4,h),self._BackgroundColor,4,0,self._BackgroundColor)
 
-            aa_round_rect(self._Parent._CanvasHWND,
-                          (x, y, self._Width - 4, h), self._BackgroundColor, 4, 0, self._BackgroundColor)
 
 
 class ListPage(Page):
-    _Icons = {}
-    _Selector = None
 
-    _FootMsg = ["Nav", "", "", "Back", "Enter"]
+    _Icons = {}
+    _Selector=None
+    
+    _FootMsg = ["Nav","","","Back","Enter"]
     _MyList = []
     _ListFontObj = fonts["varela15"]
 
     _Scroller = None
-
+    
     def __init__(self):
         Page.__init__(self)
         self._Icons = {}
         self._CanvasHWND = None
         self._MyList = []
-
+        
     def Init(self):
         self._PosX = self._Index * self._Screen._Width
         self._Width = self._Screen._Width
@@ -71,36 +76,35 @@ class ListPage(Page):
         self._PsIndex = 0
 
         #                ""   pkgname, label
-        alist = [["", "Wifi", "Wi-Fi"],
-                 ["", "Sound", "Sound Volume"],
-                 ["", "Brightness", "BackLight Brightness"],
-                 ["", "Storage", ""],
-                 ["", "Update", ""],
-                 ["", "About", "About"],
-                 ["", "PowerOFF", "Power off"]]
-
-        start_x = 0
-        start_y = 0
-
-        sys.path.append(myvars.basepath)  # add self as import path
-
-        for i, v in enumerate(alist):
+        alist         = [["","Wifi","Wi-Fi"],
+                         ["","Sound","Sound Volume"],
+                         ["","Brightness","BackLight Brightness"],
+                         ["","Storage",""],
+                         ["","Update", ""],
+                         ["","About",  "About"],
+                         ["","PowerOFF","Power off"]]
+
+        start_x  = 0
+        start_y  = 0
+
+        sys.path.append(myvars.basepath)# add self as import path
+        
+        for i,v in enumerate(alist):
             li = ListItem()
             li._Parent = self
-            li._PosX = start_x
-            li._PosY = start_y + i * ListItem._Height
-            li._Width = Width
+            li._PosX   = start_x
+            li._PosY   = start_y + i*ListItem._Height
+            li._Width  = Width
             li._Fonts["normal"] = self._ListFontObj
 
             if v[2] != "":
                 li.Init(v[2])
             else:
                 li.Init(v[1])
-
-            if v[1] == "Wifi" or v[1] == "Sound" or v[1] == "Brightness" or v[1] == "Storage" or v[1] == "Update" or v[
-                1] == "About" or v[1] == "PowerOFF":
+            
+            if v[1] == "Wifi" or v[1] == "Sound" or v[1] == "Brightness" or v[1] == "Storage" or v[1] == "Update" or v[1] == "About" or v[1] == "PowerOFF":
                 li._LinkObj = __import__(v[1])
-                init_cb = getattr(li._LinkObj, "Init", None)
+                init_cb   = getattr(li._LinkObj,"Init",None)
                 if init_cb != None:
                     if callable(init_cb):
                         li._LinkObj.Init(self._Screen)
@@ -122,33 +126,35 @@ class ListPage(Page):
         if cur_li._PosY < 0:
             for i in range(0, len(self._MyList)):
                 self._MyList[i]._PosY += self._MyList[i]._Height
+        
 
     def ScrollDown(self):
         if len(self._MyList) == 0:
             return
-        self._PsIndex += 1
+        self._PsIndex +=1
         if self._PsIndex >= len(self._MyList):
-            self._PsIndex = len(self._MyList) - 1
+            self._PsIndex = len(self._MyList) -1
 
         cur_li = self._MyList[self._PsIndex]
-        if cur_li._PosY + cur_li._Height > self._Height:
-            for i in range(0, len(self._MyList)):
+        if cur_li._PosY +cur_li._Height > self._Height:
+            for i in range(0,len(self._MyList)):
                 self._MyList[i]._PosY -= self._MyList[i]._Height
 
     def Click(self):
         cur_li = self._MyList[self._PsIndex]
         if cur_li._LinkObj != None:
-            api_cb = getattr(cur_li._LinkObj, "API", None)
+            api_cb = getattr(cur_li._LinkObj,"API",None)
             if api_cb != None:
                 if callable(api_cb):
                     cur_li._LinkObj.API(self._Screen)
 
-    def KeyDown(self, event):
+        
+    def KeyDown(self,event):
         if event.key == CurKeys["A"] or event.key == CurKeys["Menu"]:
             self.ReturnToUpLevelPage()
             self._Screen.Draw()
             self._Screen.SwapAndShow()
-
+        
         if event.key == CurKeys["Up"]:
             self.ScrollUp()
             self._Screen.Draw()
@@ -157,25 +163,28 @@ class ListPage(Page):
             self.ScrollDown()
             self._Screen.Draw()
             self._Screen.SwapAndShow()
+        
 
         if event.key == CurKeys["Enter"]:
             self.Click()
-
+            
     def Draw(self):
         self.ClearCanvas()
 
         if len(self._MyList) * ListItem._Height > self._Height:
             self._Ps._Width = self._Width - 11
-
+            
             self._Ps.Draw()
-
+            
             for i in self._MyList:
                 i.Draw()
-
-            self._Scroller.UpdateSize(len(self._MyList) * ListItem._Height, self._PsIndex * ListItem._Height)
+        
+            self._Scroller.UpdateSize( len(self._MyList)*ListItem._Height, self._PsIndex*ListItem._Height)
             self._Scroller.Draw()
         else:
             self._Ps._Width = self._Width
             self._Ps.Draw()
             for i in self._MyList:
                 i.Draw()
+
+            

+ 4 - 1
Menu/GameShell/10_Settings/myvars.py

@@ -1,9 +1,12 @@
 # -*- coding: utf-8 -*- 
 
+from sys import exit
 import os
+import sys
+
 
 basepath = os.path.dirname(os.path.realpath(__file__))
 
-icons_path = basepath + "/icons"
+icons_path = basepath+"/icons"
 
 ListPage = None

+ 4 - 4
Menu/GameShell/10_Settings/pages.py

@@ -1,13 +1,13 @@
 # -*- coding: utf-8 -*- 
 
-from . import list_page
-
-from . import myvars
+from list_page import ListPage
 
+import myvars
 
 def InitListPage(main_screen):
-    myvars.ListPage = list_page.ListPage()
 
+    myvars.ListPage = ListPage()
+    
     myvars.ListPage._Screen = main_screen
     myvars.ListPage._Name = "Setting List"
     myvars.ListPage.Init()

+ 0 - 1
Menu/GameShell/CaveStory.sh

@@ -1,2 +1 @@
-#!/usr/bin/env bash
 retroarch -L /home/cpi/apps/emulators/nxengine_libretro.so /home/cpi/games/nxengine/cavestory/data

+ 9 - 6
Menu/GameShell/Music Player/__init__.py

@@ -1,9 +1,10 @@
-# -*- coding: utf-8 -*-
+# -*- coding: utf-8 -*- 
 
+import pygame
 
-from . import myvars
 ## local UI import
-from . import pages
+import pages
+import myvars
 
 def Init(main_screen):
     pages.InitPoller()
@@ -11,11 +12,13 @@ def Init(main_screen):
     pages.InitListPage(main_screen)
     pages.InitMusicLibPage(main_screen)
     pages.InitSpectrumPage(main_screen)
-
-
+    
 def API(main_screen):
-    if main_screen != None:
+    
+    if main_screen !=None:
         main_screen.PushCurPage()
         main_screen.SetCurPage(myvars.PlayListPage)
         main_screen.Draw()
         main_screen.SwapAndShow()
+
+

+ 57 - 51
Menu/GameShell/Music Player/list_item.py

@@ -1,46 +1,53 @@
 # -*- coding: utf-8 -*- 
 
 import pygame
+from libs.roundrects import aa_round_rect
+
 ## local UI import
 from UI.constants import ICON_TYPES
+from UI.page   import Page
+from UI.label  import Label
+from UI.fonts  import fonts
 from UI.icon_item import IconItem
-from UI.label import Label
-
+from UI.util_funcs import midRect
 
 # a item for List
 # - - - - - - - - - - - -- 
 # | Icon  Text.....    > |
 # ------------------------
 
+import myvars # icons_path
+
 class ListItemIcon(IconItem):
-    _CanvasHWND = None
-    _Parent = None
-    _Width = 18
-    _Height = 18
 
+    _CanvasHWND = None
+    _Parent     = None
+    _Width      = 18
+    _Height     = 18
+    
     def Draw(self):
-        self._CanvasHWND.blit(self._ImgSurf, (
-            self._PosX, self._PosY + (self._Parent._Height - self._Height) / 2, self._Width, self._Height))
+        self._CanvasHWND.blit(self._ImgSurf,(self._PosX,self._PosY+(self._Parent._Height-self._Height)/2,self._Width,self._Height))
 
 
 class ListItemLabel(Label):
-    _ActiveColor = pygame.Color(175, 90, 0)
-    _Active = False
 
+    _ActiveColor  = pygame.Color(175,90,0)
+    _Active = False
     def Draw(self):
-        self._FontObj.set_bold(self._Active)
 
+        self._FontObj.set_bold(self._Active)
+        
         """
         if self._Active == True:
             my_text = self._FontObj.render( self._Text,True,self._ActiveColor)
         else:
             my_text = self._FontObj.render( self._Text,True,self._Color)
         """
+        
+        my_text = self._FontObj.render( self._Text,True,self._Color)
+        self._CanvasHWND.blit(my_text,(self._PosX,self._PosY,self._Width,self._Height))
 
-        my_text = self._FontObj.render(self._Text, True, self._Color)
-        self._CanvasHWND.blit(my_text, (self._PosX, self._PosY, self._Width, self._Height))
-
-
+    
 class ListItem(object):
     _PosX = 0
     _PosY = 0
@@ -48,40 +55,43 @@ class ListItem(object):
     _Height = 30
 
     _Labels = {}
-    _Icons = {}
-    _Fonts = {}
+    _Icons  = {}
+    _Fonts  = {}
     _MyType = ICON_TYPES["EXE"]
     _LinkObj = None
-    _Path = ""
-    _Active = False
-    _Playing = False  ## play or pause
-    _PlayingProcess = 0  # 0 - 100
-    _Parent = None
-
-
+    _Path    = ""
+    _Active  = False
+    _Playing = False ## play or pause
+    _PlayingProcess = 0 # 0 - 100
+    _Parent  = None
+    
+    
     def __init__(self):
         self._Labels = {}
-        self._Icons = {}
-        self._Fonts = {}
+        self._Icons  = {}
+        self._Fonts  = {}
 
-    def Init(self, text):
 
-        # self._Fonts["normal"] = fonts["veramono12"]
+    def Init(self,text):
 
+        #self._Fonts["normal"] = fonts["veramono12"]
+        
         l = ListItemLabel()
         l._PosX = 22
         l.SetCanvasHWND(self._Parent._CanvasHWND)
 
         if self._MyType == ICON_TYPES["DIR"]:
-            l.Init(text, self._Fonts["normal"])
+            l.Init(text,self._Fonts["normal"])
             self._Path = text
         else:
-            l.Init(text, self._Fonts["normal"])
+            l.Init(text,self._Fonts["normal"])
             self._Path = text
 
-        self._Labels["Text"] = l
 
-    def NewCoord(self, x, y):
+        self._Labels["Text"] = l
+        
+        
+    def NewCoord(self,x,y):
         self._PosX = x
         self._PosY = y
 
@@ -89,39 +99,35 @@ class ListItem(object):
 
         if self._MyType == ICON_TYPES["DIR"] and self._Path != "[..]":
             self._Parent._Icons["sys"]._IconIndex = 0
-            self._Parent._Icons["sys"].NewCoord(self._PosX + 12,
-                                                self._PosY + (self._Height - self._Parent._Icons["sys"]._Height) / 2 +
-                                                self._Parent._Icons["sys"]._Height / 2)
+            self._Parent._Icons["sys"].NewCoord(self._PosX+12,self._PosY+ (self._Height - self._Parent._Icons["sys"]._Height)/2+self._Parent._Icons["sys"]._Height/2)
             self._Parent._Icons["sys"].Draw()
 
         if self._MyType == ICON_TYPES["FILE"]:
             self._Parent._Icons["sys"]._IconIndex = 1
-            self._Parent._Icons["sys"].NewCoord(self._PosX + 12,
-                                                self._PosY + (self._Height - self._Parent._Icons["sys"]._Height) / 2 +
-                                                self._Parent._Icons["sys"]._Height / 2)
+            self._Parent._Icons["sys"].NewCoord(self._PosX+12,self._PosY+ (self._Height - self._Parent._Icons["sys"]._Height)/2+self._Parent._Icons["sys"]._Height/2)
             self._Parent._Icons["sys"].Draw()
-
+        
         if self._Active == True:
             self._Labels["Text"]._Active = True
         else:
             self._Labels["Text"]._Active = False
 
-        self._Labels["Text"]._PosY = self._PosY + (self._Height - self._Labels["Text"]._Height) / 2
-
-        pygame.draw.line(self._Parent._CanvasHWND, (169, 169, 169), (self._PosX, self._PosY + self._Height - 1),
-                         (self._PosX + self._Width, self._PosY + self._Height - 1), 1)
+        
+        self._Labels["Text"]._PosY = self._PosY + (self._Height - self._Labels["Text"]._Height)/2
+            
+        pygame.draw.line(self._Parent._CanvasHWND,(169,169,169),(self._PosX,self._PosY+self._Height-1),(self._PosX+self._Width,self._PosY+self._Height-1),1)
 
         if self._Playing == True:
-            self._Labels["Text"]._Active = True
+            self._Labels["Text"]._Active =True
             self._Labels["Text"].Draw()
-            # _rect = midRect(10,self._PosY+15,10,10,self._Parent._Width,self._Parent._Height)
-            # aa_round_rect(self._Parent._CanvasHWND,_rect,(0,0,0),3,0,(0,0,0))
-            # pygame.draw.polygon(self._Parent._CanvasHWND, (0,0,0), [[6, self._PosY+7], [11, self._PosY+14],[6, self._PosY+21]], 2)
-
+            #_rect = midRect(10,self._PosY+15,10,10,self._Parent._Width,self._Parent._Height)
+            #aa_round_rect(self._Parent._CanvasHWND,_rect,(0,0,0),3,0,(0,0,0))
+            #pygame.draw.polygon(self._Parent._CanvasHWND, (0,0,0), [[6, self._PosY+7], [11, self._PosY+14],[6, self._PosY+21]], 2)
+            
             if self._PlayingProcess > 0:
-                seek_posx = int(self._Width * self._PlayingProcess / 100.0)
-                pygame.draw.line(self._Parent._CanvasHWND, (255, 169, 169), (self._PosX, self._PosY + self._Height - 2),
-                                 (self._PosX + seek_posx, self._PosY + self._Height - 2), 2)
+                seek_posx = int(self._Width * self._PlayingProcess/100.0)
+                pygame.draw.line(self._Parent._CanvasHWND,(255,169,169),(self._PosX,self._PosY+self._Height-2),(self._PosX+seek_posx,self._PosY+self._Height-2),2)   
 
         else:
             self._Labels["Text"].Draw()
+

+ 106 - 88
Menu/GameShell/Music Player/mpd_spectrum_page.py

@@ -1,18 +1,31 @@
 # -*- coding: utf-8 -*- 
 
-from queue import Queue, Empty
-from threading import Thread
-
-# import gobject
+import time
 import pygame
-## local UI import
-from UI.constants import Height
-from UI.fonts import fonts
-from UI.keys_def import CurKeys
-from UI.page import Page
+
+from numpy import fromstring,ceil,abs,log10,isnan,isinf,int16
 from numpy import fft as Fft
-from numpy import fromstring, ceil, abs, log10, isnan, isinf, int16
 
+import gobject
+
+from beeprint import pp
+
+## local UI import
+from UI.constants import Width,Height
+from UI.page   import Page,PageSelector
+from UI.label  import Label
+from UI.fonts  import fonts
+from UI.util_funcs import midRect
+from UI.keys_def   import CurKeys
+
+from Queue import Queue, Empty
+from threading  import Thread
+
+
+
+from list_item  import ListItem
+
+import myvars
 
 class PIFI(object):
     _MPD_FIFO = "/tmp/mpd.fifo"
@@ -20,125 +33,126 @@ class PIFI(object):
     _SAMPLING_RATE = 44100
     _FIRST_SELECTED_BIN = 5
     _NUMBER_OF_SELECTED_BINS = 10
-    _SCALE_WIDTH = Height / 2 - 20
+    _SCALE_WIDTH = Height/2 - 20
 
     count = 0
     average = 0
-
+    
     def __init__(self):
         self.sampleSize = self._SAMPLE_SIZE
         self.samplingRate = self._SAMPLING_RATE
         self.firstSelectedBin = self._FIRST_SELECTED_BIN
         self.numberOfSelectedBins = self._NUMBER_OF_SELECTED_BINS
-
+        
         # Initialization : frequency bins
         freq = Fft.fftfreq(self.sampleSize) * self.samplingRate
-        freqR = freq[:self.sampleSize / 2]
-        self.bins = freqR[self.firstSelectedBin:self.firstSelectedBin + self.numberOfSelectedBins]
-
+        freqR = freq[:self.sampleSize/2]
+        self.bins = freqR[self.firstSelectedBin:self.firstSelectedBin+self.numberOfSelectedBins]
+        
         self.resetSmoothing()
-
+    
     def resetSmoothing(self):
         self.count = 0
         self.average = 0
-
+        
     def smoothOut(self, x):
         self.count += 1
-        self.average = (self.average * self.count + x) / (self.count + 1)
+        self.average = (self.average*self.count + x) / (self.count+1)
         return self.average
-
+    
     def scaleList(self, _list):
-        for i, x in enumerate(_list):
+        for i,x in enumerate(_list):
             if isnan(x) or isinf(x):
                 _list[i] = 0
 
         # Compute a simple just-above 'moving average' of maximums
-        maximum = 1.1 * self.smoothOut(max(_list))
+        maximum = 1.1*self.smoothOut(max( _list ))
         if maximum == 0:
             scaleFactor = 0.0
         else:
-            scaleFactor = self._SCALE_WIDTH / float(maximum)
-
+            scaleFactor = self._SCALE_WIDTH/float(maximum)
+            
         # Compute the scaled list of values
-        scaledList = [int(x * scaleFactor) for x in _list]
+        scaledList = [int(x*scaleFactor) for x in _list ]
         return scaledList
-
+        
     def computeSpectrum(self, fifoFile):
-
+        
         # Read PCM samples from fifo
-        rawSamples = fifoFile.read(self.sampleSize)  # will return empty lines (non-blocking)
+        rawSamples = fifoFile.read(self.sampleSize)    # will return empty lines (non-blocking)
         if len(rawSamples) == 0:
             print("computeSpectrum read zero")
-            return [], []
+            return [],[]
         else:
             pass
-        ##            print("computeSpectrum %d " % len(rawSamples))
-
+##            print("computeSpectrum %d " % len(rawSamples))
+            
         pcm = fromstring(rawSamples, dtype=int16)
-
+        
         # Normalize [-1; +1]
-        pcm = pcm / (2. ** 15)
-
+        pcm = pcm / (2.**15)
+        
         # Compute FFT
         N = pcm.size
         fft = Fft.fft(pcm)
-        uniquePts = ceil((N + 1) / 2.0)
+        uniquePts = ceil((N+1)/2.0)
         fft = fft[0:int(uniquePts)]
-
+        
         # Compute amplitude spectrum
         amplitudeSpectrum = abs(fft) / float(N)
-
+        
         # Compute power spectrum
-        p = amplitudeSpectrum ** 2
-
+        p = amplitudeSpectrum**2
+        
         # Multiply by two to keep same energy
         # See explanation:
         # https://web.archive.org/web/20120615002031/http://www.mathworks.com/support/tech-notes/1700/1702.html
-        if N % 2 > 0:
+        if N % 2 > 0: 
             # odd number of points
             # odd nfft excludes Nyquist point
-            p[1:len(p)] = p[1:len(p)] * 2
+            p[1:len(p)] = p[1:len(p)] * 2 
         else:
             # even number of points
-            p[1:len(p) - 1] = p[1:len(p) - 1] * 2
-
+            p[1:len(p) -1] = p[1:len(p) - 1] * 2
+        
         # Power in logarithmic scale (dB)
-        logPower = 10 * log10(p)
-
+        logPower = 10*log10(p)
+        
         # Compute RMS from power
-        # rms = numpy.sqrt(numpy.sum(p))
-        # print "RMS(power):", rms
-
+        #rms = numpy.sqrt(numpy.sum(p))
+        #print "RMS(power):", rms
+        
         # Select a significant range in the spectrum
-        spectrum = logPower[self.firstSelectedBin:self.firstSelectedBin + self.numberOfSelectedBins]
-
+        spectrum = logPower[self.firstSelectedBin:self.firstSelectedBin+self.numberOfSelectedBins]
+            
         # Scale the spectrum 
         scaledSpectrum = self.scaleList(spectrum)
-
+        
         return (self.bins, scaledSpectrum)
-
+    
 
 class MPDSpectrumPage(Page):
+
     _Icons = {}
-    _Selector = None
-    _FootMsg = ["Nav", "", "", "Back", ""]
+    _Selector=None
+    _FootMsg = ["Nav","","","Back",""]
     _MyList = []
     _ListFont = fonts["veramono12"]
 
-    _PIFI = None
-    _FiFo = None
-    _Color = pygame.Color(126, 206, 244)
+    _PIFI   =  None
+    _FiFo   = None
+    _Color  = pygame.Color(126,206,244)
     _GobjectIntervalId = -1
     _Queue = None
     _KeepReading = True
-
+    
     def __init__(self):
         Page.__init__(self)
         self._Icons = {}
         self._CanvasHWND = None
         self._MyList = []
         self._PIFI = PIFI()
-
+            
     def Init(self):
         self._PosX = self._Index * self._Screen._Width
         self._Width = self._Screen._Width
@@ -148,69 +162,71 @@ class MPDSpectrumPage(Page):
 
         self.Start()
 
-        self._GobjectIntervalId = gobject.timeout_add(50, self.Playing)
-
+        self._GobjectIntervalId = gobject.timeout_add(50,self.Playing)
+        
     def Start(self):
-
+        
         try:
             self._FIFO = open(self._PIFI._MPD_FIFO)
             q = Queue()
             self._Queue = q
-
+            
             t = Thread(target=self.GetSpectrum)
-            t.daemon = True  # thread dies with the program
+            t.daemon = True # thread dies with the program
             t.start()
-
+            
         except IOError:
-            print("open %s failed" % self._PIFI._MPD_FIFO)
+            print("open %s failed"%self._PIFI._MPD_FIFO)
             self._FIFO = None
             return
 
+
     def GetSpectrum(self):
         if self._FIFO == None:
             print("self._FIFO none")
             return
-
-        (bins, scaledSpectrum) = self._PIFI.computeSpectrum(self._FIFO)
-        self._Queue.put(scaledSpectrum)
+        
+        (bins,scaledSpectrum) = self._PIFI.computeSpectrum(self._FIFO)
+        self._Queue.put( scaledSpectrum )
 
         self._KeepReading = False
-
-        return  ## Thread ends
+        
+        return ## Thread ends
 
     def Playing(self):
         if self._Screen.CurPage() == self:
             if self._KeepReading == False:
                 self._KeepReading = True
-
+                
                 t = Thread(target=self.GetSpectrum)
-                t.daemon = True
+                t.daemon=True
                 t.start()
-
+                
             self._Screen.Draw()
             self._Screen.SwapAndShow()
-
+            
         else:
-
+            
             return False
-
+        
         return True
-
+    
     def OnLoadCb(self):
 
         if self._Queue != None:
             with self._Queue.mutex:
                 self._Queue.queue.clear()
-
+        
         try:
             if self._GobjectIntervalId != -1:
                 gobject.source_remove(self._GobjectIntervalId)
         except:
             pass
+        
+        self._GobjectIntervalId = gobject.timeout_add(50,self.Playing)
 
-        self._GobjectIntervalId = gobject.timeout_add(50, self.Playing)
-
-    def KeyDown(self, event):
+    
+    def KeyDown(self,event):
         if event.key == CurKeys["Menu"] or event.key == CurKeys["A"]:
             self.ReturnToUpLevelPage()
             self._Screen.Draw()
@@ -219,10 +235,11 @@ class MPDSpectrumPage(Page):
         if event.key == CurKeys["Start"]:
             self._Screen.Draw()
             self._Screen.SwapAndShow()
-
+            
         if event.key == CurKeys["Enter"]:
             pass
 
+        
     def Draw(self):
         self.ClearCanvas()
 
@@ -230,13 +247,14 @@ class MPDSpectrumPage(Page):
         spects = None
         try:
             spects = self._Queue.get_nowait()
-        #            print("get_nowait: " , spects)
+#            print("get_nowait: " , spects)
         except Empty:
             return
-        else:  # got line
+        else: # got line
             if len(spects) == 0:
                 return
             w = self._Width / len(spects)
-            left_margin = (w - bw) / 2
-            for i, v in enumerate(spects):
-                pygame.draw.rect(self._CanvasHWND, self._Color, (i * w + left_margin, self._Height - v, bw, v), 0)
+            left_margin = (w-bw)/2
+            for i,v in enumerate(spects):
+                pygame.draw.rect(self._CanvasHWND,self._Color,(i*w+left_margin,self._Height-v,bw,v),0)
+        

+ 105 - 93
Menu/GameShell/Music Player/music_lib_list_page.py

@@ -1,91 +1,97 @@
 # -*- coding: utf-8 -*- 
 import os
-
 import pygame
+
+from libs.roundrects import aa_round_rect
+
 ## local UI import
-from UI.constants import Width, ICON_TYPES
-from UI.fonts import fonts
+from UI.constants import Width,Height,ICON_TYPES
+from UI.page   import Page,PageSelector
+from UI.label  import Label
+from UI.fonts  import fonts
 from UI.icon_item import IconItem
-from UI.icon_pool import MyIconPool
-from UI.keys_def import CurKeys
+from UI.util_funcs import midRect
+from UI.keys_def   import CurKeys
 from UI.multi_icon_item import MultiIconItem
-from UI.page import Page, PageSelector
-from UI.scroller import ListScroller
-from libs.roundrects import aa_round_rect
+from UI.icon_pool           import MyIconPool
+from UI.scroller   import ListScroller
 
-from . import myvars
-from .list_item import ListItem
+from list_item  import ListItem
+
+
+import myvars
 
 
 class MusicLibStack:
     def __init__(self):
         self.stack = list()
 
-    def Push(self, data):
+    def Push(self,data):
         if data not in self.stack:
             self.stack.append(data)
             return True
         return False
 
     def Pop(self):
-        if len(self.stack) <= 0:
-            return None, False
-        return self.stack.pop(), True
+        if len(self.stack)<=0:
+            return None,False
+        return self.stack.pop(),True
 
     def Last(self):
-        idx = len(self.stack) - 1
+        idx = len(self.stack) -1
         if idx < 0:
             return "/"
         else:
-            return self.stack[idx]
-
+            return self.stack[ idx ]
+    
     def Length(self):
         return len(self.stack)
 
-
 class ListPageSelector(PageSelector):
-    _BackgroundColor = pygame.Color(131, 199, 219)
+    _BackgroundColor = pygame.Color(131,199,219)
 
     def __init__(self):
         self._PosX = 0
         self._PosY = 0
         self._Height = 0
-        self._Width = Width
+        self._Width  = Width
 
-    def AnimateDraw(self, x2, y2):
+    def AnimateDraw(self,x2,y2):
         pass
 
     def Draw(self):
         idx = self._Parent._PsIndex
-
+        
         if idx < len(self._Parent._MyList):
-            x = self._Parent._MyList[idx]._PosX + 2
-            y = self._Parent._MyList[idx]._PosY + 1
-            h = self._Parent._MyList[idx]._Height - 3
-
+            x = self._Parent._MyList[idx]._PosX+2
+            y = self._Parent._MyList[idx]._PosY+1
+            h = self._Parent._MyList[idx]._Height -3
+        
             self._PosX = x
             self._PosY = y
             self._Height = h
+            
+            aa_round_rect(self._Parent._CanvasHWND,  
+                          (x,y,self._Width-4,h),self._BackgroundColor,4,0,self._BackgroundColor)
 
-            aa_round_rect(self._Parent._CanvasHWND,
-                          (x, y, self._Width - 4, h), self._BackgroundColor, 4, 0, self._BackgroundColor)
 
 
 class MusicLibListPage(Page):
+
     _Icons = {}
-    _Selector = None
-    _FootMsg = ["Nav", "Scan", "", "Back", "Add to Playlist"]
+    _Selector=None
+    _FootMsg = ["Nav","Scan","","Back","Add to Playlist"]
     _MyList = []
     _SwapMyList = []
     _ListFont = fonts["notosanscjk15"]
     _MyStack = None
 
     _Scroller = None
-
+    
     _BGpng = None
     _BGwidth = 56
     _BGheight = 70
-
+    
     def __init__(self):
         Page.__init__(self)
         self._Icons = {}
@@ -93,63 +99,63 @@ class MusicLibListPage(Page):
         self._MyList = []
         self._SwapMyList = []
         self._MyStack = MusicLibStack()
-
-    def SyncList(self, path):
+        
+    def SyncList(self,path):
         if myvars.Poller == None:
             return
-
+        
         alist = myvars.Poller.listfiles(path)
         if alist == False:
             print("listfiles return false")
-            return
+            return 
 
         self._MyList = []
         self._SwapMyList = []
-
-        start_x = 0
-        start_y = 0
+        
+        start_x  = 0
+        start_y  = 0
         hasparent = 0
         if self._MyStack.Length() > 0:
             hasparent = 1
             li = ListItem()
             li._Parent = self
-            li._PosX = start_x
-            li._PosY = start_y
-            li._Width = Width
+            li._PosX   = start_x
+            li._PosY   = start_y
+            li._Width  = Width
             li._Fonts["normal"] = self._ListFont
             li._MyType = ICON_TYPES["DIR"]
             li._Parent = self
             li.Init("[..]")
             self._MyList.append(li)
-
-        for i, v in enumerate(sorted(alist)):
+        
+        for i,v in enumerate(sorted(alist)):
             li = ListItem()
             li._Parent = self
-            li._PosX = start_x
-            li._PosY = start_y + (i + hasparent) * ListItem._Height
-            li._Width = Width
+            li._PosX   = start_x
+            li._PosY   = start_y + (i+hasparent)*ListItem._Height
+            li._Width  = Width
             li._Fonts["normal"] = self._ListFont
-            li._MyType = ICON_TYPES["FILE"]
-            li._Parent = self
-
+            li._MyType  = ICON_TYPES["FILE"]
+            li._Parent  = self
+            
             if "directory" in v:
                 li._MyType = ICON_TYPES["DIR"]
                 dir_base_name = os.path.basename(v["directory"])
-                li.Init(dir_base_name)
-                li._Path = v["directory"]
+                li.Init(  dir_base_name )
+                li._Path = v["directory"] 
             elif "file" in v:
                 bname = os.path.basename(v["file"])
-                li.Init(bname)
+                li.Init( bname  )
                 li._Path = v["file"]
-
+                
             else:
                 li.Init("NoName")
-
+            
             self._MyList.append(li)
 
         for i in self._MyList:
             self._SwapMyList.append(i)
-
+        
     def Init(self):
         self._PosX = self._Index * self._Screen._Width
         self._Width = self._Screen._Width
@@ -168,86 +174,91 @@ class MusicLibListPage(Page):
         icon_for_list._ImgSurf = MyIconPool._Icons["sys"]
         icon_for_list._MyType = ICON_TYPES["STAT"]
         icon_for_list._Parent = self
-
-        icon_for_list.Adjust(0, 0, 18, 18, 0)
+        
+        icon_for_list.Adjust(0,0,18,18,0)        
         self._Icons["sys"] = icon_for_list
 
+
         self._BGpng = IconItem()
         self._BGpng._ImgSurf = MyIconPool._Icons["empty"]
         self._BGpng._MyType = ICON_TYPES["STAT"]
         self._BGpng._Parent = self
         self._BGpng.AddLabel("Please upload data over Wi-Fi", fonts["varela22"])
-        self._BGpng.SetLableColor(pygame.Color(204, 204, 204))
-        self._BGpng.Adjust(0, 0, self._BGwidth, self._BGheight, 0)
+        self._BGpng.SetLableColor(pygame.Color(204,204,204))
+        self._BGpng.Adjust(0,0,self._BGwidth,self._BGheight,0)
+
 
         self._Scroller = ListScroller()
         self._Scroller._Parent = self
         self._Scroller._PosX = self._Width - 10
         self._Scroller._PosY = 2
         self._Scroller.Init()
+        
 
-    def ScrollUp(self, Step=1):
+    def ScrollUp(self,Step=1):
         if len(self._MyList) == 0:
             return
         tmp = self._PsIndex
         self._PsIndex -= Step
-
+        
         if self._PsIndex < 0:
             self._PsIndex = 0
-        dy = tmp - self._PsIndex
+        dy = tmp-self._PsIndex 
         cur_li = self._MyList[self._PsIndex]
         if cur_li._PosY < 0:
             for i in range(0, len(self._MyList)):
-                self._MyList[i]._PosY += self._MyList[i]._Height * dy
+                self._MyList[i]._PosY += self._MyList[i]._Height*dy
+        
 
-    def ScrollDown(self, Step=1):
+    def ScrollDown(self,Step=1):
         if len(self._MyList) == 0:
             return
         tmp = self._PsIndex
-        self._PsIndex += Step
+        self._PsIndex +=Step
         if self._PsIndex >= len(self._MyList):
-            self._PsIndex = len(self._MyList) - 1
+            self._PsIndex = len(self._MyList) -1
         dy = self._PsIndex - tmp
         cur_li = self._MyList[self._PsIndex]
-        if cur_li._PosY + cur_li._Height > self._Height:
-            for i in range(0, len(self._MyList)):
-                self._MyList[i]._PosY -= self._MyList[i]._Height * dy
+        if cur_li._PosY +cur_li._Height > self._Height:
+            for i in range(0,len(self._MyList)):
+                self._MyList[i]._PosY -= self._MyList[i]._Height*dy
 
     def Click(self):
         if len(self._MyList) == 0:
             return
-
+        
         cur_li = self._MyList[self._PsIndex]
 
         if cur_li._MyType == ICON_TYPES["DIR"]:
             if cur_li._Path == "[..]":
                 self._MyStack.Pop()
-                self.SyncList(self._MyStack.Last())
+                self.SyncList( self._MyStack.Last() )
                 self._PsIndex = 0
             else:
-                self._MyStack.Push(self._MyList[self._PsIndex]._Path)
-                self.SyncList(self._MyStack.Last())
+                self._MyStack.Push( self._MyList[self._PsIndex]._Path )
+                self.SyncList( self._MyStack.Last() )
                 self._PsIndex = 0
-
-        if cur_li._MyType == ICON_TYPES["FILE"]:  ## add to playlist only
+                
+        if cur_li._MyType == ICON_TYPES["FILE"]: ## add to playlist only
             myvars.Poller.addfile(cur_li._Path)
-            myvars.PlayListPage.SyncList()
-            print("add", cur_li._Path)
-
+            myvars.PlayListPage.SyncList()            
+            print("add" , cur_li._Path)
+            
         self._Screen.Draw()
         self._Screen.SwapAndShow()
 
     def Rescan(self):
         self.SyncList("/")
         self._PsIndex = 0
-
-    def KeyDown(self, event):
-
+        
+    def KeyDown(self,event):
+        
         if event.key == CurKeys["Menu"] or event.key == CurKeys["Left"] or event.key == CurKeys["A"]:
+            
             self.ReturnToUpLevelPage()
             self._Screen.Draw()
             self._Screen.SwapAndShow()
-
+        
         if event.key == CurKeys["Up"]:
             self.ScrollUp()
             self._Screen.Draw()
@@ -256,7 +267,7 @@ class MusicLibListPage(Page):
             self.ScrollDown()
             self._Screen.Draw()
             self._Screen.SwapAndShow()
-
+        
         """
         if event.key == CurKeys["Right"]:
             self.ScrollDown(Step=5)
@@ -268,18 +279,19 @@ class MusicLibListPage(Page):
             self._Screen.Draw()
             self._Screen.SwapAndShow()
         """
-
+        
         if event.key == CurKeys["X"]:
             self.Rescan()
             self._Screen.Draw()
             self._Screen.SwapAndShow()
-
+                                     
         if event.key == CurKeys["Enter"]:
             self.Click()
-
+            
     def Draw(self):
         self.ClearCanvas()
 
+
         """
         start_x = 0
         start_y = 0
@@ -300,14 +312,14 @@ class MusicLibListPage(Page):
         """
 
         if len(self._MyList) == 0:
-            self._BGpng.NewCoord(self._Width / 2, self._Height / 2)
+            self._BGpng.NewCoord(self._Width/2,self._Height/2)
             self._BGpng.Draw()
             return
-
+        
         else:
             if len(self._MyList) * ListItem._Height > self._Height:
                 self._Ps._Width = self._Width - 11
-
+            
                 self._Ps.Draw()
                 for i in self._MyList:
                     if myvars.PlayListPage.InPlayList(i._Path):
@@ -322,8 +334,8 @@ class MusicLibListPage(Page):
                         continue
                     
                     i.Draw()
-
-                self._Scroller.UpdateSize(len(self._MyList) * ListItem._Height, self._PsIndex * ListItem._Height)
+                    
+                self._Scroller.UpdateSize( len(self._MyList)*ListItem._Height, self._PsIndex*ListItem._Height)
                 self._Scroller.Draw()
             else:
                 self._Ps._Width = self._Width
@@ -340,4 +352,4 @@ class MusicLibListPage(Page):
                     if i._PosY < 0:
                         continue
                         
-                    i.Draw()
+                    i.Draw()    

+ 4 - 1
Menu/GameShell/Music Player/myvars.py

@@ -1,5 +1,8 @@
-Poller = None  # MPD Poller
+
+
+Poller = None # MPD Poller
 PlayListPage = None
 MusicLibListPage = None
 
 SpectrumPage = None
+

+ 16 - 17
Menu/GameShell/Music Player/pages.py

@@ -1,39 +1,38 @@
 # -*- coding: utf-8 -*- 
 
-# from libs.MPD import poller
+from libs.MPD import poller
 
-from . import myvars
-from .mpd_spectrum_page import MPDSpectrumPage
-from .music_lib_list_page import MusicLibListPage
-from .play_list_page import PlayListPage
+from play_list_page      import PlayListPage
+from music_lib_list_page import MusicLibListPage
+from mpd_spectrum_page   import MPDSpectrumPage
+import myvars
 
+from config import MPD_socket
 
 def InitPoller():
-    myvars.Poller = None
-    # try:
-    #    myvars.Poller = poller.MPDPoller(host=MPD_socket)
-    #    myvars.Poller.connect()
-    # except:
-    #    myvars.Poller = None
-
+    try:
+        myvars.Poller = poller.MPDPoller(host=MPD_socket)
+        myvars.Poller.connect()
+    except:
+        myvars.Poller = None
+        
 
 def InitMusicLibPage(main_screen):
     myvars.MusicLibListPage = MusicLibListPage()
     myvars.MusicLibListPage._Screen = main_screen
-    myvars.MusicLibListPage._Name = "Music Library"
+    myvars.MusicLibListPage._Name   = "Music Library"
     myvars.MusicLibListPage.Init()
 
-
 def InitListPage(main_screen):
-    myvars.PlayListPage = PlayListPage()
 
+    myvars.PlayListPage = PlayListPage()
+    
     myvars.PlayListPage._Screen = main_screen
     myvars.PlayListPage._Name = "Play List"
     myvars.PlayListPage.Init()
 
-
 def InitSpectrumPage(main_screen):
     myvars.SpectrumPage = MPDSpectrumPage()
     myvars.SpectrumPage._Screen = main_screen
-    myvars.SpectrumPage._Name = "Spectrum"
+    myvars.SpectrumPage._Name   = "Spectrum"
     myvars.SpectrumPage.Init()

+ 85 - 74
Menu/GameShell/Music Player/play_list_page.py

@@ -1,65 +1,71 @@
 # -*- coding: utf-8 -*- 
 import os
-
-# import gobject
 import pygame
+import gobject
+
+from libs.roundrects import aa_round_rect
+
 ## local UI import
-from UI.constants import Width, ICON_TYPES
-from UI.fonts import fonts
+from UI.constants import Width,Height,ICON_TYPES
+from UI.page   import Page,PageSelector
 from UI.icon_item import IconItem
-from UI.icon_pool import MyIconPool
-from UI.keys_def import CurKeys
-from UI.page import Page, PageSelector
-from UI.scroller import ListScroller
-from libs.roundrects import aa_round_rect
+from UI.label  import Label
+from UI.fonts  import fonts
+from UI.util_funcs import midRect
+from UI.keys_def   import CurKeys
+from UI.icon_pool  import MyIconPool
 
-from . import myvars
-from .list_item import ListItem
+from UI.scroller   import ListScroller
 
+from list_item  import ListItem
+
+import myvars
 
 class ListPageSelector(PageSelector):
-    _BackgroundColor = pygame.Color(131, 199, 219)
+    _BackgroundColor = pygame.Color(131,199,219)
 
     def __init__(self):
         self._PosX = 0
         self._PosY = 0
         self._Height = 0
-        self._Width = Width
+        self._Width  = Width 
 
-    def AnimateDraw(self, x2, y2):
+    def AnimateDraw(self,x2,y2):
         pass
 
     def Draw(self):
         idx = self._Parent._PsIndex
-        if idx > (len(self._Parent._MyList) - 1):
+        if idx > (len(self._Parent._MyList)-1):
             idx = len(self._Parent._MyList)
             if idx > 0:
-                idx -= 1
-            elif idx == 0:  # Nothing
+                idx -=1
+            elif idx == 0: #Nothing
                 return
 
-        x = self._Parent._MyList[idx]._PosX + 2
-        y = self._Parent._MyList[idx]._PosY + 1
-        h = self._Parent._MyList[idx]._Height - 3
-
+        x = self._Parent._MyList[idx]._PosX+2
+        y = self._Parent._MyList[idx]._PosY+1
+        h = self._Parent._MyList[idx]._Height -3
+        
         self._PosX = x
         self._PosY = y
         self._Height = h
 
-        aa_round_rect(self._Parent._CanvasHWND,
-                      (x, y, self._Width - 4, h), self._BackgroundColor, 4, 0, self._BackgroundColor)
+        aa_round_rect(self._Parent._CanvasHWND,  
+                      (x,y,self._Width-4,h),self._BackgroundColor,4,0,self._BackgroundColor)
+        
 
 
 class PlayListPage(Page):
+
     _Icons = {}
-    _Selector = None
-    _FootMsg = ["Nav", "", "Remove", "Back", "Play/Pause"]
+    _Selector=None
+    _FootMsg = ["Nav","","Remove","Back","Play/Pause"]
     _MyList = []
     _ListFont = fonts["notosanscjk15"]
 
     _Scroller = None
-
-    _BGpng = None
+    
+    _BGpng  = None
     _BGwidth = 75
     _BGheight = 70
 
@@ -73,58 +79,59 @@ class PlayListPage(Page):
 
     def SyncList(self):
         self._MyList = []
-        start_x = 0
-        start_y = 0
+        start_x  = 0
+        start_y  = 0
         if myvars.Poller == None:
             return
-
+        
         play_list = myvars.Poller.playlist()
-        for i, v in enumerate(play_list):
+        for i,v in enumerate(play_list):
             li = ListItem()
             li._Parent = self
-            li._PosX = start_x
-            li._PosY = start_y + i * ListItem._Height
-            li._Width = Width
+            li._PosX   = start_x
+            li._PosY   = start_y + i*ListItem._Height
+            li._Width  = Width
             li._Fonts["normal"] = self._ListFont
 
             if "title" in v:
-                li.Init(v["title"])
+                li.Init( v["title"])
                 if "file" in v:
                     li._Path = v["file"]
-
+                
             elif "file" in v:
                 li.Init(os.path.basename(v["file"]))
-                li._Path = v["file"]
+                li._Path = v["file"] 
             else:
                 li.Init("NoName")
 
             li._Labels["Text"]._PosX = 7
             self._MyList.append(li)
 
+            
         self.SyncPlaying()
 
-    def GObjectInterval(self):  ## 250 ms
+    def GObjectInterval(self): ## 250 ms 
         if self._Screen.CurPage() == self:
             self.SyncPlaying()
             self._Screen.Draw()
             self._Screen.SwapAndShow()
 
         return True
-
+    
     def SyncPlaying(self):
         if myvars.Poller == None:
             return
-
+        
         current_song = myvars.Poller.poll()
-
-        for i, v in enumerate(self._MyList):
+        
+        for i ,v in enumerate(self._MyList):
             self._MyList[i]._Playing = False
             self._MyList[i]._PlayingProcess = 0
-
+            
         if current_song != None:
             if "song" in current_song:
                 posid = int(current_song["song"])
-                if posid < len(self._MyList):  # out of index
+                if posid < len(self._MyList): # out of index
                     if "state" in current_song:
                         if current_song["state"] == "stop":
                             self._MyList[posid]._Playing = False
@@ -132,17 +139,18 @@ class PlayListPage(Page):
                             self._MyList[posid]._Playing = True
                     if "time" in current_song:
                         times_ = current_song["time"].split(":")
-                        if len(times_) > 1:
+                        if len(times_)> 1:
                             cur = float(times_[0])
                             end = float(times_[1])
-                            pros = int((cur / end) * 100.0)
+                            pros = int((cur/end)*100.0)
                             self._MyList[posid]._PlayingProcess = pros
-
-    def InPlayList(self, path):
-        for i, v in enumerate(self._MyList):
+                        
+                
+    def InPlayList(self,path):
+        for i,v in enumerate(self._MyList):
             if v._Path == path:
                 return True
-
+    
     def Init(self):
         self._PosX = self._Index * self._Screen._Width
         self._Width = self._Screen._Width
@@ -156,22 +164,23 @@ class PlayListPage(Page):
         self._PsIndex = 0
 
         self.SyncList()
-        gobject.timeout_add(850, self.GObjectInterval)
+        gobject.timeout_add(850,self.GObjectInterval)
 
         self._BGpng = IconItem()
         self._BGpng._ImgSurf = MyIconPool._Icons["heart"]
         self._BGpng._MyType = ICON_TYPES["STAT"]
         self._BGpng._Parent = self
         self._BGpng.AddLabel("my favourites", fonts["varela18"])
-        self._BGpng.SetLableColor(pygame.Color(204, 204, 204))
-        self._BGpng.Adjust(0, 0, self._BGwidth, self._BGheight, 0)
+        self._BGpng.SetLableColor(pygame.Color(204,204,204))
+        self._BGpng.Adjust(0,0,self._BGwidth,self._BGheight,0)
 
         self._Scroller = ListScroller()
         self._Scroller._Parent = self
         self._Scroller._PosX = self._Width - 10
         self._Scroller._PosY = 2
         self._Scroller.Init()
-
+        
+        
     def ScrollUp(self):
         if len(self._MyList) == 0:
             return
@@ -182,17 +191,18 @@ class PlayListPage(Page):
         if cur_li._PosY < 0:
             for i in range(0, len(self._MyList)):
                 self._MyList[i]._PosY += self._MyList[i]._Height
-            self._Scrolled += 1
+            self._Scrolled +=1
+
     def ScrollDown(self):
         if len(self._MyList) == 0:
             return
-        self._PsIndex += 1
+        self._PsIndex +=1
         if self._PsIndex >= len(self._MyList):
-            self._PsIndex = len(self._MyList) - 1
+            self._PsIndex = len(self._MyList) -1
 
         cur_li = self._MyList[self._PsIndex]
-        if cur_li._PosY + cur_li._Height > self._Height:
-            for i in range(0, len(self._MyList)):
+        if cur_li._PosY +cur_li._Height > self._Height:
+            for i in range(0,len(self._MyList)):
                 self._MyList[i]._PosY -= self._MyList[i]._Height
             self._Scrolled -=1
 
@@ -214,7 +224,7 @@ class PlayListPage(Page):
     def Click(self):
         if len(self._MyList) == 0:
             return
-
+        
         cur_li = self._MyList[self._PsIndex]
         play_pos_id = myvars.Poller.play(self._PsIndex)
 
@@ -222,20 +232,20 @@ class PlayListPage(Page):
 
         self._Screen.Draw()
         self._Screen.SwapAndShow()
-
+        
     def OnReturnBackCb(self): # return from music_lib_list_page
         self.SyncList()
         self.SyncScroll()
-
-    def KeyDown(self, event):
+        
+    def KeyDown(self,event):
         if event.key == CurKeys["A"] or event.key == CurKeys["Menu"]:
             if myvars.Poller != None:
                 myvars.Poller.stop()
-
+            
             self.ReturnToUpLevelPage()
             self._Screen.Draw()
             self._Screen.SwapAndShow()
-
+        
         if event.key == CurKeys["Up"]:
             self.ScrollUp()
             self._Screen.Draw()
@@ -244,32 +254,32 @@ class PlayListPage(Page):
             self.ScrollDown()
             self._Screen.Draw()
             self._Screen.SwapAndShow()
-
-        if event.key == CurKeys["Right"]:  # add
+        
+        if event.key == CurKeys["Right"]:#add
             self._Screen.PushCurPage()
             self._Screen.SetCurPage(myvars.MusicLibListPage)
             self._Screen.Draw()
             self._Screen.SwapAndShow()
-
-        if event.key == CurKeys["Y"]:  # del selected songs
+        
+        if event.key == CurKeys["Y"]:# del selected songs
             myvars.Poller.delete(self._PsIndex)
             self.SyncList()
             self._Screen.Draw()
             self._Screen.SwapAndShow()
-
+            
         if event.key == CurKeys["Enter"]:
             self.Click()
 
-        if event.key == CurKeys["Start"]:  # start spectrum
+        if event.key == CurKeys["Start"]: # start spectrum
             self._Screen.PushPage(myvars.SpectrumPage)
             self._Screen.Draw()
             self._Screen.SwapAndShow()
-
+            
     def Draw(self):
         self.ClearCanvas()
 
         if len(self._MyList) == 0:
-            self._BGpng.NewCoord(self._Width / 2, self._Height / 2)
+            self._BGpng.NewCoord(self._Width/2,self._Height/2)
             self._BGpng.Draw()
             return
         else:
@@ -284,7 +294,7 @@ class PlayListPage(Page):
                         continue
                     
                     i.Draw()
-                self._Scroller.UpdateSize(len(self._MyList) * ListItem._Height, self._PsIndex * ListItem._Height)
+                self._Scroller.UpdateSize( len(self._MyList)*ListItem._Height, self._PsIndex*ListItem._Height)
                 self._Scroller.Draw()
             else:
                 self._Ps._Width = self._Width
@@ -298,3 +308,4 @@ class PlayListPage(Page):
                         continue
                     
                     i.Draw()
+                

+ 29 - 28
Menu/GameShell/PowerOFF/__init__.py

@@ -1,21 +1,24 @@
 # -*- coding: utf-8 -*- 
 
-import config
 import pygame
+
+#UI lib
+from UI.constants    import RUNSYS
+from UI.keys_def     import CurKeys
 from UI.confirm_page import ConfirmPage
-# UI lib
-from UI.constants import RUNSYS
-from UI.keys_def import CurKeys
 
+import config
 
 class PowerOffConfirmPage(ConfirmPage):
+    
     _ConfirmText = "Confirm Power OFF?"
+    
 
     def CheckBattery(self):
         try:
             f = open(config.Battery)
         except IOError:
-            print("PowerOFF open %s failed" % config.Battery)
+            print( "PowerOFF open %s failed" % config.Battery)
             return 0
         else:
             with f:
@@ -31,14 +34,15 @@ class PowerOffConfirmPage(ConfirmPage):
                     cur_cap = int(bat_uevent["POWER_SUPPLY_CAPACITY"])
                 else:
                     cur_cap = 0
-
+                
                 return cur_cap
-
+                    
         return 0
-
-    def KeyDown(self, event):
-
+        
+    def KeyDown(self,event):
+        
         if event.key == CurKeys["Menu"] or event.key == CurKeys["A"]:
+            
             self.ReturnToUpLevelPage()
             self._Screen.Draw()
             self._Screen.SwapAndShow()
@@ -48,41 +52,38 @@ class PowerOffConfirmPage(ConfirmPage):
                 cmdpath = "feh --bg-center gameshell/wallpaper/gameover.png;"
             else:
                 cmdpath = "feh --bg-center gameshell/wallpaper/seeyou.png;"
-
+            
             cmdpath += "sleep 3;"
-
-            # cmdpath += "echo 'halt -p' > /tmp/halt_cmd"
-
+            
+            #cmdpath += "echo 'halt -p' > /tmp/halt_cmd"
+            
             cmdpath += "sudo halt -p"
-            pygame.event.post(pygame.event.Event(RUNSYS, message=cmdpath))
+            pygame.event.post( pygame.event.Event(RUNSYS, message=cmdpath))
+
 
 
 class APIOBJ(object):
-    _StoragePage = None
 
+    _StoragePage = None
     def __init__(self):
         pass
-
-    def Init(self, main_screen):
+    def Init(self,main_screen):
         self._Page = PowerOffConfirmPage()
 
         self._Page._Screen = main_screen
-        self._Page._Name = "Power OFF"
+        self._Page._Name ="Power OFF"
         self._Page.Init()
-
-    def API(self, main_screen):
-        if main_screen != None:
+        
+        
+    def API(self,main_screen):
+        if main_screen !=None:
             main_screen.PushPage(self._Page)
             main_screen.Draw()
             main_screen.SwapAndShow()
 
-
 OBJ = APIOBJ()
-
-
-def Init(main_screen):
+def Init(main_screen):    
     OBJ.Init(main_screen)
-
-
 def API(main_screen):
     OBJ.API(main_screen)
+    

+ 1 - 2
Menu/GameShell/RetroArch.sh

@@ -1,2 +1 @@
-#!/usr/bin/env bash
-retroarch
+retroarch 

+ 74 - 74
Menu/GameShell/TinyCloud/__init__.py

@@ -1,39 +1,39 @@
 # -*- coding: utf-8 -*- 
 import pygame
 import validators
-from UI.constants import ICON_TYPES
-from UI.fonts import fonts
+
+from UI.constants import Width,Height,ICON_TYPES
+from UI.simple_name_space import SimpleNamespace
+from UI.page  import Page
+from UI.label  import Label
+from UI.fonts  import fonts
 from UI.icon_item import IconItem
 from UI.icon_pool import MyIconPool
-from UI.keys_def import CurKeys
-from UI.label import Label
-from UI.page import Page
-from UI.simple_name_space import SimpleNamespace
-
+from UI.keys_def  import CurKeys
 
-# from libs.DBUS  import is_wifi_connected_now,get_wifi_ip
+from libs.DBUS  import is_wifi_connected_now,get_wifi_ip
 
 class TinyCloudPage(Page):
-    _FootMsg = ["Nav.", "", "", "Back", ""]
+    _FootMsg =  ["Nav.","","","Back",""]
     _MyList = []
-
+    
     _ListFontObj = fonts["varela13"]
-
+    
     _AList = {}
     _Labels = {}
 
     _Coords = {}
-
-    _URLColor = pygame.Color(51, 166, 255)
-    _TextColor = pygame.Color(83, 83, 83)
+    
+    _URLColor  = pygame.Color(51,166,255)
+    _TextColor = pygame.Color(83,83,83)
     _Scrolled = 0
-
+    
     _PngSize = {}
-
+    
     _DrawOnce = False
     _Scroller = None
     _Scrolled = 0
-
+    
     def __init__(self):
         Page.__init__(self)
         self._Icons = {}
@@ -54,7 +54,7 @@ class TinyCloudPage(Page):
         self._Coords["forKey"].y = self._Coords["forID"].y
 
         self._Coords["key_and_pass"] = SimpleNamespace()
-        self._Coords["key_and_pass"].x = 36  # 141
+        self._Coords["key_and_pass"].x = 36 # 141
         self._Coords["key_and_pass"].y = self._Coords["forID"].y
 
         self._Coords["forssh"] = SimpleNamespace()
@@ -84,14 +84,15 @@ class TinyCloudPage(Page):
         self._Coords["airplay_name"] = SimpleNamespace()
         self._Coords["airplay_name"].x = 68
         self._Coords["airplay_name"].y = self._Coords["for_airplay"].y
+        
 
-        self._Coords["bg"] = SimpleNamespace()
-        self._Coords["bg"].x = self._Width / 2
-        self._Coords["bg"].y = self._Height / 2
+        self._Coords["bg"]          = SimpleNamespace()
+        self._Coords["bg"].x        = self._Width/2
+        self._Coords["bg"].y        = self._Height/2
 
-        self._Coords["online"] = SimpleNamespace()
-        self._Coords["online"].x = 266
-        self._Coords["online"].y = 99
+        self._Coords["online"]          = SimpleNamespace()
+        self._Coords["online"].x        = 266
+        self._Coords["online"].y        = 99
 
     def SetLabels(self):
         if is_wifi_connected_now():
@@ -103,126 +104,125 @@ class TinyCloudPage(Page):
             except:
                 print("ip error %s " % self._IP)
                 self._IP = "xxx.xxx.xxx.xxx"
-
+            
         else:
             self._IP = "xxx.xxx.xxx.xxx"
-
+        
         labels = \
-            [["forssh", "For ssh and scp:", self._ListFontObj, self._TextColor],
-             ["ssh_addr", "ssh cpi@%s" % self._IP, self._ListFontObj, self._URLColor],
-             ["forwin", "For Windows network:", self._ListFontObj, self._TextColor],
-             ["samba_games", "\\\\%s\games" % self._IP, self._ListFontObj, self._URLColor],
-             ["samba_music", "\\\\%s\music" % self._IP, self._ListFontObj, self._URLColor],
-             ["forID", "ID:", self._ListFontObj, self._TextColor],
-             ["forKey", "Key:", self._ListFontObj, self._TextColor],
-             ["key_and_pass", "cpi", self._ListFontObj, self._URLColor],
-             ["for_airplay", "Airplay:", self._ListFontObj, self._TextColor],
-             ["airplay_name", "clockworkpi", self._ListFontObj, self._URLColor]]
+        [["forssh","For ssh and scp:",self._ListFontObj,self._TextColor],
+         ["ssh_addr","ssh cpi@%s" % self._IP, self._ListFontObj,self._URLColor],
+         ["forwin", "For Windows network:",    self._ListFontObj, self._TextColor],
+         ["samba_games", "\\\\%s\games" % self._IP, self._ListFontObj,self._URLColor],
+         ["samba_music", "\\\\%s\music" % self._IP, self._ListFontObj,self._URLColor],
+         ["forID",      "ID:",                     self._ListFontObj, self._TextColor],
+         ["forKey",     "Key:",                    self._ListFontObj, self._TextColor],
+         ["key_and_pass", "cpi",                   self._ListFontObj, self._URLColor],
+         ["for_airplay", "Airplay:",               self._ListFontObj, self._TextColor],
+         ["airplay_name","clockworkpi",            self._ListFontObj, self._URLColor]]
 
         for i in labels:
             l = Label()
             l.SetCanvasHWND(self._CanvasHWND)
-            l.Init(i[1], i[2])
+            l.Init(i[1],i[2])
             l.SetColor(i[3])
-            self._Labels[i[0]] = l
-
-        self.SetCoords()  ##
+            self._Labels[ i[0] ] = l
 
+        self.SetCoords() ##
+        
     def Init(self):
 
+        
         if self._Screen != None:
             if self._Screen._CanvasHWND != None and self._CanvasHWND == None:
                 self._HWND = self._Screen._CanvasHWND
-                self._CanvasHWND = pygame.Surface((self._Screen._Width, self._Screen._Height))
-
-        self._PosX = self._Index * self._Screen._Width
-        self._Width = self._Screen._Width  ## equal to screen width
+                self._CanvasHWND = pygame.Surface( (self._Screen._Width,self._Screen._Height) )
+        
+        self._PosX = self._Index*self._Screen._Width 
+        self._Width = self._Screen._Width ## equal to screen width
         self._Height = self._Screen._Height
 
-        self._PngSize["bg"] = (253, 132)
-        self._PngSize["online"] = (75, 122)
-
+        self._PngSize["bg"] = (253,132)
+        self._PngSize["online"] = (75,122)
+        
         bgpng = IconItem()
         bgpng._ImgSurf = MyIconPool._Icons["needwifi_bg"]
         bgpng._MyType = ICON_TYPES["STAT"]
         bgpng._Parent = self
-        bgpng.Adjust(0, 0, self._PngSize["bg"][0], self._PngSize["bg"][1], 0)
+        bgpng.Adjust(0,0,self._PngSize["bg"][0],self._PngSize["bg"][1],0)
 
         self._Icons["bg"] = bgpng
-
+        
         onlinepng = IconItem()
         onlinepng._ImgSurf = MyIconPool._Icons["online"]
         onlinepng._MyType = ICON_TYPES["STAT"]
         onlinepng._Parent = self
-        onlinepng.Adjust(0, 0, self._PngSize["online"][0], self._PngSize["online"][1], 0)
+        onlinepng.Adjust(0,0,self._PngSize["online"][0], self._PngSize["online"][1],0)
 
         self._Icons["online"] = onlinepng
 
         self.SetLabels()
 
-    def KeyDown(self, event):
+    def KeyDown(self,event):
         if event.key == CurKeys["A"] or event.key == CurKeys["Menu"]:
             if self._FootMsg[3] == "Back":
                 self.ReturnToUpLevelPage()
                 self._Screen.Draw()
                 self._Screen.SwapAndShow()
             return
-
+        
     def Draw(self):
         if self._DrawOnce == False:
             self.ClearCanvas()
 
             if is_wifi_connected_now():
-
+                
                 self._Icons["online"].NewCoord(self._Coords["online"].x, self._Coords["online"].y)
                 self._Icons["online"].Draw()
 
                 self.SetLabels()
-
+                
                 for i in self._Labels:
                     if i in self._Coords:
-                        self._Labels[i].NewCoord(self._Coords[i].x, self._Coords[i].y)
+                        self._Labels[i].NewCoord( self._Coords[i].x, self._Coords[i].y)
                         self._Labels[i].Draw()
 
-                self._Labels["key_and_pass"].NewCoord(103, self._Coords["key_and_pass"].y)
+                self._Labels["key_and_pass"].NewCoord( 103,self._Coords["key_and_pass"].y)
                 self._Labels["key_and_pass"].Draw()
 
             else:
                 self._Icons["bg"].NewCoord(self._Coords["bg"].x, self._Coords["bg"].y)
                 self._Icons["bg"].Draw()
 
+                
             self._DrawOnce = True
-
+            
         if self._HWND != None:
-            self._HWND.fill((255, 255, 255))
-            self._HWND.blit(self._CanvasHWND, (self._PosX, self._PosY, self._Width, self._Height))
-
-
+            self._HWND.fill((255,255,255))
+            self._HWND.blit(self._CanvasHWND,(self._PosX,self._PosY,self._Width, self._Height ) )
+            
+            
+        
 class APIOBJ(object):
-    _Page = None
 
+    _Page = None
     def __init__(self):
         pass
-
-    def Init(self, main_screen):
+    def Init(self,main_screen):
         self._Page = TinyCloudPage()
         self._Page._Screen = main_screen
-        self._Page._Name = "Tiny cloud"
+        self._Page._Name ="Tiny cloud"
         self._Page.Init()
-
-    def API(self, main_screen):
-        if main_screen != None:
+        
+    def API(self,main_screen):
+        if main_screen !=None:
             main_screen.PushPage(self._Page)
             main_screen.Draw()
             main_screen.SwapAndShow()
 
-
 OBJ = APIOBJ()
-
-
-def Init(main_screen):
+def Init(main_screen):    
     OBJ.Init(main_screen)
-
-
 def API(main_screen):
     OBJ.API(main_screen)
+    
+        

+ 0 - 1
Menu/GameShell/freeDM.sh

@@ -1,2 +1 @@
-#!/usr/bin/env bash
 chocolate-doom -iwad /home/cpi/games/FreeDM/freedoom1.wad

+ 0 - 0
skin/default/images/Menu/GameShell/20_Retro Games/MAME.png → skin/default/Menu/GameShell/20_Retro Games/MAME.png


+ 0 - 0
skin/default/images/Menu/GameShell/20_Retro Games/MGBA.png → skin/default/Menu/GameShell/20_Retro Games/MGBA.png


+ 0 - 0
skin/default/images/Menu/GameShell/20_Retro Games/NESTOPIA.png → skin/default/Menu/GameShell/20_Retro Games/NESTOPIA.png


+ 0 - 0
skin/default/images/Menu/GameShell/CaveStory.png → skin/default/Menu/GameShell/CaveStory.png


+ 0 - 0
skin/default/images/Menu/GameShell/Music Player.png → skin/default/Menu/GameShell/Music Player.png


+ 0 - 0
skin/default/images/Menu/GameShell/PowerOFF.png → skin/default/Menu/GameShell/PowerOFF.png


+ 0 - 0
skin/default/images/Menu/GameShell/Retro Games.png → skin/default/Menu/GameShell/Retro Games.png


+ 0 - 0
skin/default/images/Menu/GameShell/RetroArch.png → skin/default/Menu/GameShell/RetroArch.png


+ 0 - 0
skin/default/images/Menu/GameShell/Settings.png → skin/default/Menu/GameShell/Settings.png


+ 0 - 0
skin/default/images/Menu/GameShell/Sleep.png → skin/default/Menu/GameShell/Sleep.png


+ 0 - 0
skin/default/images/Menu/GameShell/TinyCloud.png → skin/default/Menu/GameShell/TinyCloud.png


+ 0 - 0
skin/default/images/Menu/GameShell/freeDM.png → skin/default/Menu/GameShell/freeDM.png


+ 2 - 12
skin/default/config.cfg

@@ -1,13 +1,3 @@
 [Colors]
-High=#33a6ff
-White=#ffffff
-
-[Fonts]
-varela=VarelaRound-Regular.ttf
-veramono=VeraMono.ttf
-noto=NotoSansMono-Regular.ttf
-otocjk=NotoSansCJK-Regular.ttf
-
-[Images]
-blank_icon=sys.py/gameshell/blank.png
-corners_tiles=sys.py/gameshell/icons/roundcorners.png
+High = #33a6ff
+White = #ffffff

+ 0 - 0
skin/default/images/sys.py/gameshell/blank.png → skin/default/sys.py/gameshell/blank.png


+ 0 - 0
skin/default/images/sys.py/gameshell/footbar_icons/footbar.png → skin/default/sys.py/gameshell/footbar_icons/footbar.png


+ 0 - 0
skin/default/images/sys.py/gameshell/icons/_L.png → skin/default/sys.py/gameshell/icons/_L.png


+ 0 - 0
skin/default/images/sys.py/gameshell/icons/_R.png → skin/default/sys.py/gameshell/icons/_R.png


+ 0 - 0
skin/default/images/sys.py/gameshell/icons/about_bg.png → skin/default/sys.py/gameshell/icons/about_bg.png


+ 0 - 0
skin/default/images/sys.py/gameshell/icons/blueselector.png → skin/default/sys.py/gameshell/icons/blueselector.png


+ 0 - 0
skin/default/images/sys.py/gameshell/icons/done.png → skin/default/sys.py/gameshell/icons/done.png


+ 0 - 0
skin/default/images/sys.py/gameshell/icons/empty.png → skin/default/sys.py/gameshell/icons/empty.png


+ 0 - 0
skin/default/images/sys.py/gameshell/icons/heart.png → skin/default/sys.py/gameshell/icons/heart.png


+ 0 - 0
skin/default/images/sys.py/gameshell/icons/icon_sd.png → skin/default/sys.py/gameshell/icons/icon_sd.png


+ 0 - 0
skin/default/images/sys.py/gameshell/icons/light.png → skin/default/sys.py/gameshell/icons/light.png


+ 0 - 0
skin/default/images/sys.py/gameshell/icons/lock.png → skin/default/sys.py/gameshell/icons/lock.png


+ 0 - 0
skin/default/images/sys.py/gameshell/icons/needwifi_bg.png → skin/default/sys.py/gameshell/icons/needwifi_bg.png


+ 0 - 0
skin/default/images/sys.py/gameshell/icons/online.png → skin/default/sys.py/gameshell/icons/online.png


+ 0 - 0
skin/default/images/sys.py/gameshell/icons/rom_download.png → skin/default/sys.py/gameshell/icons/rom_download.png


+ 0 - 0
skin/default/images/sys.py/gameshell/icons/roundcorners.png → skin/default/sys.py/gameshell/icons/roundcorners.png


+ 0 - 0
skin/default/images/sys.py/gameshell/icons/scale.png → skin/default/sys.py/gameshell/icons/scale.png


+ 0 - 0
skin/default/images/sys.py/gameshell/icons/star.png → skin/default/sys.py/gameshell/icons/star.png


+ 0 - 0
skin/default/images/sys.py/gameshell/icons/sys.png → skin/default/sys.py/gameshell/icons/sys.png


+ 0 - 0
skin/default/images/sys.py/gameshell/icons/vol.png → skin/default/sys.py/gameshell/icons/vol.png


+ 0 - 0
skin/default/images/sys.py/gameshell/titlebar_icons/battery_unknown.png → skin/default/sys.py/gameshell/titlebar_icons/battery_unknown.png


+ 0 - 0
skin/default/images/sys.py/gameshell/titlebar_icons/soundvolume.png → skin/default/sys.py/gameshell/titlebar_icons/soundvolume.png


+ 0 - 0
skin/default/images/sys.py/gameshell/titlebar_icons/wifi.png → skin/default/sys.py/gameshell/titlebar_icons/wifi.png


+ 0 - 0
skin/default/images/sys.py/gameshell/titlebar_icons/withcharging.png → skin/default/sys.py/gameshell/titlebar_icons/withcharging.png


+ 0 - 0
skin/default/images/sys.py/gameshell/titlebar_icons/without_charging.png → skin/default/sys.py/gameshell/titlebar_icons/without_charging.png


+ 39 - 32
sys.py/UI/Emulator/__init__.py

@@ -1,31 +1,36 @@
 # -*- coding: utf-8 -*- 
 
+import pygame
+from pygame.locals import *
+from sys import exit
 import os
+import sys
 
-import pygame
 
-from .fav_list_page import FavListPage
-from .rom_list_page import RomListPage
 ## local UI import
-from ..delete_confirm_page import DeleteConfirmPage
-from ..icon_pool import MyIconPool
-from ..keys_def import CurKeys
+from UI.delete_confirm_page import DeleteConfirmPage
+from UI.icon_pool           import MyIconPool
+from UI.keys_def            import CurKeys
 
+from rom_list_page import RomListPage
+from fav_list_page import FavListPage
 
 class FavDeleteConfirmPage(DeleteConfirmPage):
-
-    def KeyDown(self, event):
-
+    
+    def KeyDown(self,event):
+        
         if event.key == CurKeys["Menu"] or event.key == CurKeys["A"]:
+            
             self.ReturnToUpLevelPage()
             self._Screen.Draw()
             self._Screen.SwapAndShow()
-
+                
+        
         if event.key == CurKeys["B"]:
             try:
-                # self._FileName
+                #self._FileName
                 stats = os.stat(self._FileName)
-                os.chown(self._FileName, stats.st_uid, stats.st_uid)  ## normally uid and gid should be the same
+                os.chown(self._FileName, stats.st_uid,stats.st_uid) ## normally uid and gid should be the same 
             except:
                 print("error in FavDeleteConfirmPage chown ")
 
@@ -33,7 +38,7 @@ class FavDeleteConfirmPage(DeleteConfirmPage):
             self._Screen.Draw()
             self._Screen.SwapAndShow()
             self.Reset()
-
+                
             pygame.time.delay(300)
             self.ReturnToUpLevelPage()
             self._Screen.Draw()
@@ -43,14 +48,15 @@ class FavDeleteConfirmPage(DeleteConfirmPage):
 
 
 class MyEmulator(object):
+
     _Icons = {}
     RomListPage = None
     FavListPage = None
     _Emulator = None
-
+    
     _FavGID = 31415
     _FavGname = "cpifav"
-
+    
     def __init__(self):
         self._Icons = {}
 
@@ -64,43 +70,44 @@ class MyEmulator(object):
                 self._Icons[keyname] = pygame.image.load(basepath+"/"+i).convert_alpha()
         """
         self._Icons["sys"] = MyIconPool._Icons["sys"]
-
-    def InitDeleteConfirmPage(self, main_screen):
+        
+        
+    def InitDeleteConfirmPage(self,main_screen):
         self.DeleteConfirmPage = DeleteConfirmPage()
         self.DeleteConfirmPage._Screen = main_screen
-        self.DeleteConfirmPage._Name = "Delete Confirm"
+        self.DeleteConfirmPage._Name   = "Delete Confirm"
         self.DeleteConfirmPage.Init()
 
         self.FavDeleteConfirmPage = FavDeleteConfirmPage()
         self.FavDeleteConfirmPage._Screen = main_screen
-        self.FavDeleteConfirmPage._Name = "Delete Confirm"
+        self.FavDeleteConfirmPage._Name   = "Delete Confirm"
         self.FavDeleteConfirmPage.Init()
-
-    def InitFavListPage(self, main_screen):
+        
+    def InitFavListPage(self,main_screen):
         self.FavListPage = FavListPage()
         self.FavListPage._Screen = main_screen
-        self.FavListPage._Name = "Favourite Games"
+        self.FavListPage._Name   = "Favourite Games"
         self.FavListPage._Emulator = self._Emulator
         self.FavListPage._Parent = self
-
+        
         self.FavListPage.Init()
-
-    def InitRomListPage(self, main_screen):
+    
+    def InitRomListPage(self,main_screen):
         self.RomListPage = RomListPage()
         self.RomListPage._Screen = main_screen
-        self.RomListPage._Name = self._Emulator["TITLE"]
+        self.RomListPage._Name   = self._Emulator["TITLE"]
         self.RomListPage._Emulator = self._Emulator
         self.RomListPage._Parent = self
         self.RomListPage.Init()
-
-    def Init(self, main_screen):
+    
+    def Init(self,main_screen):
         self.load_icons()
-        self.InitDeleteConfirmPage(main_screen)
+        self.InitDeleteConfirmPage(main_screen)    
         self.InitRomListPage(main_screen)
         self.InitFavListPage(main_screen)
-
-    def API(self, main_screen):
-        if main_screen != None:
+    
+    def API(self,main_screen):
+        if main_screen !=None:
             main_screen.PushCurPage()
             main_screen.SetCurPage(self.RomListPage)
             main_screen.Draw()

+ 138 - 125
sys.py/UI/Emulator/fav_list_page.py

@@ -1,103 +1,108 @@
 # -*- coding: utf-8 -*- 
 
-import glob
 import os
-
 import pygame
+import glob
+
 from libs.roundrects import aa_round_rect
 
-from .list_item import ListItem
-from .rom_so_confirm_page import RomSoConfirmPage
 ## local UI import
-from ..constants import Width, ICON_TYPES, RUNEVT
-from ..fonts import fonts
-from ..icon_item import IconItem
-from ..icon_pool import MyIconPool
-from ..keys_def import CurKeys
-from ..multi_icon_item import MultiIconItem
-from ..page import Page, PageSelector
-from ..scroller import ListScroller
-from ..util_funcs import CmdClean, FileExists
+from UI.constants import Width,Height,ICON_TYPES,RUNEVT
+from UI.page   import Page,PageSelector
+from UI.label  import Label
+from UI.icon_item import IconItem
+from UI.fonts  import fonts
+from UI.util_funcs import midRect,CmdClean,FileExists
+from UI.keys_def   import CurKeys
+from UI.multi_icon_item import MultiIconItem
+from UI.icon_pool import MyIconPool
+from UI.scroller  import ListScroller
+
+from rom_so_confirm_page import RomSoConfirmPage
+
+from list_item  import ListItem
 
 
 class FavStack:
     _Emulator = None
-
+    
     def __init__(self):
         self.stack = list()
 
-    def Push(self, data):
+    def Push(self,data):
         if data not in self.stack:
             self.stack.append(data)
             return True
         return False
 
     def Pop(self):
-        if len(self.stack) <= 0:
-            return None, False
-        return self.stack.pop(), True
+        if len(self.stack)<=0:
+            return None,False
+        return self.stack.pop(),True
 
     def Last(self):
-        idx = len(self.stack) - 1
-        if idx < 0:  ## empty stack,return root path
+        idx = len(self.stack) -1
+        if idx < 0:## empty stack,return root path
             return self._Emulator["ROM"]
         else:
-            return self.stack[idx]
-
+            return self.stack[ idx ]
+    
     def Length(self):
         return len(self.stack)
 
-
 class ListPageSelector(PageSelector):
-    _BackgroundColor = pygame.Color(131, 199, 219)
+    _BackgroundColor = pygame.Color(131,199,219)
 
     def __init__(self):
         self._PosX = 0
         self._PosY = 0
         self._Height = 0
-        self._Width = Width - 12
+        self._Width  = Width-12
 
-    def AnimateDraw(self, x2, y2):
+    def AnimateDraw(self,x2,y2):
         pass
 
     def Draw(self):
         idx = self._Parent._PsIndex
-        if idx > (len(self._Parent._MyList) - 1):
+        if idx > (len(self._Parent._MyList)-1):
             idx = len(self._Parent._MyList)
             if idx > 0:
-                idx -= 1
-            elif idx == 0:  ##nothing in _MyList
+                idx -=1
+            elif idx == 0:##nothing in _MyList
                 return
 
-        self._Parent._PsIndex = idx  # sync PsIndex
-
-        x = self._Parent._MyList[idx]._PosX + 2
-        y = self._Parent._MyList[idx]._PosY + 1
-        h = self._Parent._MyList[idx]._Height - 3
-
+        self._Parent._PsIndex = idx #sync PsIndex
+        
+        x = self._Parent._MyList[idx]._PosX+2
+        y = self._Parent._MyList[idx]._PosY+1
+        h = self._Parent._MyList[idx]._Height -3
+        
         self._PosX = x
         self._PosY = y
         self._Height = h
 
-        aa_round_rect(self._Parent._CanvasHWND,
-                      (x, y, self._Width - 4, h), self._BackgroundColor, 4, 0, self._BackgroundColor)
+        aa_round_rect(self._Parent._CanvasHWND,  
+                    (x,y,self._Width-4,h),self._BackgroundColor,4,0,self._BackgroundColor)
+
 
 
 class FavListPage(Page):
+
     _Icons = {}
-    _Selector = None
-    _FootMsg = ["Nav", "Scan", "Remove", "", "Run"]
+    _Selector=None
+    _FootMsg = ["Nav","Scan","Remove","","Run"]
     _MyList = []
     _ListFont = fonts["notosanscjk15"]
     _MyStack = None
     _Emulator = None
-    _Parent = None
+    _Parent   = None
     _Scroller = None
     _Scrolled = 0
-    _BGwidth = 75
+    _BGwidth  = 75
     _BGheight = 73
     _RomSoConfirmDownloadPage = None
 
+    
     def __init__(self):
         Page.__init__(self)
         self._Icons = {}
@@ -105,18 +110,19 @@ class FavListPage(Page):
         self._MyList = []
         self._MyStack = FavStack()
         self._Emulator = {}
-
-    def GeneratePathList(self, path):
+        
+    def GeneratePathList(self,path):
         if os.path.isdir(path) == False:
             return False
 
-        files_path = glob.glob(path + "/*")
+
+        files_path = glob.glob(path+"/*")
 
         ret = []
 
-        for i, v in enumerate(files_path):
+        for i ,v in enumerate(files_path):
             dirmap = {}
-            # if os.path.isdir(v):
+            #if os.path.isdir(v):
             #    continue
             #    dir_base_name = os.path.basename(v)
             #    if dir_base_name == ".Trash" or dir_base_name == ".Fav":
@@ -124,59 +130,60 @@ class FavListPage(Page):
             #    else:
             #        dirmap["directory"] = v
             #        ret.append(dirmap)
-
+                    
             if os.path.isfile(v):
                 stats = os.stat(v)
                 if stats.st_gid != self._Parent._FavGID:
                     continue
                 bname = os.path.basename(v)  ### filter extension
-                if len(bname) > 1:
-                    pieces = bname.split(".")
+                if len(bname)> 1:
+                    pieces  = bname.split(".")
                     if len(pieces) > 1:
-                        if pieces[len(pieces) - 1].lower() in self._Emulator["EXT"]:
+                        if pieces[ len(pieces)-1   ].lower() in self._Emulator["EXT"]:
                             dirmap["file"] = v
                             ret.append(dirmap)
+                
+#            else:
+#                print("not file or dir")
 
-        #            else:
-        #                print("not file or dir")
-
+        
         return ret
 
-    def SyncList(self, path):
-
+    def SyncList(self,path):
+        
         alist = self.GeneratePathList(path)
-
+        
         if alist == False:
             print("listfiles return false")
             return
-        #        print("fav list alist: ")
-        #        print(alist)
-
+#        print("fav list alist: ")
+#        print(alist)
+        
         self._MyList = []
-        start_x = 0
-        start_y = 0
+        start_x  = 0
+        start_y  = 0
         hasparent = 0
         if self._MyStack.Length() > 0:
             hasparent = 1
             li = ListItem()
             li._Parent = self
-            li._PosX = start_x
-            li._PosY = start_y
-            li._Width = Width
+            li._PosX   = start_x
+            li._PosY   = start_y
+            li._Width  = Width
             li._Fonts["normal"] = self._ListFont
             li._MyType = ICON_TYPES["DIR"]
             li._Parent = self
             li.Init("[..]")
             self._MyList.append(li)
-
-        for i, v in enumerate(sorted(alist)):
+        
+        for i,v in enumerate(sorted(alist)):
             li = ListItem()
             li._Parent = self
-            li._PosX = start_x
-            li._PosY = start_y + (i + hasparent) * ListItem._Height
-            li._Width = Width
+            li._PosX   = start_x
+            li._PosY   = start_y + (i+hasparent)*ListItem._Height
+            li._Width  = Width
             li._Fonts["normal"] = self._ListFont
-            li._MyType = ICON_TYPES["FILE"]
+            li._MyType  = ICON_TYPES["FILE"]
             li._Parent = self
             if "directory" in v:
                 li._MyType = ICON_TYPES["DIR"]
@@ -185,9 +192,11 @@ class FavListPage(Page):
                 li.Init(v["file"])
             else:
                 li.Init("NoName")
-
+            
             self._MyList.append(li)
 
+        
+        
     def Init(self):
         self._PosX = self._Index * self._Screen._Width
         self._Width = self._Screen._Width
@@ -208,17 +217,18 @@ class FavListPage(Page):
         icon_for_list._ImgSurf = self._Parent._Icons["sys"]
         icon_for_list._MyType = ICON_TYPES["STAT"]
         icon_for_list._Parent = self
-        icon_for_list.Adjust(0, 0, 18, 18, 0)
-
+        icon_for_list.Adjust(0,0,18,18,0)
+        
         self._Icons["sys"] = icon_for_list
 
+
         bgpng = IconItem()
         bgpng._ImgSurf = MyIconPool._Icons["star"]
         bgpng._MyType = ICON_TYPES["STAT"]
         bgpng._Parent = self
         bgpng.AddLabel("my favourites games", fonts["varela18"])
-        bgpng.SetLableColor(pygame.Color(204, 204, 204))
-        bgpng.Adjust(0, 0, self._BGwidth, self._BGheight, 0)
+        bgpng.SetLableColor(pygame.Color(204,204,204))
+        bgpng.Adjust(0,0,self._BGwidth,self._BGheight,0)
 
         self._Icons["bg"] = bgpng
 
@@ -235,15 +245,15 @@ class FavListPage(Page):
         rom_so_confirm_page.Init()
 
         self._RomSoConfirmDownloadPage = rom_so_confirm_page
-
+        
     def ScrollUp(self):
         if len(self._MyList) == 0:
             return
-
+        
         self._PsIndex -= 1
         if self._PsIndex < 0:
             self._PsIndex = 0
-
+        
         cur_li = self._MyList[self._PsIndex]
         if cur_li._PosY < 0:
             for i in range(0, len(self._MyList)):
@@ -254,17 +264,16 @@ class FavListPage(Page):
     def ScrollDown(self):
         if len(self._MyList) == 0:
             return
-
-        self._PsIndex += 1
+        
+        self._PsIndex +=1
         if self._PsIndex >= len(self._MyList):
-            self._PsIndex = len(self._MyList) - 1
+            self._PsIndex = len(self._MyList) -1
 
         cur_li = self._MyList[self._PsIndex]
-        if cur_li._PosY + cur_li._Height > self._Height:
-            for i in range(0, len(self._MyList)):
+        if cur_li._PosY +cur_li._Height > self._Height:
+            for i in range(0,len(self._MyList)):
                 self._MyList[i]._PosY -= self._MyList[i]._Height
-            self._Scrolled -= 1
-
+            self._Scrolled -=1
     def SyncScroll(self):
         ## 
         if self._Scrolled == 0:
@@ -277,10 +286,10 @@ class FavListPage(Page):
                     for i in range(0, len(self._MyList)):
                         self._MyList[i]._PosY += self._Scrolled * self._MyList[i]._Height
             elif self._Scrolled < 0:
-                if cur_li._PosY + cur_li._Height > self._Height:
-                    for i in range(0, len(self._MyList)):
+                if cur_li._PosY +cur_li._Height > self._Height:
+                    for i in range(0,len(self._MyList)):
                         self._MyList[i]._PosY += self._Scrolled * self._MyList[i]._Height
-
+                
     def Click(self):
 
         if len(self._MyList) == 0:
@@ -293,33 +302,33 @@ class FavListPage(Page):
 
         if cur_li._MyType == ICON_TYPES["DIR"]:
             return
-
-        if cur_li._MyType == ICON_TYPES["FILE"]:  ## add to playlist only
+        
+        if cur_li._MyType == ICON_TYPES["FILE"]: ## add to playlist only
             self._Screen._MsgBox.SetText("Launching...")
             self._Screen._MsgBox.Draw()
             self._Screen.SwapAndShow()
-            print("Run ", cur_li._Path)
-
+            print("Run ",cur_li._Path)
+            
             # check ROM_SO exists
             if FileExists(self._Emulator["ROM_SO"]):
-                escaped_path = CmdClean(cur_li._Path)
-
+                escaped_path = CmdClean( cur_li._Path)
+                
                 custom_config = ""
                 if self._Emulator["RETRO_CONFIG"] != "" and len(self._Emulator["RETRO_CONFIG"]) > 5:
                     custom_config = " -c " + self._Emulator["RETRO_CONFIG"]
                         
                 cmdpath = " ".join( (self._Emulator["LAUNCHER"],self._Emulator["ROM_SO"], custom_config, escaped_path))
-
-                pygame.event.post(pygame.event.Event(RUNEVT, message=cmdpath))
+                
+                pygame.event.post( pygame.event.Event(RUNEVT, message=cmdpath))
                 return
             else:
-
+                
                 self._Screen.PushPage(self._RomSoConfirmDownloadPage)
                 self._Screen.Draw()
                 self._Screen.SwapAndShow()
 
             return
-
+    
         self._Screen.Draw()
         self._Screen.SwapAndShow()
 
@@ -327,37 +336,39 @@ class FavListPage(Page):
         if self._MyStack.Length() == 0:
             self.SyncList(self._Emulator["ROM"])
         else:
-            self.SyncList(self._MyStack.Last())
-
+            self.SyncList( self._MyStack.Last() )
+            
         idx = self._PsIndex
-        if idx > (len(self._MyList) - 1):
+        if idx > (len(self._MyList)-1):
             idx = len(self._MyList)
             if idx > 0:
-                idx -= 1
-            elif idx == 0:  ##nothing in _MyList
+                idx -=1
+            elif idx == 0:##nothing in _MyList
                 pass
-
-        self._PsIndex = idx  ## sync PsIndex
+        
+        self._PsIndex = idx ## sync PsIndex
 
         self.SyncScroll()
 
+
     def OnReturnBackCb(self):
         self.ReScan()
         self._Screen.Draw()
         self._Screen.SwapAndShow()
-
+        
     def OnLoadCb(self):
         self.ReScan()
         self._Screen.Draw()
         self._Screen.SwapAndShow()
-
-    def KeyDown(self, event):
-
-        if event.key == CurKeys["Menu"] or event.key == CurKeys["Left"]:
+        
+    def KeyDown(self,event):
+        
+        if event.key == CurKeys["Menu"] or event.key == CurKeys["Left"]: 
             self.ReturnToUpLevelPage()
             self._Screen.Draw()
             self._Screen.SwapAndShow()
 
+        
         if event.key == CurKeys["Up"]:
             self.ScrollUp()
             self._Screen.Draw()
@@ -366,19 +377,21 @@ class FavListPage(Page):
             self.ScrollDown()
             self._Screen.Draw()
             self._Screen.SwapAndShow()
+        
 
         if event.key == CurKeys["Enter"]:
             self.Click()
 
-        if event.key == CurKeys["X"]:  # Scan current
-            self.ReScan()
-            self._Screen.Draw()
-            self._Screen.SwapAndShow()
+                
+        if event.key == CurKeys["X"]: #Scan current
+           self.ReScan() 
+           self._Screen.Draw()
+           self._Screen.SwapAndShow()
 
-        if event.key == CurKeys["Y"]:  # del
+        if event.key == CurKeys["Y"]: #del
             if len(self._MyList) == 0:
                 return
-
+            
             cur_li = self._MyList[self._PsIndex]
             if cur_li.IsFile():
                 """
@@ -390,28 +403,28 @@ class FavListPage(Page):
                 #self._Screen.SwapAndShow()
                 """
 
-                # delete directly without confirm dialog
+                #delete directly without confirm dialog
                 stats = os.stat(cur_li._Path)
-                os.chown(cur_li._Path, stats.st_uid, stats.st_uid) ## normally uid and gid should be the same 
+                os.chown(cur_li._Path, stats.st_uid,stats.st_uid) ## normally uid and gid should be the same 
                 self._Screen._MsgBox.SetText("Deleting...")
                 self._Screen._MsgBox.Draw()
                 self._Screen.SwapAndShow()
                 pygame.time.delay(600)
-                self.ReScan()
+                self.ReScan()                    
                 self._Screen.Draw()
                 self._Screen.SwapAndShow()
-
+                
     def Draw(self):
         self.ClearCanvas()
-
+        
         if len(self._MyList) == 0:
-            self._Icons["bg"].NewCoord(self._Width / 2, self._Height / 2)
+            self._Icons["bg"].NewCoord(self._Width/2,self._Height/2)
             self._Icons["bg"].Draw()
         else:
             if len(self._MyList) * ListItem._Height > self._Height:
                 self._Ps._Width = self._Width - 10
                 self._Ps.Draw()
-
+                
                 for i in self._MyList:
                     if i._PosY > self._Height + self._Height/2:
                         break
@@ -421,9 +434,9 @@ class FavListPage(Page):
                     
                     i.Draw()
                 
-                self._Scroller.UpdateSize(len(self._MyList) * ListItem._Height, self._PsIndex * ListItem._Height)
+                self._Scroller.UpdateSize( len(self._MyList)*ListItem._Height, self._PsIndex*ListItem._Height)
                 self._Scroller.Draw()
-
+    
             else:
                 self._Ps._Width = self._Width
                 self._Ps.Draw()

+ 3 - 9
sys.py/UI/Emulator/list_item.py

@@ -6,17 +6,11 @@ import os
 
 ## local UI import
 from UI.constants import ICON_TYPES
+from UI.page   import Page
 from UI.label  import Label
+from UI.fonts  import fonts
 from UI.icon_item import IconItem
-# from beeprint import pp
-import os
-
-import pygame
-## local UI import
-from UI.constants import ICON_TYPES
-from UI.icon_item import IconItem
-from UI.label import Label
-
+from UI.util_funcs import midRect
 
 # a item for List
 # - - - - - - - - - - - -- 

+ 156 - 139
sys.py/UI/Emulator/rom_list_page.py

@@ -1,129 +1,139 @@
 # -*- coding: utf-8 -*- 
 
-import glob
 import os
-
 import pygame
+
+import glob
+import shutil
+import gobject
+import validators
+#from pySmartDL import SmartDL
+
+
 from libs.roundrects import aa_round_rect
 
-from .list_item import ListItem
-from .rom_so_confirm_page import RomSoConfirmPage
 ## local UI import
-from ..constants import Width, ICON_TYPES, RUNEVT
-from ..fonts import fonts
-from ..icon_item import IconItem
-from ..icon_pool import MyIconPool
-from ..keys_def import CurKeys
-from ..multi_icon_item import MultiIconItem
-from ..page import Page, PageSelector
-from ..scroller import ListScroller
-from ..util_funcs import CmdClean, FileExists
-
+from UI.constants import Width,Height,ICON_TYPES,RUNEVT
+from UI.page   import Page,PageSelector
+from UI.label  import Label
+from UI.icon_item import IconItem
+from UI.fonts  import fonts
+from UI.util_funcs import midRect,CmdClean,FileExists
+from UI.keys_def   import CurKeys
+from UI.multi_icon_item import MultiIconItem
+from UI.icon_pool  import MyIconPool
+from UI.scroller   import ListScroller
+
+from rom_so_confirm_page import RomSoConfirmPage
 
 from UI.Emulator.list_item  import ListItem
-
+import config
+    
 class RomStack:
     _Emulator = None
-
+    
     def __init__(self):
         self.stack = list()
 
-    def Push(self, data):
+    def Push(self,data):
         if data not in self.stack:
             self.stack.append(data)
             return True
         return False
 
     def Pop(self):
-        if len(self.stack) <= 0:
-            return None, False
-        return self.stack.pop(), True
+        if len(self.stack)<=0:
+            return None,False
+        return self.stack.pop(),True
 
     def Last(self):
-        idx = len(self.stack) - 1
-        if idx < 0:  ## empty stack,return root path
+        idx = len(self.stack) -1
+        if idx < 0:## empty stack,return root path
             return self._Emulator["ROM"]
         else:
-            return self.stack[idx]
-
+            return self.stack[ idx ]
+    
     def Length(self):
         return len(self.stack)
 
-
 class ListPageSelector(PageSelector):
-    _BackgroundColor = pygame.Color(131, 199, 219)
+    _BackgroundColor = pygame.Color(131,199,219)
 
     def __init__(self):
         self._PosX = 0
         self._PosY = 0
         self._Height = 0
-        self._Width = Width - 12
+        self._Width  = Width-12
 
-    def AnimateDraw(self, x2, y2):
+    def AnimateDraw(self,x2,y2):
         pass
 
     def Draw(self):
         idx = self._Parent._PsIndex
-        if idx > (len(self._Parent._MyList) - 1):
+        if idx > (len(self._Parent._MyList)-1):
             idx = len(self._Parent._MyList)
             if idx > 0:
-                idx -= 1
-            elif idx == 0:  ##nothing in _MyList
+                idx -=1
+            elif idx == 0:##nothing in _MyList
                 return
 
-        self._Parent._PsIndex = idx  ## sync PsIndex
-
-        x = self._Parent._MyList[idx]._PosX + 2
-        y = self._Parent._MyList[idx]._PosY + 1
-        h = self._Parent._MyList[idx]._Height - 3
-
+        self._Parent._PsIndex = idx ## sync PsIndex
+        
+        x = self._Parent._MyList[idx]._PosX+2
+        y = self._Parent._MyList[idx]._PosY+1
+        h = self._Parent._MyList[idx]._Height -3
+        
         self._PosX = x
         self._PosY = y
         self._Height = h
 
-        aa_round_rect(self._Parent._CanvasHWND,
-                      (x, y, self._Width - 4, h), self._BackgroundColor, 4, 0, self._BackgroundColor)
+        aa_round_rect(self._Parent._CanvasHWND,  
+                    (x,y,self._Width-4,h),self._BackgroundColor,4,0,self._BackgroundColor)
+
 
 
 class RomListPage(Page):
+
     _Icons = {}
-    _Selector = None
-    _FootMsg = ["Nav", "Scan", "Del", "Add Fav", "Run"]
+    _Selector=None
+    _FootMsg = ["Nav","Scan","Del","Add Fav","Run"]
     _MyList = []
     _ListFont = fonts["notosanscjk15"]
     _MyStack = None
     _Emulator = None
-    _Parent = None
+    _Parent   = None
 
     _Scroller = None
-
+    
     _Scrolled = 0
 
     _BGwidth = 56
     _BGheight = 70
 
     _RomSoConfirmDownloadPage = None
-
+    
+    
     def __init__(self):
         Page.__init__(self)
-
+        
         self._Icons = {}
         self._CanvasHWND = None
         self._MyList = []
         self._MyStack = RomStack()
         self._Emulator = {}
-
-    def GeneratePathList(self, path):
+        
+    def GeneratePathList(self,path):
         if os.path.isdir(path) == False:
             return False
 
-        files_path = glob.glob(path + "/*")
 
+        files_path = glob.glob(path+"/*")
+        
         ret = []
 
-        for i, v in enumerate(files_path):
+        for i ,v in enumerate(files_path):
             dirmap = {}
-            # if os.path.isdir(v):
+            #if os.path.isdir(v):
             #    dir_base_name = os.path.basename(v)
             #    if dir_base_name == ".Trash" or dir_base_name == ".Fav":
             #        pass
@@ -134,55 +144,56 @@ class RomListPage(Page):
                 stats = os.stat(v)
                 if stats.st_gid == self._Parent._FavGID:
                     continue
-
+                
                 bname = os.path.basename(v)  ### filter extension
-                if len(bname) > 1:
-                    pieces = bname.split(".")
+                if len(bname)> 1:
+                    pieces  = bname.split(".")
                     if len(pieces) > 1:
-                        if pieces[len(pieces) - 1].lower() in self._Emulator["EXT"]:
+                        if pieces[ len(pieces)-1   ].lower() in self._Emulator["EXT"]:
                             dirmap["file"] = v
                             ret.append(dirmap)
-        #            else:
-        #                print("not file or dir")
+#            else:
+#                print("not file or dir")
 
+        
         return ret
 
-    def SyncList(self, path):
-
+    def SyncList(self,path):
+        
         alist = self.GeneratePathList(path)
-
+        
         if alist == False:
             print("listfiles return false")
             return
-
+                
         self._MyList = []
-        start_x = 0
-        start_y = 0
+        start_x  = 0
+        start_y  = 0
         hasparent = 0
         if self._MyStack.Length() > 0:
             hasparent = 1
             li = ListItem()
             li._Parent = self
-            li._PosX = start_x
-            li._PosY = start_y
-            li._Width = Width
+            li._PosX   = start_x
+            li._PosY   = start_y
+            li._Width  = Width
             li._Fonts["normal"] = self._ListFont
             li._MyType = ICON_TYPES["DIR"]
             li._Parent = self
             li.Init("[..]")
             self._MyList.append(li)
-
-        for i, v in enumerate(sorted(alist)):
+        
+        for i,v in enumerate(sorted(alist)):
             li = ListItem()
             li._Parent = self
-            li._PosX = start_x
-            li._PosY = start_y + (i + hasparent) * ListItem._Height
-            li._Width = Width
+            li._PosX   = start_x
+            li._PosY   = start_y + (i+hasparent)*ListItem._Height
+            li._Width  = Width
             li._Fonts["normal"] = self._ListFont
-            li._MyType = ICON_TYPES["FILE"]
+            li._MyType  = ICON_TYPES["FILE"]
 
             li._Parent = self
-
+            
             if "directory" in v:
                 li._MyType = ICON_TYPES["DIR"]
                 li.Init(v["directory"])
@@ -191,8 +202,10 @@ class RomListPage(Page):
             else:
                 li.Init("NoName")
 
+            
             self._MyList.append(li)
 
+        
     def Init(self):
         self._PosX = self._Index * self._Screen._Width
         self._Width = self._Screen._Width
@@ -208,16 +221,17 @@ class RomListPage(Page):
         self.SyncList(self._Emulator["ROM"])
 
         ### will also mkdir of the ***ROM self
-        try:
-            os.makedirs(self._Emulator["ROM"] + "/.Trash")
+        try: 
+            os.makedirs(self._Emulator["ROM"]+"/.Trash")
         except OSError:
-            if not os.path.isdir(self._Emulator["ROM"] + "/.Trash"):
+            if not os.path.isdir(self._Emulator["ROM"]+"/.Trash"):
                 raise
+            
 
-        try:
-            os.makedirs(self._Emulator["ROM"] + "/.Fav")
+        try: 
+            os.makedirs(self._Emulator["ROM"]+"/.Fav")
         except OSError:
-            if not os.path.isdir(self._Emulator["ROM"] + "/.Fav"):
+            if not os.path.isdir(self._Emulator["ROM"]+"/.Fav"):
                 raise
 
         self._MyStack._Emulator = self._Emulator
@@ -226,18 +240,19 @@ class RomListPage(Page):
         icon_for_list._ImgSurf = self._Parent._Icons["sys"]
         icon_for_list._MyType = ICON_TYPES["STAT"]
         icon_for_list._Parent = self
-
-        icon_for_list.Adjust(0, 0, 18, 18, 0)
-
+        
+        icon_for_list.Adjust(0,0,18,18,0)
+        
         self._Icons["sys"] = icon_for_list
 
+
         bgpng = IconItem()
         bgpng._ImgSurf = MyIconPool._Icons["empty"]
         bgpng._MyType = ICON_TYPES["STAT"]
         bgpng._Parent = self
         bgpng.AddLabel("Please upload data over Wi-Fi", fonts["varela22"])
-        bgpng.SetLableColor(pygame.Color(204, 204, 204))
-        bgpng.Adjust(0, 0, self._BGwidth, self._BGheight, 0)
+        bgpng.SetLableColor(pygame.Color(204,204,204))
+        bgpng.Adjust(0,0,self._BGwidth,self._BGheight,0)
 
         self._Icons["bg"] = bgpng
 
@@ -254,11 +269,11 @@ class RomListPage(Page):
         rom_so_confirm_page.Init()
 
         self._RomSoConfirmDownloadPage = rom_so_confirm_page
-
+        
     def ScrollUp(self):
         if len(self._MyList) == 0:
             return
-
+        
         self._PsIndex -= 1
         if self._PsIndex < 0:
             self._PsIndex = 0
@@ -266,22 +281,22 @@ class RomListPage(Page):
         if cur_li._PosY < 0:
             for i in range(0, len(self._MyList)):
                 self._MyList[i]._PosY += self._MyList[i]._Height
-            self._Scrolled += 1
+            self._Scrolled +=1
 
     def ScrollDown(self):
         if len(self._MyList) == 0:
             return
-
-        self._PsIndex += 1
+        
+        self._PsIndex +=1
         if self._PsIndex >= len(self._MyList):
-            self._PsIndex = len(self._MyList) - 1
+            self._PsIndex = len(self._MyList) -1
 
         cur_li = self._MyList[self._PsIndex]
-        if cur_li._PosY + cur_li._Height > self._Height:
-            for i in range(0, len(self._MyList)):
+        if cur_li._PosY +cur_li._Height > self._Height:
+            for i in range(0,len(self._MyList)):
                 self._MyList[i]._PosY -= self._MyList[i]._Height
             self._Scrolled -= 1
-
+            
     def SyncScroll(self):
         ## 
         if self._Scrolled == 0:
@@ -294,10 +309,10 @@ class RomListPage(Page):
                     for i in range(0, len(self._MyList)):
                         self._MyList[i]._PosY += self._Scrolled * self._MyList[i]._Height
             elif self._Scrolled < 0:
-                if cur_li._PosY + cur_li._Height > self._Height:
-                    for i in range(0, len(self._MyList)):
+                if cur_li._PosY +cur_li._Height > self._Height:
+                    for i in range(0,len(self._MyList)):
                         self._MyList[i]._PosY += self._Scrolled * self._MyList[i]._Height
-
+                
     def Click(self):
         if len(self._MyList) == 0:
             return
@@ -306,40 +321,40 @@ class RomListPage(Page):
             return
         
         cur_li = self._MyList[self._PsIndex]
-
+        
         if cur_li._MyType == ICON_TYPES["DIR"]:
             if cur_li._Path == "[..]":
                 self._MyStack.Pop()
-                self.SyncList(self._MyStack.Last())
+                self.SyncList( self._MyStack.Last() )
                 self._PsIndex = 0
             else:
-                self._MyStack.Push(self._MyList[self._PsIndex]._Path)
-                self.SyncList(self._MyStack.Last())
+                self._MyStack.Push( self._MyList[self._PsIndex]._Path )
+                self.SyncList( self._MyStack.Last() )
                 self._PsIndex = 0
-
-        if cur_li._MyType == ICON_TYPES["FILE"]:  ## add to playlist only
+                
+        if cur_li._MyType == ICON_TYPES["FILE"]: ## add to playlist only
             self._Screen._MsgBox.SetText("Launching...")
             self._Screen._MsgBox.Draw()
             self._Screen.SwapAndShow()
-            print("Run  ", cur_li._Path)
+            print("Run  ",cur_li._Path)
 
             # check ROM_SO exists
             if FileExists(self._Emulator["ROM_SO"]):
-                escaped_path = CmdClean(cur_li._Path)
-
+                escaped_path = CmdClean( cur_li._Path)
+                
                 custom_config = ""
                 if self._Emulator["RETRO_CONFIG"] != "" and len(self._Emulator["RETRO_CONFIG"]) > 5:
                     custom_config = " -c " + self._Emulator["RETRO_CONFIG"]
                     
                 cmdpath = " ".join( (self._Emulator["LAUNCHER"],self._Emulator["ROM_SO"], custom_config, escaped_path))
-                pygame.event.post(pygame.event.Event(RUNEVT, message=cmdpath))
+                pygame.event.post( pygame.event.Event(RUNEVT, message=cmdpath))
                 return
             else:
-
+                
                 self._Screen.PushPage(self._RomSoConfirmDownloadPage)
                 self._Screen.Draw()
                 self._Screen.SwapAndShow()
-
+    
         self._Screen.Draw()
         self._Screen.SwapAndShow()
 
@@ -347,28 +362,29 @@ class RomListPage(Page):
         if self._MyStack.Length() == 0:
             self.SyncList(self._Emulator["ROM"])
         else:
-            self.SyncList(self._MyStack.Last())
+            self.SyncList( self._MyStack.Last() )
 
+        
         idx = self._PsIndex
-        if idx > (len(self._MyList) - 1):
+        if idx > (len(self._MyList)-1):
             idx = len(self._MyList)
             if idx > 0:
-                idx -= 1
-            elif idx == 0:  ##nothing in _MyList
+                idx -=1
+            elif idx == 0:##nothing in _MyList
                 pass
-
-        self._PsIndex = idx  ## sync PsIndex
+        
+        self._PsIndex = idx ## sync PsIndex
 
         self.SyncScroll()
 
     def OnReturnBackCb(self):
-        self.ReScan()
+        self.ReScan()        
         self._Screen.Draw()
         self._Screen.SwapAndShow()
+        
+    def KeyDown(self,event):
 
-    def KeyDown(self, event):
-
-        if event.key == CurKeys["Menu"]:
+        if event.key == CurKeys["Menu"] : 
             self.ReturnToUpLevelPage()
             self._Screen.Draw()
             self._Screen.SwapAndShow()
@@ -378,7 +394,7 @@ class RomListPage(Page):
             self._Screen.SetCurPage(self._Parent.FavListPage)
             self._Screen.Draw()
             self._Screen.SwapAndShow()
-
+        
         if event.key == CurKeys["Up"]:
             self.ScrollUp()
             self._Screen.Draw()
@@ -395,54 +411,55 @@ class RomListPage(Page):
         if event.key == CurKeys["A"]:
             if len(self._MyList) == 0:
                 return
-
+            
             cur_li = self._MyList[self._PsIndex]
             if cur_li.IsFile():
                 # remove any dup first
-
+                
                 try:
-                    os.system("chgrp " + self._Parent._FavGname + " " + CmdClean(cur_li._Path))
+                    os.system("chgrp " + self._Parent._FavGname +" "+ CmdClean(cur_li._Path))
                 except:
                     pass
-
+                
                 self._Screen._MsgBox.SetText("Adding to Favourite list")
                 self._Screen._MsgBox.Draw()
                 self._Screen.SwapAndShow()
-
+                
                 pygame.time.delay(600)
-                self.ReScan()
+                self.ReScan()                    
                 self._Screen.Draw()
                 self._Screen.SwapAndShow()
-
-        if event.key == CurKeys["X"]:  # Scan current
-            self.ReScan()
-            self._Screen.Draw()
-            self._Screen.SwapAndShow()
-
-        if event.key == CurKeys["Y"]:  # del
+                
+        if event.key == CurKeys["X"]: #Scan current
+           self.ReScan() 
+           self._Screen.Draw()
+           self._Screen.SwapAndShow()
+           
+        if event.key == CurKeys["Y"]: #del
             if len(self._MyList) == 0:
                 return
-
+            
             cur_li = self._MyList[self._PsIndex]
             if cur_li.IsFile():
+                
                 self._Parent.DeleteConfirmPage.SetFileName(cur_li._Path)
-                self._Parent.DeleteConfirmPage.SetTrashDir(self._Emulator["ROM"] + "/.Trash")
-
+                self._Parent.DeleteConfirmPage.SetTrashDir(self._Emulator["ROM"]+"/.Trash")
+            
                 self._Screen.PushCurPage()
                 self._Screen.SetCurPage(self._Parent.DeleteConfirmPage)
                 self._Screen.Draw()
                 self._Screen.SwapAndShow()
-
+            
     def Draw(self):
         self.ClearCanvas()
         if len(self._MyList) == 0:
-            self._Icons["bg"].NewCoord(self._Width / 2, self._Height / 2)
+            self._Icons["bg"].NewCoord(self._Width/2,self._Height/2)
             self._Icons["bg"].Draw()
         else:
             if len(self._MyList) * ListItem._Height > self._Height:
                 self._Ps._Width = self._Width - 10
                 self._Ps.Draw()
-
+                
                 for i in self._MyList:
                     if i._PosY > self._Height + self._Height/2:
                         break
@@ -451,9 +468,9 @@ class RomListPage(Page):
                         continue
                     i.Draw()
                     
-                self._Scroller.UpdateSize(len(self._MyList) * ListItem._Height, self._PsIndex * ListItem._Height)
+                self._Scroller.UpdateSize( len(self._MyList)*ListItem._Height, self._PsIndex*ListItem._Height)
                 self._Scroller.Draw()
-
+    
             else:
                 self._Ps._Width = self._Width
                 self._Ps.Draw()

+ 37 - 28
sys.py/UI/Emulator/rom_so_confirm_page.py

@@ -1,16 +1,24 @@
-# -*- coding: utf-8 -*-
+
+# -*- coding: utf-8 -*- 
 
 import os
+import pygame
+
+import glob
+import shutil
+import gobject
+import validators
+#from pySmartDL import SmartDL
+
+from libs.roundrects import aa_round_rect
 
-import config
 from UI.confirm_page import ConfirmPage
 from UI.download_process_page import DownloadProcessPage
-from UI.fonts import fonts
-from UI.keys_def import CurKeys
+from UI.keys_def   import CurKeys
+from UI.fonts  import fonts
 from UI.multilabel import MultiLabel
 
-
-# from pySmartDL import SmartDL
+import config
 
 class RomSoConfirmPage(ConfirmPage):
     _ListFont = fonts["veramono18"]
@@ -18,12 +26,12 @@ class RomSoConfirmPage(ConfirmPage):
     _ConfirmText = "Do you want to setup this game engine automatically?"
 
     _MyDownloadPage = None
-
+    
     def CheckBattery(self):
         try:
             f = open(config.Battery)
         except IOError:
-            print("RomSoConfirmPage open %s failed" % config.Battery)
+            print( "RomSoConfirmPage open %s failed" % config.Battery)
             return 6
         else:
             with f:
@@ -39,9 +47,9 @@ class RomSoConfirmPage(ConfirmPage):
                     cur_cap = int(bat_uevent["POWER_SUPPLY_CAPACITY"])
                 else:
                     cur_cap = 0
-
+                
                 return cur_cap
-
+                    
         return 0
 
     def Init(self):
@@ -54,19 +62,19 @@ class RomSoConfirmPage(ConfirmPage):
         li = MultiLabel()
         li.SetCanvasHWND(self._CanvasHWND)
         li._Width = 160
-        li.Init(self._ConfirmText, self._ListFont)
-
-        li._PosX = (self._Width - li._Width) / 2
-        li._PosY = (self._Height - li._Height) / 2
-
-        self._BGPosX = li._PosX - 20
-        self._BGPosY = li._PosY - 20
-        self._BGWidth = li._Width + 40
-        self._BGHeight = li._Height + 40
-
+        li.Init(self._ConfirmText,self._ListFont)
+        
+        li._PosX = (self._Width - li._Width)/2
+        li._PosY = (self._Height - li._Height)/2
+
+        self._BGPosX = li._PosX-20
+        self._BGPosY = li._PosY-20
+        self._BGWidth = li._Width+40
+        self._BGHeight = li._Height+40
+        
         self._MyList.append(li)
-
-    def SnapMsg(self, msg):
+        
+    def SnapMsg(self,msg):
         self._MyList[0].SetText(msg)
         self._Screen.Draw()
         self._Screen.SwapAndShow()
@@ -76,8 +84,8 @@ class RomSoConfirmPage(ConfirmPage):
         self.ReturnToUpLevelPage()
         self._Screen.Draw()
         self._Screen.SwapAndShow()
-
-    def KeyDown(self, event):
+    
+    def KeyDown(self,event):    
         if event.key == CurKeys["Menu"] or event.key == CurKeys["A"]:
             self.ReturnToUpLevelPage()
             self._Screen.Draw()
@@ -92,19 +100,20 @@ class RomSoConfirmPage(ConfirmPage):
                     self._MyDownloadPage._Screen = self._Screen
                     self._MyDownloadPage._Name = "Downloading..."
                     self._MyDownloadPage.Init()
-
+                
                 self._Screen.PushPage(self._MyDownloadPage)
                 self._Screen.Draw()
                 self._Screen.SwapAndShow()
 
                 if config.CurKeySet == "PC":
-                    so_url = self._Parent._Emulator["SO_URL"]  ## [rom/fav]_list_page is _Parent
-                    so_url = so_url.replace("armhf", "x86_64")
+                    so_url = self._Parent._Emulator["SO_URL"] ## [rom/fav]_list_page is _Parent
+                    so_url = so_url.replace("armhf","x86_64")
                     print(so_url)
-                    self._MyDownloadPage.StartDownload(so_url, os.path.dirname(self._Parent._Emulator["ROM_SO"]))
+                    self._MyDownloadPage.StartDownload(so_url,os.path.dirname(self._Parent._Emulator["ROM_SO"]))
                 else:
                     self._MyDownloadPage.StartDownload(self._Parent._Emulator["SO_URL"],
                                                        os.path.dirname(self._Parent._Emulator["ROM_SO"]))
+            
 
     def Draw(self):
         self.ClearCanvas()

+ 0 - 0
sys.py/UI/__init__.py


+ 57 - 45
sys.py/UI/above_all_patch.py

@@ -1,69 +1,80 @@
 # -*- coding: utf-8 -*- 
 
-import alsaaudio
 import pygame
+
 from libs.roundrects import aa_round_rect
 
+import alsaaudio
+
 ## local package import
-from .constants import Width, Height
-from .fonts import fonts
-from .util_funcs import midRect
+from constants   import ICON_TYPES,icon_ext,icon_width,icon_height,RUNEVT
+from icon_item   import IconItem
+from page        import Page,PageStack
+from title_bar   import TitleBar
+from foot_bar    import FootBar
+from constants   import Width,Height,bg_color
+from util_funcs  import midRect
+from fonts       import fonts
+from keys_def    import CurKeys
+from label       import Label
+
+
 
 
 class AboveAllPatch(object):
-    _PosX = Width / 2
-    _PosY = Height / 2
-    _Width = 50
-    _Height = 120
-
-    _Text = ""
-    _FontObj = fonts["veramono20"]
-    _Parent = None
-    _Color = pygame.Color(83, 83, 83)
-    _ValColor = pygame.Color(0, 0, 255)
+    _PosX  =Width/2
+    _PosY  =Height/2
+    _Width =50
+    _Height=120
+    
+    _Text  =""
+    _FontObj=fonts["veramono20"]
+    _Parent =None
+    _Color = pygame.Color(83,83,83)
+    _ValColor= pygame.Color(0,0,255)
     _CanvasHWND = None
     _TextSurf = None
-    _Icons = {}
-    _Value = 0
-
+    _Icons   = {}
+    _Value   = 0
+    
     def __init__(self):
         self._Icons = {}
-
+    
     def Init(self):
         pass
-
-    def SetCanvasHWND(self, _canvashwnd):
+    
+    def SetCanvasHWND(self,_canvashwnd):
         self._CanvasHWND = _canvashwnd
 
     def Draw(self):
-        start_rect = midRect(self._PosX, self._PosY, self._Width, self._Height, Width, Height)
-        aa_round_rect(self._CanvasHWND, start_rect, self._Color, 3, 0, self._Color)
+        start_rect = midRect(self._PosX,self._PosY,self._Width,self._Height,Width,Height)
+        aa_round_rect(self._CanvasHWND,start_rect, self._Color,3,0, self._Color)
 
         if self._Value > 10:
-            vol_height = int(self._Height * (float(self._Value) / 100.0))
-            dheight = self._Height - vol_height
-
-            vol_rect = pygame.Rect(self._PosX - self._Width / 2, self._PosY - self._Height / 2 + dheight, self._Width,
-                                   vol_height)
-
-            aa_round_rect(self._CanvasHWND, vol_rect, self._ValColor, 3, 0, self._ValColor)
+            vol_height = int(self._Height * (float( self._Value)/100.0))
+            dheight    = self._Height - vol_height
+            
+            vol_rect = pygame.Rect(self._PosX-self._Width/2, self._PosY-self._Height/2+dheight, self._Width, vol_height)
 
+            aa_round_rect(self._CanvasHWND,vol_rect, self._ValColor,3,0, self._ValColor)
+        
         else:
             vol_height = 10
-            dheight = self._Height - vol_height
-            vol_rect = pygame.Rect(self._PosX - self._Width / 2, self._PosY - self._Height / 2 + dheight, self._Width,
-                                   vol_height)
-
-            aa_round_rect(self._CanvasHWND, vol_rect, self._ValColor, 3, 0, self._ValColor)
+            dheight    = self._Height - vol_height
+            vol_rect = pygame.Rect(self._PosX-self._Width/2, self._PosY-self._Height/2+dheight, self._Width, vol_height)
 
+            aa_round_rect(self._CanvasHWND,vol_rect, self._ValColor,3,0, self._ValColor)
+    
 
 class SoundPatch(AboveAllPatch):
-    snd_segs = [[0, 20], [21, 40], [41, 50], [51, 60], [61, 70], [71, 85], [86, 90], [91, 95], [96, 100]]
+    
+#    _Segs       = [0,15,29, 45,55,65, 75,90,100]
+    snd_segs = [ [0,20],[21,40],[41,50],[51,60],[61,70],[71,85],[86,90],[91,95],[96,100] ]
     _Needle = 0
-
+    
     def Init(self):
         self.SetCanvasHWND(self._Parent._CanvasHWND)
-
+        
     def VolumeUp(self):
         m = alsaaudio.Mixer()
         vol = m.getvolume()[0]
@@ -73,9 +84,9 @@ class SoundPatch(AboveAllPatch):
             if  vol >= v[0] and vol <= v[1]:
                 self._Needle = i
                 break
-
+          
         self._Needle += 1
-
+        
         if self._Needle > len(self.snd_segs) -1:
             self._Needle = len(self.snd_segs) -1
 
@@ -86,7 +97,7 @@ class SoundPatch(AboveAllPatch):
 
 #        print( self._Value)
         return self._Value
-
+        
     def VolumeDown(self):
         m = alsaaudio.Mixer()
         vol = m.getvolume()[0]
@@ -111,12 +122,13 @@ class SoundPatch(AboveAllPatch):
         self._Value = vol
         return vol
 
+
     def Draw(self):
         # 200 total width
         # h = 40
         for i in range(0,self._Needle+1):
-            # w = 10,h = 40
-            vol_rect = pygame.Rect(80 + i * 20, self._Height / 2 + 20, 10, 40)
-
-            aa_round_rect(self._CanvasHWND, vol_rect, self._Parent._SkinManager.GiveColor("Front"),
-                          3, 0, self._Parent._SkinManager.GiveColor("Front"))
+            #w = 10,h = 40
+            vol_rect = pygame.Rect(80+i*20, self._Height/2+20,10, 40)
+            
+            aa_round_rect(self._CanvasHWND,vol_rect, self._Parent._SkinManager.GiveColor("Front"),3,0, self._Parent._SkinManager.GiveColor("Front"))
+    

+ 76 - 68
sys.py/UI/confirm_page.py

@@ -1,90 +1,98 @@
 # -*- coding: utf-8 -*- 
 
 import pygame
+import os
+
 from libs.roundrects import aa_round_rect
 
-# UI lib
-from .constants import Width
-from .fonts import fonts
-from .label import Label
-from .page import Page, PageSelector
+#UI lib
+from constants import Width,Height,ICON_TYPES
+from page   import Page,PageSelector
+from label  import Label
+from fonts  import fonts
+from util_funcs import midRect
+from keys_def   import CurKeys
+
 
 
 class ListPageSelector(PageSelector):
-    _BackgroundColor = pygame.Color(131, 199, 219)
+    _BackgroundColor = pygame.Color(131,199,219)
 
     def __init__(self):
         self._PosX = 0
         self._PosY = 0
         self._Height = 0
-        self._Width = Width
+        self._Width  = Width
 
-    def AnimateDraw(self, x2, y2):
+    def AnimateDraw(self,x2,y2):
         pass
 
     def Draw(self):
         idx = self._Parent._PsIndex
-        if idx > (len(self._Parent._MyList) - 1):
+        if idx > (len(self._Parent._MyList)-1):
             idx = len(self._Parent._MyList)
             if idx > 0:
-                idx -= 1
-            elif idx == 0:  # Nothing
+                idx -=1
+            elif idx == 0: #Nothing
                 return
-
-        x = self._Parent._MyList[idx]._PosX + 2
-        y = self._Parent._MyList[idx]._PosY + 1
-        h = self._Parent._MyList[idx]._Height - 3
-
+        
+        x = self._Parent._MyList[idx]._PosX+2
+        y = self._Parent._MyList[idx]._PosY+1
+        h = self._Parent._MyList[idx]._Height -3
+        
         self._PosX = x
         self._PosY = y
         self._Height = h
 
-        aa_round_rect(self._Parent._CanvasHWND,
-                      (x, y, self._Width - 4, h), self._BackgroundColor, 4, 0, self._BackgroundColor)
+        aa_round_rect(self._Parent._CanvasHWND,  
+                    (x,y,self._Width-4,h),self._BackgroundColor,4,0,self._BackgroundColor)
+
 
 
 class ConfirmPage(Page):
+
     _Icons = {}
-    _Selector = None
-    _FootMsg = ["Nav", "", "", "Cancel", "Yes"]
+    _Selector=None
+    _FootMsg = ["Nav","","","Cancel","Yes"]
     _MyList = []
     _ListFont = fonts["veramono20"]
     _MyStack = None
-    _FileName = ""
-    _TrashDir = ""
+    _FileName     = ""
+    _TrashDir     = ""
     _ConfirmText = "Confirm?"
-    _BGPosX = 0
-    _BGPosY = 0
-    _BGWidth = 0
-    _BGHeight = 0
-    _Parent = None
-
+    _BGPosX      = 0
+    _BGPosY      = 0
+    _BGWidth     = 0
+    _BGHeight    = 0
+    _Parent      = None
+    
     def __init__(self):
         Page.__init__(self)
         self._Icons = {}
         self._CanvasHWND = None
         self._MyList = []
-
+        
     def Reset(self):
         self._MyList[0].SetText(self._ConfirmText)
-        self._MyList[0]._PosX = (self._Width - self._MyList[0]._Width) / 2
-        self._MyList[0]._PosY = (self._Height - self._MyList[0]._Height) / 2
-
-        self._BGPosX = self._MyList[0]._PosX - 10
-        self._BGPosY = self._MyList[0]._PosY - 10
-        self._BGWidth = self._MyList[0]._Width + 20
-        self._BGHeight = self._MyList[0]._Height + 20
-
-    def SnapMsg(self, msg):
+        self._MyList[0]._PosX = (self._Width - self._MyList[0]._Width)/2
+        self._MyList[0]._PosY = (self._Height - self._MyList[0]._Height)/2
+        
+        self._BGPosX = self._MyList[0]._PosX-10
+        self._BGPosY = self._MyList[0]._PosY-10
+        self._BGWidth = self._MyList[0]._Width+20
+        self._BGHeight = self._MyList[0]._Height+20
+
+        
+    def SnapMsg(self,msg):
         self._MyList[0].SetText(msg)
-        self._MyList[0]._PosX = (self._Width - self._MyList[0]._Width) / 2
-        self._MyList[0]._PosY = (self._Height - self._MyList[0]._Height) / 2
-
-        self._BGPosX = self._MyList[0]._PosX - 10
-        self._BGPosY = self._MyList[0]._PosY - 10
-        self._BGWidth = self._MyList[0]._Width + 20
-        self._BGHeight = self._MyList[0]._Height + 20
-
+        self._MyList[0]._PosX = (self._Width - self._MyList[0]._Width)/2
+        self._MyList[0]._PosY = (self._Height - self._MyList[0]._Height)/2
+
+        self._BGPosX = self._MyList[0]._PosX-10
+        self._BGPosY = self._MyList[0]._PosY-10
+        self._BGWidth = self._MyList[0]._Width+20
+        self._BGHeight = self._MyList[0]._Height+20
+        
     def Init(self):
         self._PosX = self._Index * self._Screen._Width
         self._Width = self._Screen._Width
@@ -99,34 +107,34 @@ class ConfirmPage(Page):
 
         li = Label()
         li.SetCanvasHWND(self._CanvasHWND)
-        li.Init(self._ConfirmText, self._ListFont)
-
-        li._PosX = (self._Width - li._Width) / 2
-        li._PosY = (self._Height - li._Height) / 2
-
-        self._BGPosX = li._PosX - 10
-        self._BGPosY = li._PosY - 10
-        self._BGWidth = li._Width + 20
-        self._BGHeight = li._Height + 20
-
+        li.Init(self._ConfirmText,self._ListFont)
+        
+        li._PosX = (self._Width - li._Width)/2
+        li._PosY = (self._Height - li._Height)/2
+
+        self._BGPosX = li._PosX-10
+        self._BGPosY = li._PosY-10
+        self._BGWidth = li._Width+20
+        self._BGHeight = li._Height+20
+        
         self._MyList.append(li)
-
-    def KeyDown(self, event):
-
-        if event.key == CurKeys["Menu"] or event.key == CurKeys["A"]:
+        
+    def KeyDown(self,event):
+        
+        if event.key == CurKeys["Menu"] or event.key == CurKeys["A"]:            
             self.ReturnToUpLevelPage()
             self._Screen.Draw()
             self._Screen.SwapAndShow()
-
+        
     def DrawBG(self):
-        _rect = pygame.Rect(self._BGPosX, self._BGPosY, self._BGWidth, self._BGHeight)
-
-        pygame.draw.rect(self._CanvasHWND, (255, 255, 255), _rect, 0)
-        pygame.draw.rect(self._CanvasHWND, (83, 83, 83), _rect, 1)
-
+        _rect = pygame.Rect(self._BGPosX,self._BGPosY,self._BGWidth,self._BGHeight)
+        
+        pygame.draw.rect(self._CanvasHWND,(255,255,255),_rect,0)
+        pygame.draw.rect(self._CanvasHWND,(83,83,83),_rect,1)
+        
     def Draw(self):
-        # self.ClearCanvas()
-
+        #self.ClearCanvas()
+        
         self.DrawBG()
         for i in self._MyList:
             i.Draw()

+ 28 - 14
sys.py/UI/constants.py

@@ -1,31 +1,45 @@
 # -*- coding: utf-8 -*- 
 
 import pygame
+from pygame.locals import *
+from sys import exit
+import os
+import sys
+
+from datetime import datetime
+
+import base64
+from beeprint import pp
+
 
 Width = 320
 Height = 240
-bg_color = pygame.Color(255, 255, 255)
+bg_color =  pygame.Color(255,255,255)
 
-icon_width = 80
+icon_width  = 80
 icon_height = 80
 icon_ext = ".sh"
 
-ICON_TYPES = {"Emulator": 7, "FILE": 6, "STAT": 5, "NAV": 4, "LETTER": 3, "FUNC": 2, "DIR": 1, "EXE": 0,
-              "None": -1}  # FUNC is like UI widget's function,DIR contains child page,EXE just execute a binary
 
-## H=horizontal, V=vertical, S=Single Line
-# SLeft start from left, single line
-# SCenter star from center, single line
-ALIGN = {"HLeft": 0, "HCenter": 1, "HRight": 2, "VMiddle": 3, "SLeft": 4, "VCenter": 5, "SCenter": 6}
+ICON_TYPES={"Emulator":7,"FILE":6,"STAT":5,"NAV":4,"LETTER":3,"FUNC":2,"DIR":1,"EXE":0,"None":-1} # FUNC is like UI widget's function,DIR contains child page,EXE just execute a binary
+
+## H=horizontal  ,V=vertical S=Single Line
+#SLeft start from left, single line
+#SCenter star from center ,single line
+ALIGN = {"HLeft":0,"HCenter":1,"HRight":2,"VMiddle":3,"SLeft":4,"VCenter":5,"SCenter":6}
 
-DT = pygame.time.Clock().tick(30)  # fps in ms,eg:50
+DT = pygame.time.Clock().tick(30)   # fps in ms,eg:50
 
-GMEVT = pygame.USEREVENT + 1
+
+GMEVT = pygame.USEREVENT+1
 update_titlebar_event = pygame.event.Event(GMEVT, message="titlebar")
 
-RUNEVT = pygame.USEREVENT + 2
-RUNSYS = pygame.USEREVENT + 3
+RUNEVT = pygame.USEREVENT+2
+RUNSYS = pygame.USEREVENT+3
+
+
+LOWLIGHT = pygame.USEREVENT+4 ## when dim screen backlight
+
+FOOTMSG = pygame.USEREVENT+5 ## when dim screen backlight
 
-LOWLIGHT = pygame.USEREVENT + 4  ## when dim screen backlight
 
-FOOTMSG = pygame.USEREVENT + 5  ## when dim screen backlight

+ 33 - 24
sys.py/UI/delete_confirm_page.py

@@ -1,39 +1,46 @@
 # -*- coding: utf-8 -*- 
 
+import pygame
 import os
 import shutil
 
-import pygame
-
-from .confirm_page import ConfirmPage
-# UI lib
-from .keys_def import CurKeys
 
+#UI lib
+from constants import Width,Height,ICON_TYPES
+from page   import Page,PageSelector
+from label  import Label
+from fonts  import fonts
+from util_funcs import midRect
+from keys_def   import CurKeys
+from confirm_page import ConfirmPage
 
 class DeleteConfirmPage(ConfirmPage):
-    _FileName = ""
-    _TrashDir = ""
-    _ConfirmText = "Confirm delete?"
 
-    def SetTrashDir(self, d):
+    _FileName     = ""
+    _TrashDir     = ""
+    _ConfirmText = "Confirm delete?"
+    
+    def SetTrashDir(self,d):
         self._TrashDir = d
-
+        
         if os.path.isdir(self._TrashDir) == False:
             raise IOError("Trash not existed")
-
-    def SetFileName(self, fn):
+        
+    def SetFileName(self,fn):
         self._FileName = fn
-
-    def KeyDown(self, event):
-
+        
+    def KeyDown(self,event):
+        
         if event.key == CurKeys["Menu"] or event.key == CurKeys["A"]:
+            
             self.ReturnToUpLevelPage()
             self._Screen.Draw()
             self._Screen.SwapAndShow()
-
+                
+        
         if event.key == CurKeys["B"]:
             try:
-                os.remove(self._TrashDir + "/" + os.path.basename(self._FileName))
+                os.remove(self._TrashDir+"/"+os.path.basename(self._FileName))
             except:
                 pass
 
@@ -41,24 +48,26 @@ class DeleteConfirmPage(ConfirmPage):
                 shutil.move(self._FileName, self._TrashDir)
             except shutil.Error as e:
                 if "already exists" in str(e):
-                    self._Screen._MsgBox.SetText("Already existed")
+                        self._Screen._MsgBox.SetText("Already existed")
                 else:
                     self._Screen._MsgBox.SetText("Error ")
-
+                
                 self._Screen._MsgBox.Draw()
                 self._Screen.SwapAndShow()
-            else:
-                # self._Screen._MsgBox.SetText("Deleteing..")
-                # self._Screen._MsgBox.Draw()
-                # self._Screen.SwapAndShow()
+            else:    
+                #self._Screen._MsgBox.SetText("Deleteing..")
+                #self._Screen._MsgBox.Draw()
+                #self._Screen.SwapAndShow()
                 self.SnapMsg("Deleteing....")
                 self._Screen.Draw()
                 self._Screen.SwapAndShow()
                 self.Reset()
-
+                
                 pygame.time.delay(300)
                 self.ReturnToUpLevelPage()
                 self._Screen.Draw()
                 self._Screen.SwapAndShow()
 
             print(self._FileName)
+
+    

+ 48 - 50
sys.py/UI/download.py

@@ -1,10 +1,11 @@
-# import urllib3
-import hashlib
 import os
 import pycurl
+import sys
 import time
-from threading import Thread
+import urllib2
+import hashlib
 
+from threading import Thread
 
 class Download(Thread):
     _dst_path = ""
@@ -21,11 +22,11 @@ class Download(Thread):
         self.useragent = useragent
         self.cookies = cookies
         self.downloaded = 0
-
-        self.progress = {'downloaded': 0, 'total': 0, 'percent': 0, 'stopped': False}
+        
+        self.progress = { 'downloaded': 0, 'total': 0, 'percent': 0,'stopped':False }
         self.stop = False
         self.filename = ""
-
+    
     def isFinished(self):
         return self._is_finished
 
@@ -39,7 +40,7 @@ class Download(Thread):
         return self._errors
 
     def run(self):
-
+        
         c = pycurl.Curl()
         c.setopt(pycurl.URL, self.url)
         c.setopt(pycurl.FOLLOWLOCATION, 1)
@@ -47,18 +48,18 @@ class Download(Thread):
         c.setopt(pycurl.NOBODY, 1)
 
         c.setopt(pycurl.CONNECTTIMEOUT, 10)
-
+        
         if self.useragent:
             c.setopt(pycurl.USERAGENT, self.useragent)
-
+        
         # add cookies, if available
         if self.cookies:
             c.setopt(pycurl.COOKIE, self.cookies)
         c.perform()
         realurl = c.getinfo(pycurl.EFFECTIVE_URL)
-
+        
         self.filename = realurl.split("/")[-1].strip()
-
+        
         c = pycurl.Curl()
         c.setopt(pycurl.CONNECTTIMEOUT, 10)
         c.setopt(pycurl.URL, realurl)
@@ -67,70 +68,70 @@ class Download(Thread):
         c.setopt(pycurl.XFERINFOFUNCTION, self.getProgress)
         if self.useragent:
             c.setopt(pycurl.USERAGENT, self.useragent)
-
+        
         # configure pycurl output file
         if self.path == False:
             self.path = os.getcwd()
         filepath = os.path.join(self.path, self.filename)
-
-        if os.path.exists(filepath):  ## remove old file,restart download
+            
+        if os.path.exists(filepath):## remove old file,restart download 
             os.system("rm -rf " + filepath)
             f = open(filepath, "wb")
         else:
             f = open(filepath, "wb")
-
+        
         c.setopt(pycurl.WRITEDATA, f)
-
+        
         self._dst_path = filepath
 
         # add cookies, if available
         if self.cookies:
             c.setopt(pycurl.COOKIE, self.cookies)
-
+    
         # download file
         try:
             c.perform()
-        except pycurl.error as error:
-            errno, errstr = error
+        except pycurl.error, error:
+            errno,errstr = error
             print("curl error: %s" % errstr)
             self._errors.append(errstr)
             self.stop = True
             self.progress["stopped"] = True
         finally:
 
-            code = c.getinfo(c.RESPONSE_CODE)
-            c.close()
+            code = c.getinfo( c.RESPONSE_CODE )
+            c.close()            
             self._is_finished = True
-
+        
             if self.progress["percent"] < 100:
                 self._is_successful = False
             else:
                 if self._HashFunc != None:
                     hashed = self.hashlib_hash(self._HashFunc, self._dst_path)
                     if hashed == self._HashValue:
-                        self._is_successful = True
+                        self._is_successful= True
                     else:
                         self._is_successful = False
                         self._errors.append("hash failed")
                 else:
                     if code != 200:
                         self._is_successful = False
-                        os.system("rm -rf " + self._dst_path)  ## clear garbage file
+                        os.system("rm -rf " + self._dst_path) ## clear garbage file
                         self._errors.append("response error %d " % code)
                     else:
-                        self._is_successful = True  ## 100% downloaded without hash check
-
-    def getProgress(self, download_t, download_d, upload_t, upload_d):
+                        self._is_successful = True ## 100% downloaded without hash check
+ 
+    def getProgress(self,download_t, download_d, upload_t, upload_d):
         if download_t and download_d:
             self.progress['downloaded'] = download_d + self.downloaded
-            self.progress['total'] = download_t + self.downloaded
-            self.progress['percent'] = (float(self.progress['downloaded']) / float(self.progress['total'])) * 100.0
-            self.progress["stopped"] = False
+            self.progress['total'] = download_t + self.downloaded 
+            self.progress['percent'] = ( float(self.progress['downloaded']) / float(self.progress['total'])) * 100.0
+            self.progress["stopped"] = False            
         if self.stop:
             self.progress["stopped"] = True
             return 1
-
-    def hashlib_hash(method, fname):  # eg: method == hashlib.md5(),function pointer
+    
+    def hashlib_hash(method,fname): #eg: method == hashlib.md5(),function pointer
         hash_ = method
         with open(fname, "rb") as f:
             for chunk in iter(lambda: f.read(4096), b""):
@@ -138,36 +139,35 @@ class Download(Thread):
 
         return hash_.hexdigest()
 
-    def add_hash_verification(self, method_name, method_value):
+    def add_hash_verification(self,method_name,method_value):
         if method_name == "md5":
             self._HashFunc = hashlib.md5()
         else:
             self._HashFunc = None
-
+ 
         self._HashValue = method_value
 
     def get_progress(self):
         return self.progress["percent"]
-
+    
     def stop(self):
         self.stop = True
-
+ 
     def cancel(self):
         # sets the boolean to stop the thread.
         self.stop = True
-
-
+        
 def main():
     from optparse import OptionParser
-
+    
     parser = OptionParser(usage="%prog [options] <url>")
-    parser.add_option("-p", "--path", default=False, dest="path", help="download file to PATH", metavar="PATH")
-    parser.add_option("-c", "--cookies", default=False, dest="cookies", help="specify cookie(s)", metavar="COOKIES")
+    parser.add_option(  "-p", "--path", default=False, dest="path", help="download file to PATH", metavar="PATH")
+    parser.add_option(  "-c", "--cookies", default=False, dest="cookies", help="specify cookie(s)", metavar="COOKIES")
     opts, args = parser.parse_args()
 
     if len(args) == 0:
         parser.error("No url supplied")
-
+    
     for url in args:
         print("Downloading: %s" % url)
         if opts.path:
@@ -182,18 +182,17 @@ def main():
         while 1:
             try:
                 progress = d.progress['percent']
-
+                
                 download_dx = d.progress["downloaded"] - last_downloaded
 
-                speed = float(download_dx) / (sleep_time * 1000.0)
-
+                speed = float(download_dx) / ( sleep_time * 1000.0)
+                
                 last_downloaded = d.progress["downloaded"]
-
+                
                 if d.progress["stopped"] == True:
                     break
 
-                print("%.2f percent | %d of %d | %.1f KB/s" % (
-                progress, d.progress['downloaded'], d.progress['total'], speed))
+                print("%.2f percent | %d of %d | %.1f KB/s" % (progress, d.progress['downloaded'], d.progress['total'], speed))
 
                 if progress == 100:
                     print("")
@@ -209,7 +208,6 @@ def main():
 
             except:
                 raise
-
-
+            
 if __name__ == "__main__":
     main()

+ 18 - 12
sys.py/UI/download_process_page.py

@@ -1,22 +1,28 @@
 # -*- coding: utf-8 -*- 
 import os
-
-# import gobject
 import pygame
+
+import gobject
 import validators
+
+
+from libs.roundrects import aa_round_rect
+
 ## local UI import
-from UI.constants import Width, Height, ICON_TYPES
-from UI.download import Download
-from UI.fonts import fonts
+from UI.constants import Width,Height,ICON_TYPES,RUNEVT
+from UI.page   import Page,PageSelector
+from UI.label  import Label
 from UI.icon_item import IconItem
-from UI.icon_pool import MyIconPool
-from UI.keys_def import CurKeys
-from UI.label import Label
-from UI.page import Page
-from UI.util_funcs import midRect
-from libs.DBUS import is_wifi_connected_now
-from libs.roundrects import aa_round_rect
+from UI.fonts  import fonts
+from UI.util_funcs import midRect,CmdClean,FileExists
+from UI.keys_def   import CurKeys
+from UI.multi_icon_item import MultiIconItem
+from UI.icon_pool  import MyIconPool
+from UI.download   import Download
+
+from libs.DBUS     import is_wifi_connected_now
 
+import config
 
 class DownloadProcessPage(Page):
     _FootMsg = ["Nav.","","","Back",""]

+ 52 - 44
sys.py/UI/fonts.py

@@ -1,56 +1,64 @@
 # -*- coding: utf-8 -*- 
 
 import pygame
+from pygame.locals import *
+from sys import exit
+import os
+import sys
+
+import config
 
 if not pygame.font.get_init():
     pygame.font.init()
 
-skinpath = "../skin/" + "default" + "/truetype"
+
+skinpath = "../skin/"+config.SKIN+"/truetype"
 fonts_path = {}
 
-fonts_path["varela"] = "%s/VarelaRound-Regular.ttf" % skinpath
+fonts_path["varela"]   = "%s/VarelaRound-Regular.ttf" % skinpath
 fonts_path["veramono"] = "%s/VeraMono.ttf" % skinpath
-fonts_path["noto"] = "%s/NotoSansMono-Regular.ttf" % skinpath
-fonts_path["notocjk"] = "%s/NotoSansCJK-Regular.ttf" % skinpath
+fonts_path["noto"]     = "%s/NotoSansMono-Regular.ttf" % skinpath
+fonts_path["notocjk"]     = "%s/NotoSansCJK-Regular.ttf" % skinpath
 
 fonts = {}
-fonts["varela12"] = pygame.font.Font(fonts_path["varela"], 12)
-fonts["varela13"] = pygame.font.Font(fonts_path["varela"], 13)
-fonts["varela14"] = pygame.font.Font(fonts_path["varela"], 14)
-fonts["varela15"] = pygame.font.Font(fonts_path["varela"], 15)
-
-fonts["varela16"] = pygame.font.Font(fonts_path["varela"], 16)
-fonts["varela18"] = pygame.font.Font(fonts_path["varela"], 18)
-fonts["varela20"] = pygame.font.Font(fonts_path["varela"], 20)
-fonts["varela22"] = pygame.font.Font(fonts_path["varela"], 22)
-fonts["varela23"] = pygame.font.Font(fonts_path["varela"], 23)
-fonts["varela24"] = pygame.font.Font(fonts_path["varela"], 24)
-fonts["varela25"] = pygame.font.Font(fonts_path["varela"], 25)
-fonts["varela26"] = pygame.font.Font(fonts_path["varela"], 26)
-fonts["varela27"] = pygame.font.Font(fonts_path["varela"], 27)
-fonts["varela28"] = pygame.font.Font(fonts_path["varela"], 28)
-fonts["varela34"] = pygame.font.Font(fonts_path["varela"], 34)
-fonts["varela40"] = pygame.font.Font(fonts_path["varela"], 40)
-
-fonts["veramono25"] = pygame.font.Font(fonts_path["veramono"], 25)
-fonts["veramono24"] = pygame.font.Font(fonts_path["veramono"], 24)
-fonts["veramono23"] = pygame.font.Font(fonts_path["veramono"], 23)
-fonts["veramono22"] = pygame.font.Font(fonts_path["veramono"], 22)
-fonts["veramono21"] = pygame.font.Font(fonts_path["veramono"], 21)
-fonts["veramono20"] = pygame.font.Font(fonts_path["veramono"], 20)
-fonts["veramono18"] = pygame.font.Font(fonts_path["veramono"], 18)
-fonts["veramono16"] = pygame.font.Font(fonts_path["veramono"], 16)
-fonts["veramono15"] = pygame.font.Font(fonts_path["veramono"], 15)
-fonts["veramono14"] = pygame.font.Font(fonts_path["veramono"], 14)
-fonts["veramono13"] = pygame.font.Font(fonts_path["veramono"], 13)
-fonts["veramono12"] = pygame.font.Font(fonts_path["veramono"], 12)
-fonts["veramono11"] = pygame.font.Font(fonts_path["veramono"], 11)
-fonts["veramono10"] = pygame.font.Font(fonts_path["veramono"], 10)
-
-for i in range(10, 18):
-    fonts["notosansmono" + str(i)] = pygame.font.Font(fonts_path["noto"], i)
-
-for i in range(10, 18):
-    fonts["notosanscjk" + str(i)] = pygame.font.Font(fonts_path["notocjk"], i)
-
-fonts["arial"] = pygame.font.SysFont("arial", 16)
+fonts["varela12"] = pygame.font.Font(fonts_path["varela"],12)
+fonts["varela13"] = pygame.font.Font(fonts_path["varela"],13)
+fonts["varela14"] = pygame.font.Font(fonts_path["varela"],14)
+fonts["varela15"] = pygame.font.Font(fonts_path["varela"],15)
+
+fonts["varela16"] = pygame.font.Font(fonts_path["varela"],16)
+fonts["varela18"] = pygame.font.Font(fonts_path["varela"],18)
+fonts["varela20"] = pygame.font.Font(fonts_path["varela"],20)
+fonts["varela22"] = pygame.font.Font(fonts_path["varela"],22)
+fonts["varela23"] = pygame.font.Font(fonts_path["varela"],23)
+fonts["varela24"] = pygame.font.Font(fonts_path["varela"],24)
+fonts["varela25"] = pygame.font.Font(fonts_path["varela"],25)
+fonts["varela26"] = pygame.font.Font(fonts_path["varela"],26)
+fonts["varela27"] = pygame.font.Font(fonts_path["varela"],27)
+fonts["varela28"] = pygame.font.Font(fonts_path["varela"],28)
+fonts["varela34"] = pygame.font.Font(fonts_path["varela"],34)
+fonts["varela40"] = pygame.font.Font(fonts_path["varela"],40)
+
+fonts["veramono25"] = pygame.font.Font(fonts_path["veramono"],25)
+fonts["veramono24"] = pygame.font.Font(fonts_path["veramono"],24)
+fonts["veramono23"] = pygame.font.Font(fonts_path["veramono"],23)
+fonts["veramono22"] = pygame.font.Font(fonts_path["veramono"],22)
+fonts["veramono21"] = pygame.font.Font(fonts_path["veramono"],21)
+fonts["veramono20"] = pygame.font.Font(fonts_path["veramono"],20)
+fonts["veramono18"] = pygame.font.Font(fonts_path["veramono"],18)
+fonts["veramono16"] = pygame.font.Font(fonts_path["veramono"],16)
+fonts["veramono15"] = pygame.font.Font(fonts_path["veramono"],15)
+fonts["veramono14"] = pygame.font.Font(fonts_path["veramono"],14)
+fonts["veramono13"] = pygame.font.Font(fonts_path["veramono"],13)
+fonts["veramono12"] = pygame.font.Font(fonts_path["veramono"],12)
+fonts["veramono11"] = pygame.font.Font(fonts_path["veramono"],11)
+fonts["veramono10"] = pygame.font.Font(fonts_path["veramono"],10)
+
+for i in range(10,18):
+    fonts["notosansmono"+str(i)] = pygame.font.Font(fonts_path["noto"],i)
+
+for i in range(10,18):
+    fonts["notosanscjk"+str(i)] = pygame.font.Font(fonts_path["notocjk"],i)
+    
+fonts["arial"] = pygame.font.SysFont("arial",16)
+

+ 89 - 87
sys.py/UI/foot_bar.py

@@ -1,113 +1,112 @@
 # -*- coding: utf-8 -*- 
 
+import pygame
 import os
 
-import pygame
 
-##local import
-from .constants import Width, Height, ICON_TYPES, ALIGN
-from .fonts import fonts
-from .icon_pool import MyIconPool
-from .multi_icon_item import MultiIconItem
-from .util_funcs import FileExists, midRect, SkinMap
+##local import 
+from constants  import Width,Height,ICON_TYPES,ALIGN
+from util_funcs import FileExists,midRect,SkinMap
+from icon_item  import IconItem
+from fonts      import fonts
+from multi_icon_item import MultiIconItem
+from icon_pool  import MyIconPool
+from libs.roundrects import aa_round_rect
 
 icon_base_path = SkinMap("gameshell/footbar_icons/")
 
-
-
 class FootBarIcon(MultiIconItem):
 
     def TotalWidth(self):
-        return self._Width + self._Label._Width
-
+        return self._Width+self._Label._Width
+    
     def Draw(self):
-        if self._Align == ALIGN["VCenter"]:  # default
+        if self._Align==ALIGN["VCenter"]: #default
             if self._Label != None:
-                self._Label._PosX = self._PosX - self._Label._Width / 2
-                self._Label._PosY = self._PosY + self._Height / 2 + 12
-
-        elif self._Align == ALIGN["HLeft"]:
+                self._Label._PosX = self._PosX - self._Label._Width/2
+                self._Label._PosY = self._PosY + self._Height/2 + 12
+                
+        elif self._Align ==ALIGN["HLeft"]:
             if self._Label != None:
-                self._Label._PosX = self._PosX + self._Width / 2 + 3
-                self._Label._PosY = self._PosY - self._Label._Height / 2
+                self._Label._PosX = self._PosX + self._Width/2 + 3
+                self._Label._PosY = self._PosY - self._Label._Height/2
 
-        if self._Label != None:
+        if self._Label!=None:
             self._Label.Draw()
-
+        
         if self._ImgSurf != None:
-            self._Parent._CanvasHWND.blit(self._ImgSurf, midRect(self._PosX,
-                                                                 self._PosY,
-                                                                 self._Width, self._Height, Width, Height),
-                                          (0, self._IconIndex * self._IconHeight, self._IconWidth, self._IconHeight))
-
-
+            self._Parent._CanvasHWND.blit(self._ImgSurf,midRect(self._PosX,
+                                                                self._PosY,
+                                                                self._Width,self._Height,Width,Height),
+                                          (0,self._IconIndex*self._IconHeight,self._IconWidth,self._IconHeight))
 class FootBar:
-    _PosX = 0
-    _PosY = 0
-    _Width = Width
-    _Height = 20
-    _BarHeight = 20.5
+    _PosX      = 0
+    _PosY      = 0
+    _Width     = Width
+    _Height    = 20
+    _BarHeight = 20.5 
     _BorderWidth = 1
     _CanvasHWND = None
-    _HWND = None
-    _Icons = {}
-    _IconWidth = 18
-    _IconHeight = 18
-    _LabelFont = fonts["veramono10"]
-    _State = "normal"
+    _HWND       = None
+    _Icons      = {}
+    _IconWidth   = 18
+    _IconHeight  = 18
+    _LabelFont   = fonts["veramono10"]
+    _State       = "normal"
     
     _SkinManager = None
-
+    
     def __init__(self):
         self._Icons = {}
 
-    def ReadFootBarIcons(self, icondir):
+
+    def ReadFootBarIcons(self,icondir):
         if FileExists(icondir) == False and os.path.isdir(icondir) == False:
             return
 
-        keynames = ["nav", "x", "y", "a", "b"]
-
-        share_surf = pygame.image.load(icon_base_path + "footbar.png").convert_alpha()
+        keynames = ["nav","x","y","a","b"]
 
+        share_surf = pygame.image.load(icon_base_path+"footbar.png").convert_alpha()
+        
         files = os.listdir(icondir)
-        for _i, i in enumerate(keynames):
+        for _i,i in enumerate( keynames):
             it = FootBarIcon()
             it._MyType = ICON_TYPES["NAV"]
             it._Parent = self
-            it._ImgSurf = share_surf
-            it._Align = ALIGN["HLeft"]  # (x)text <=
+            it._ImgSurf= share_surf
+            it._Align = ALIGN["HLeft"] # (x)text <= 
 
-            it.AddLabel("game", self._LabelFont)
-            it.Adjust(self._IconWidth / 2 + _i * self._IconWidth, self._IconHeight / 2 + 2, self._IconWidth,
-                      self._IconHeight, 0)
+            it.AddLabel("game",self._LabelFont)
+            it.Adjust(self._IconWidth/2+_i*self._IconWidth, self._IconHeight/2+2, self._IconWidth, self._IconHeight,0)
             it._IconIndex = _i
             self._Icons[i] = it
 
-    def Init(self, screen):
-        self._HWND = screen
-        self._CanvasHWND = pygame.Surface((Width, int(self._BarHeight)))
+        
+    def Init(self,screen):
+        self._HWND       = screen
+        self._CanvasHWND = pygame.Surface((Width,int(self._BarHeight)))
 
         self.ReadFootBarIcons(icon_base_path)
 
-        round_corners = MultiIconItem()
+        round_corners   =  MultiIconItem()
         round_corners._IconWidth = 10
         round_corners._IconHeight = 10
-
+        
         round_corners._MyType = ICON_TYPES["STAT"]
         round_corners._Parent = self
         round_corners._ImgSurf = MyIconPool._Icons["roundcorners"]
-        round_corners.Adjust(0, 0, 10, 10, 0)
+        round_corners.Adjust(0,0,10,10,0)
 
         self._Icons["round_corners"] = round_corners
-
+        
     def ResetNavText(self):
         self._Icons["nav"]._Label.SetText("Nav.")
         self._State = "normal"
         self.Draw()
-
-    def UpdateNavText(self, texts):
+        
+    def UpdateNavText(self,texts):
         self._State = "tips"
-        my_text = self._LabelFont.render(texts, True, self._SkinManager.GiveColor("Text"))
+        my_text = self._LabelFont.render(texts,True,self._SkinManager.GiveColor("Text"))
         """
         _w = 0
         for i, x in enumerate(("b","a","y","x")):
@@ -117,67 +116,70 @@ class FootBar:
                 else:
                     _w += self._Icons[x].TotalWidth()+5
         """
-        left_width = self._Width - 18
+        left_width = self._Width  - 18
 
         final_piece = ""
-        for i, v in enumerate(texts):
-            text_slice = texts[:i + 1]
-            my_text = self._LabelFont.render(text_slice, True, self._SkinManager.GiveColor("Text"))
+        for i ,v in enumerate(texts):
+            text_slice = texts[:i+1]
+            my_text = self._LabelFont.render(text_slice,True, self._SkinManager.GiveColor("Text"))
             final_piece = text_slice
             if my_text.get_width() >= left_width:
                 break
-
-        print("finalpiece %s" % final_piece)
-        self._Icons["nav"]._Label.SetText(final_piece)
+            
+        print("finalpiece %s" %final_piece)
+        self._Icons["nav"]._Label.SetText( final_piece )
 
         self.Draw()
-
-    def SetLabelTexts(self, texts):
-        for idx, x in enumerate(("nav", "x", "y", "a", "b")):
+        
+    def SetLabelTexts(self,texts):
+        for idx,x in enumerate(("nav","x","y","a","b")):
             try:
                 self._Icons[x]._Label.SetText(texts[idx])
             except IndexError:
-                print("Index " + x + " doesn't exist!")
+                print("Index "+x+" doesn't exist!")
 
+    
     def ClearCanvas(self):
-        self._CanvasHWND.fill(self._SkinManager.GiveColor("White"))
-
-        self._Icons["round_corners"].NewCoord(5, self._Height - 5)
+        self._CanvasHWND.fill( self._SkinManager.GiveColor("White") )
+        
+        self._Icons["round_corners"].NewCoord(5,self._Height -5 )
         self._Icons["round_corners"]._IconIndex = 2
         self._Icons["round_corners"].Draw()
 
-        self._Icons["round_corners"].NewCoord(self._Width - 5, self._Height - 5)
+        self._Icons["round_corners"].NewCoord(self._Width-5,self._Height-5)
         self._Icons["round_corners"]._IconIndex = 3
         self._Icons["round_corners"].Draw()
 
+        
         """
         aa_round_rect(self._CanvasHWND,  
                     (0,0,self._Width,self._Height),self._BgColor,8,0, self._BgColor)
 
         pygame.draw.rect(self._CanvasHWND,self._BgColor,(0,0,Width,self._BarHeight/2), 0 )
         """
-
+        
     def Draw(self):
         self.ClearCanvas()
-        self._Icons["nav"].NewCoord(self._IconWidth / 2 + 3, self._IconHeight / 2 + 2)
+        self._Icons["nav"].NewCoord(self._IconWidth/2+3,self._IconHeight/2+2)
         self._Icons["nav"].Draw()
 
         if self._State == "normal":
-            _w = 0
-            # for i,x in enumerate(("a","b","x","y")):
-            for i, x in enumerate(("b", "a", "y", "x")):
-                if self._Icons[x]._Label._Text != "":
-                    if i == 0:
+            _w=0
+            #for i,x in enumerate(("a","b","x","y")):
+            for i, x in enumerate(("b","a","y","x")):
+                if self._Icons[x]._Label._Text!="":
+                    if i==0:
                         _w += self._Icons[x].TotalWidth()
                     else:
-                        _w += self._Icons[x].TotalWidth() + 5
-
+                        _w += self._Icons[x].TotalWidth()+5
+                    
                     start_x = self._Width - _w
-                    start_y = self._IconHeight / 2 + 2
-                    self._Icons[x].NewCoord(start_x, start_y)
+                    start_y = self._IconHeight/2+2
+                    self._Icons[x].NewCoord(start_x,start_y)
                     self._Icons[x].Draw()
 
-        pygame.draw.line(self._CanvasHWND, self._SkinManager.GiveColor("Line"), (0, 0), (Width, 0), self._BorderWidth)
 
-        if self._HWND != None:
-            self._HWND.blit(self._CanvasHWND, (self._PosX, Height - self._Height, Width, self._BarHeight))
+        pygame.draw.line(self._CanvasHWND,self._SkinManager.GiveColor("Line"),(0,0),(Width,0),self._BorderWidth)
+
+        if self._HWND  != None:
+            self._HWND.blit(self._CanvasHWND,(self._PosX,Height - self._Height,Width,self._BarHeight))

+ 49 - 49
sys.py/UI/icon_item.py

@@ -3,70 +3,70 @@
 import pygame
 
 ## local import
-from .constants import icon_width, icon_height, ICON_TYPES, ALIGN, Width, Height
-from .label import Label
-from .util_funcs import color_surface, midRect
-
+from constants  import icon_width,icon_height,ICON_TYPES,ALIGN,icon_ext,Width,Height
+from util_funcs import color_surface,midRect
+from label      import Label
 
 class IconItem:
-    _PosX = 0
-    _PosY = 0
-    _Width = 0
-    _Height = 0
-    _ImageName = ""
+    _PosX=0
+    _PosY=0
+    _Width=0
+    _Height=0
+    _ImageName=""
     _ImgSurf = None
     _Parent = None
-    _Index = 0
+    _Index  = 0
     _MyType = ICON_TYPES["EXE"]
     _CmdPath = ""
     _LinkPage = None
-    _Label = None
-    _Align = ALIGN["VCenter"]  # set for the Icon Image and Text Label
-
+    _Label   = None
+    _Align   = ALIGN["VCenter"] # set for the Icon Image and Text Label
+    
     def __init__(self):
-        self._ImgSurf = None
+        self._ImgSurf=None
+        
 
-    def Init(self, x, y, w, h, at):  # the Surface is assigned in Screen
+    def Init(self,x,y,w,h,at): # the Surface is assigned in Screen 
         self._PosX = x
         self._PosY = y
         self._Width = w
         self._Height = h
         self._AnimationTime = at
 
-    def SetLableColor(self, color):
+    def SetLableColor(self,color):
         self._Label.SetColor(color)
-
-    def NewCoord(self, x, y):
+        
+    def NewCoord(self,x,y):
         self._PosX = x
         self._PosY = y
 
-    def AddLabel(self, text, fontobj):
+    def AddLabel(self,text,fontobj):
         if self._Label == None:
             self._Label = Label()
-            self._Label.Init(text, fontobj)
+            self._Label.Init(text,fontobj)
         else:
-            # just replace the text
-            self._Label.Init(text, fontobj)
+            #just replace the text
+            self._Label._Init(text,fontobj)
 
-    def Adjust(self, x, y, w, h, at):  # the Surface is assigned in Screen
-        self.Init(x, y, w, h, at)
+    def Adjust(self,x,y,w,h,at): # the Surface is assigned in Screen 
+        self.Init(x,y,w,h,at)
 
         if self._Label != None:
-            self._Label.SetCanvasHWND(self._Parent._CanvasHWND)
+            self._Label.SetCanvasHWND( self._Parent._CanvasHWND)
 
         self.CreateImageSurf()
         self.AdjustLinkPage()
 
     def AdjustLinkPage(self):
-        if self._MyType == ICON_TYPES["DIR"] and self._LinkPage != None:
+        if self._MyType==ICON_TYPES["DIR"] and self._LinkPage != None:
             self._LinkPage._Index = 0
             self._LinkPage._Align = ALIGN["SLeft"]
             self._LinkPage._IconNumbers = len(self._LinkPage._Icons)
             self._LinkPage._Screen = self._Parent._Screen
-            self._LinkPage._CanvasHWND = self._Parent._Screen._CanvasHWND
-
-            self._LinkPage._FootMsg = ["Nav.", "", "", "Back", "Enter"]  ## Default Page Foot info
-
+            self._LinkPage._CanvasHWND       = self._Parent._Screen._CanvasHWND
+            
+            self._LinkPage._FootMsg =  ["Nav.","","","Back","Enter"] ## Default Page Foot info
+            
             if self._LinkPage._Align == ALIGN["HLeft"]:
                 self._LinkPage.AdjustHLeftAlign()
             elif self._LinkPage._Align == ALIGN["SLeft"]:
@@ -76,34 +76,34 @@ class IconItem:
                     self._LinkPage._IconIndex = self._LinkPage._PsIndex
 
     def CreateImageSurf(self):
-
+        
         if self._ImgSurf == None and self._ImageName != "":
-            #            print(self._ImageName)
-            self._ImgSurf = pygame.image.load(self._ImageName).convert_alpha()
+#            print(self._ImageName)
+            self._ImgSurf = pygame.image.load( self._ImageName ).convert_alpha() 
             if self._ImgSurf.get_width() > icon_width or self._ImgSurf.get_height() > icon_height:
-                self._ImgSurf = pygame.transform.scale(self._ImgSurf, (icon_width, icon_height))
-
-    def ChangeImgSurfColor(self, color):
-        color_surface(self._ImgSurf, color)
+                self._ImgSurf = pygame.transform.scale(self._ImgSurf,(icon_width,icon_height))
+   
+    def ChangeImgSurfColor(self,color):
+        color_surface(self._ImgSurf,color)
 
     def Clear(self):
         pass
 
     def Draw(self):
-        if self._Align == ALIGN["VCenter"]:  # default
+        if self._Align==ALIGN["VCenter"]: #default
             if self._Label != None:
-                self._Label._PosX = self._PosX - self._Label._Width / 2 + self._Parent._PosX
-                self._Label._PosY = self._PosY + self._Height / 2 + 6 + self._Parent._PosY
-
-        elif self._Align == ALIGN["HLeft"]:
+                self._Label._PosX = self._PosX - self._Label._Width/2 + self._Parent._PosX
+                self._Label._PosY = self._PosY + self._Height/2 +6  + self._Parent._PosY
+                
+        elif self._Align ==ALIGN["HLeft"]:
             if self._Label != None:
-                self._Label._PosX = self._PosX + self._Width / 2 + 3 + self._Parent._PosX
-                self._Label._PosY = self._PosY - self._Label._Height / 2 + self._Parent._PosY
+                self._Label._PosX = self._PosX + self._Width/2 + 3 + self._Parent._PosX
+                self._Label._PosY = self._PosY - self._Label._Height/2 + self._Parent._PosY
 
-        if self._Label != None:
+        if self._Label!=None:
             self._Label.Draw()
-
+        
         if self._ImgSurf != None:
-            self._Parent._CanvasHWND.blit(self._ImgSurf, midRect(self._PosX + self._Parent._PosX,
-                                                                 self._PosY + self._Parent._PosY,
-                                                                 self._Width, self._Height, Width, Height))
+            self._Parent._CanvasHWND.blit(self._ImgSurf,midRect(self._PosX+self._Parent._PosX,
+                                       self._PosY+self._Parent._PosY,
+                                       self._Width,self._Height,Width,Height))

+ 12 - 11
sys.py/UI/icon_pool.py

@@ -1,28 +1,29 @@
 # -*- coding: utf-8 -*- 
 
-import os
-
 import pygame
+from pygame.locals import *
+from sys import exit
+import os
+import sys
 
-from .util_funcs import SkinMap
-
-
+from util_funcs  import SkinMap
 ##pool only store surfaces
 
 class IconPool(object):
+
     _GameShellIconPath = SkinMap("gameshell/icons/")
     _Icons = {}
-
     def __init__(self):
-        self._Icons = {}
+        self._Icons= {}
 
     def Init(self):
-
+        
         files = os.listdir(self._GameShellIconPath)
         for i in files:
-            if os.path.isfile(self._GameShellIconPath + "/" + i) and i.endswith(".png"):
+            if os.path.isfile(self._GameShellIconPath+"/"+i) and i.endswith(".png"):
                 keyname = i.split(".")[0]
-                self._Icons[keyname] = pygame.image.load(self._GameShellIconPath + "/" + i).convert_alpha()
-
+                self._Icons[keyname] = pygame.image.load(self._GameShellIconPath+"/"+i).convert_alpha()
+                
 
 MyIconPool = IconPool()
+

+ 39 - 18
sys.py/UI/keys_def.py

@@ -1,37 +1,58 @@
 # -*- coding: utf-8 -*- 
+
 import pygame
+from pygame.locals import *
+from sys import exit
+import os
+import sys
+
+
+from config import CurKeySet
 
 GameShell = {}
-GameShell["Up"] = pygame.K_UP
+"""
+GameShell["Up"]   = pygame.K_w
+GameShell["Down"] = pygame.K_s
+GameShell["Left"] = pygame.K_a
+GameShell["Right"]= pygame.K_d
+"""
+GameShell["Up"]   = pygame.K_UP
 GameShell["Down"] = pygame.K_DOWN
 GameShell["Left"] = pygame.K_LEFT
-GameShell["Right"] = pygame.K_RIGHT
+GameShell["Right"]= pygame.K_RIGHT
+
 GameShell["Menu"] = pygame.K_ESCAPE
-GameShell["X"] = pygame.K_u
-GameShell["Y"] = pygame.K_i
-GameShell["A"] = pygame.K_j
-GameShell["B"] = pygame.K_k
+GameShell["X"]    = pygame.K_u
+GameShell["Y"]    = pygame.K_i
+GameShell["A"]    = pygame.K_j
+GameShell["B"]    = pygame.K_k
+
 GameShell["Vol-"] = pygame.K_SPACE
 GameShell["Vol+"] = pygame.K_RETURN
 GameShell["Space"] = pygame.K_SPACE
+
 GameShell["Enter"] = pygame.K_k
 GameShell["Start"] = pygame.K_RETURN
 
+
 PC = {}
-PC["Up"] = pygame.K_UP
-PC["Down"] = pygame.K_DOWN
-PC["Left"] = pygame.K_LEFT
+
+PC["Up"]    = pygame.K_UP
+PC["Down"]  = pygame.K_DOWN
+PC["Left"]  = pygame.K_LEFT
 PC["Right"] = pygame.K_RIGHT
-PC["Menu"] = pygame.K_ESCAPE
-PC["X"] = pygame.K_x
-PC["Y"] = pygame.K_y
-PC["A"] = pygame.K_a
-PC["B"] = pygame.K_b
-PC["Vol-"] = pygame.K_SPACE
-PC["Vol+"] = pygame.K_RETURN
+PC["Menu"]  = pygame.K_ESCAPE
+PC["X"]     = pygame.K_x
+PC["Y"]     = pygame.K_y
+PC["A"]     = pygame.K_a
+PC["B"]     = pygame.K_b
+PC["Vol-"]  = pygame.K_SPACE
+PC["Vol+"]  = pygame.K_RETURN
 PC["Enter"] = pygame.K_RETURN
 PC["Space"] = pygame.K_SPACE
 PC["Start"] = pygame.K_s
 
-
-CurKeys = PC
+if CurKeySet == "PC":
+    CurKeys = PC
+else:
+    CurKeys = GameShell

+ 57 - 0
sys.py/UI/label.py

@@ -0,0 +1,57 @@
+# -*- coding: utf-8 -*- 
+
+import pygame
+
+#import base64
+#from beeprint import pp
+
+class Label:
+    _PosX=0
+    _PosY=0
+    _Width=0
+    _Height=0
+    _Text=""
+    _FontObj=None
+    _Color = pygame.Color(83,83,83)
+    _CanvasHWND = None
+    _TextSurf = None
+    def __init__(self):
+        pass
+    
+    def Init(self,text,font_obj,color=pygame.Color(83,83,83)):
+        self._Color = color
+        self._FontObj = font_obj
+        self._Text = text
+
+        my_text = self._FontObj.render(self._Text,True,self._Color)
+        self._Width = my_text.get_width()
+        self._Height = my_text.get_height()
+
+    def NewCoord(self,x,y):
+        self._PosX = x
+        self._PosY = y
+        
+    def SetColor(self,color):
+        self._Color = color
+    
+    def GetText(self):
+        return self._Text
+    
+    def SetText(self,text):
+        self._Text = text
+        
+        my_text = self._FontObj.render(self._Text,True,self._Color)
+        self._Width = my_text.get_width()
+        self._Height = my_text.get_height()
+
+    def Width(self):
+        return self._Width
+    
+    def SetCanvasHWND(self,_canvashwnd):
+        self._CanvasHWND = _canvashwnd
+
+    def Draw(self):
+        self._FontObj.set_bold(False) ## avoing same font tangling set_bold to others
+        my_text = self._FontObj.render( self._Text,True,self._Color)
+        
+        self._CanvasHWND.blit(my_text,(self._PosX,self._PosY,self._Width,self._Height))

+ 205 - 194
sys.py/UI/main_screen.py

@@ -1,51 +1,60 @@
 # -*- coding: utf-8 -*- 
 
+import pygame
+from pygame.locals import *
+from sys import exit
 import os
 import sys
 
-import pygame
 from libs import easing
-
-from .Emulator import MyEmulator
-from .constants import ICON_TYPES, icon_ext, RUNEVT
-from .constants import Width, Height
-from .fonts import fonts
-from .foot_bar import FootBar
-from .icon_item import IconItem
-from .keys_def import CurKeys
-from .label import Label
-from .page import Page, PageStack
-from .skin_manager import SkinManager
-from .title_bar import TitleBar
-from .untitled_icon import UntitledIcon
-from .util_funcs import midRect, FileExists, ReplaceSuffix, CmdClean, MakeExecutable, SkinMap
-
+from datetime import datetime
+
+from beeprint import pp
+
+## local package import
+from constants   import ICON_TYPES,icon_ext,icon_width,icon_height,RUNEVT
+from icon_item   import IconItem
+from page        import Page,PageStack
+from title_bar   import TitleBar
+from foot_bar    import FootBar
+from constants   import Width,Height,bg_color
+from util_funcs  import midRect,FileExists,ReplaceSuffix,ReadTheFileContent,CmdClean,MakeExecutable,SkinMap
+from fonts       import fonts
+from keys_def    import CurKeys
+from label       import Label
+from untitled_icon import UntitledIcon
+from Emulator    import MyEmulator
+
+from skin_manager import SkinManager
 
 class MessageBox(Label):
     _Parent = None
-
-    def Init(self, text, font_obj, color=pygame.Color(83, 83, 83)):
+    
+    def __init__(self):
+        pass
+    
+    def Init(self,text,font_obj,color=pygame.Color(83,83,83)):
         self._Color = color
         self._FontObj = font_obj
         self._Text = text
 
         self._Width = 0
         self._Height = 0
-        self._CanvasHWND = pygame.Surface((int(self._Parent._Width), int(self._Parent._Height)))
-        self._HWND = self._Parent._CanvasHWND
+        self._CanvasHWND = pygame.Surface( ( int(self._Parent._Width),int(self._Parent._Height)))
+        self._HWND       = self._Parent._CanvasHWND
 
-    def SetText(self, text):
+    def SetText(self,text):
         self._Text = text
-
+        
     def Draw(self):
         self._Width = 0
         self._Height = 0
-        self._CanvasHWND.fill((255, 255, 255))
-
+        self._CanvasHWND.fill( (255,255,255))
+        
         words = self._Text.split(' ')
         space = self._FontObj.size(' ')[0]
-        max_width = self._Parent._Width - 40
-        x, y = (0, 0)
+        max_width = self._Parent._Width-40
+        x ,y = (0,0)
         row_total_width = 0
         lines = 0
 
@@ -56,110 +65,108 @@ class MessageBox(Label):
             row_total_width += word_width
             if lines == 0:
                 lines += word_height
-            if row_total_width + space >= max_width:
+            if row_total_width+space  >= max_width:
                 x = 0  # Reset the x.
                 y += word_height  # Start on new row.
                 row_total_width = word_width
-
+                
                 lines += word_height
-
+                
             self._CanvasHWND.blit(word_surface, (x, y))
-
-            if len(words) == 1:  # single line
+            
+            if len(words) == 1: # single line 
                 x += word_width
             else:
                 x += word_width + space
-
+            
             if x > self._Width:
                 self._Width = x
 
             if lines >= (self._Parent._Height - 40):
                 break
-
+        
         self._Height = lines
-
+        
         padding = 5
-        x = (self._Parent._Width - self._Width) / 2
-        y = (self._Parent._Height - self._Height) / 2
-        # print("x %d y %d w %d h %d" %(x,y,self._Width,self._Height ))
-
-        pygame.draw.rect(self._HWND, (255, 255, 255),
-                         (x - padding, y - padding, self._Width + padding * 2, self._Height + padding * 2))
-
+        x = (self._Parent._Width - self._Width)/2
+        y = (self._Parent._Height - self._Height)/2
+       # print("x %d y %d w %d h %d" %(x,y,self._Width,self._Height ))
+        
+        pygame.draw.rect(self._HWND,(255,255,255),(x-padding,y-padding, self._Width+padding*2,self._Height+padding*2))        
+    
         if self._HWND != None:
-            rect = midRect(self._Parent._Width / 2, self._Parent._Height / 2, self._Width, self._Height, Width, Height)
-            self._HWND.blit(self._CanvasHWND, rect, (0, 0, self._Width, self._Height))
-            # self._HWND.blit(self._CanvasHWND,rect)
-
-        pygame.draw.rect(self._HWND, (0, 0, 0),
-                         (x - padding, y - padding, self._Width + padding * 2, self._Height + padding * 2), 1)
-
+            rect = midRect(self._Parent._Width/2,self._Parent._Height/2,self._Width,self._Height,Width,Height)
+            self._HWND.blit(self._CanvasHWND,rect,(0,0,self._Width,self._Height))
+            #self._HWND.blit(self._CanvasHWND,rect)
+            
+        pygame.draw.rect(self._HWND,(0,0,0),(x-padding,y-padding, self._Width+padding*2,self._Height+padding*2),1)
+            
 
 python_package_flag = "__init__.py"
-emulator_flag = "action.config"
+emulator_flag       = "action.config"
 
-
-# Abstract object for manage Pages ,not the pygame's physic screen
+##Abstract object for manage Pages ,not the pygame's physic screen
 class MainScreen(object):
     _Pages = []
     _PageMax = 0
     _PageIndex = 0
-    _PosX = 0
-    _PosY = TitleBar._BarHeight + 1
-    _Width = Width
-    _Height = Height - FootBar._BarHeight - TitleBar._BarHeight - 1
+    _PosX  = 0
+    _PosY  = TitleBar._BarHeight+1
+    _Width = Width 
+    _Height = Height -FootBar._BarHeight -TitleBar._BarHeight-1
     _MyPageStack = None
-    _CurrentPage = None  # pointer to the current displaying Page Class
-    _CanvasHWND = None
-    _HWND = None
-    _TitleBar = None
-    _FootBar = None
-    _MsgBox = None
-    _MsgBoxFont = fonts["veramono20"]
-    _IconFont = fonts["varela15"]
+    _CurrentPage = None # pointer to the current displaying Page Class
+    _CanvasHWND  = None
+    _HWND        = None
+    _TitleBar    = None
+    _FootBar     = None
+    _MsgBox      = None
+    _MsgBoxFont  = fonts["veramono20"]
+    _IconFont    = fonts["varela15"]
     _SkinManager = None
-
+    
     def __init__(self):
         self._Pages = []
         self._MyPageStack = PageStack()
 
     def Init(self):
-        self._CanvasHWND = pygame.Surface((self._Width, self._Height))
-        self._MsgBox = MessageBox()
-        self._MsgBox._Parent = self
+        self._CanvasHWND = pygame.Surface((self._Width,self._Height))
+        self._MsgBox= MessageBox()
+        self._MsgBox._Parent= self
         self._MsgBox.Init(" ", self._MsgBoxFont)
 
         self._SkinManager = SkinManager()
         self._SkinManager.Init()
-
+        
     def FartherPages(self):
         self._PageMax = len(self._Pages)
-        for i in range(0, self._PageMax):
+        for i in range(0,self._PageMax):
             self._Pages[i]._Index = i
             self._Pages[i]._CanvasHWND = self._CanvasHWND
             self._Pages[i]._IconNumbers = len(self._Pages[i]._Icons)
             self._Pages[i]._Screen = self
             self._Pages[i].Adjust()
-
+            
             if self._Pages[i]._IconNumbers > 1:
                 self._Pages[i]._PsIndex = 1
                 self._Pages[i]._IconIndex = self._Pages[i]._PsIndex
-
+            
+                
         self._CurrentPage = self._Pages[self._PageIndex]
         self._CurrentPage._OnShow = True
 
     def GetMyRightSidePage(self):
-        ret = self._PageIndex + 1
-        if ret > (self._PageMax - 1):
-            ret = self._PageMax - 1
+        ret = self._PageIndex +1
+        if ret > (self._PageMax -1):
+            ret = self._PageMax -1
         return ret
-
+    
     def PageMoveLeft(self):
         self._Pages[self._PageIndex]._OnShow = False
         if self._PageIndex < (self._PageMax - 1):
-            my_right_side_page = self.GetMyRightSidePage()
-            for i in range(0, self._PageMax):
-                if i != self._PageIndex and i != my_right_side_page:
+            my_right_side_page  = self.GetMyRightSidePage()
+            for i in range(0,self._PageMax):
+                if i!= self._PageIndex and i != my_right_side_page:
                     self._Pages[i].MoveLeft(Width)
 
             self._Pages[self._PageIndex].EasingLeft(Width)
@@ -168,16 +175,16 @@ class MainScreen(object):
                 self._Pages[my_right_side_page].EasingLeft(Width)
 
             self._Pages[self._PageIndex].ResetPageSelector()
-
-        self._PageIndex += 1
-        if self._PageIndex > (self._PageMax - 1):
-            self._PageIndex = (self._PageMax - 1)
+            
+        self._PageIndex+=1
+        if self._PageIndex > (self._PageMax -1):
+            self._PageIndex = (self._PageMax -1)
 
         self._Pages[self._PageIndex]._OnShow = True
         self._CurrentPage = self._Pages[self._PageIndex]
 
     def GetMyLeftSidePage(self):
-        ret = self._PageIndex - 1
+        ret = self._PageIndex -1
         if ret < 0:
             ret = 0
         return ret
@@ -186,10 +193,10 @@ class MainScreen(object):
         self._Pages[self._PageIndex]._OnShow = False
         if self._PageIndex > 0:
             my_left_side_page = self.GetMyLeftSidePage()
-            for i in range(0, self._PageMax):
-                if i != self._PageIndex and i != my_left_side_page:
+            for i in range(0,self._PageMax):
+                if i!= self._PageIndex and i!= my_left_side_page:
                     pass
-                # self._Pages[i].MoveRight(Width)
+                #self._Pages[i].MoveRight(Width)
 
             self._Pages[self._PageIndex].EasingRight(Width)
 
@@ -198,41 +205,42 @@ class MainScreen(object):
 
             self._Pages[self._PageIndex].ResetPageSelector()
 
-        self._PageIndex -= 1
+        self._PageIndex-=1
         if self._PageIndex < 0:
             self._PageIndex = 0
 
         self._Pages[self._PageIndex]._OnShow = True
         self._CurrentPage = self._Pages[self._PageIndex]
 
+
     def EasingAllPageLeft(self):
         current_time = 0.0
         start_posx = 0.0
         current_posx = start_posx
-        final_posx = float(Width)
-        posx_init = 0
-        dur = 30
-        last_posx = 0.0
+        final_posx   = float(Width)
+        posx_init    = 0
+        dur          = 30
+        last_posx    = 0.0
         all_last_posx = []
         if self._PageIndex >= (self._PageMax - 1):
             return
-        for i in range(0, Width * dur):
-            current_posx = easing.SineIn(current_time, start_posx, final_posx - start_posx, float(dur))
+        for i in range(0,Width*dur):
+            current_posx = easing.SineIn(current_time,start_posx,final_posx-start_posx,float(dur))
             if current_posx >= final_posx:
                 current_posx = final_posx
 
-            dx = current_posx - last_posx
+            dx  = current_posx - last_posx
             all_last_posx.append(int(dx))
-            current_time += 1
+            current_time+=1
             last_posx = current_posx
             if current_posx >= final_posx:
                 break
 
         c = 0
         for i in all_last_posx:
-            c += i
+            c+=i
         if c < final_posx - start_posx:
-            all_last_posx.append(final_posx - c)
+            all_last_posx.append( final_posx - c )
 
         for i in all_last_posx:
             self.ClearCanvas()
@@ -240,44 +248,45 @@ class MainScreen(object):
                 j._PosX -= i
                 j.DrawIcons()
                 j._Screen.SwapAndShow()
-
+                
+        
         self._Pages[self._PageIndex]._OnShow = False
 
-        self._PageIndex += 1
-        if self._PageIndex > (self._PageMax - 1):
-            self._PageIndex = (self._PageMax - 1)
+        self._PageIndex+=1
+        if self._PageIndex > (self._PageMax -1):
+            self._PageIndex = (self._PageMax -1)
 
         self._Pages[self._PageIndex]._OnShow = True
         self._CurrentPage = self._Pages[self._PageIndex]
-
+        
     def EasingAllPageRight(self):
         current_time = 0.0
         start_posx = 0.0
         current_posx = start_posx
-        final_posx = float(Width)
-        posx_init = 0
-        dur = 30
-        last_posx = 0.0
+        final_posx   = float(Width)
+        posx_init    = 0
+        dur          = 30
+        last_posx    = 0.0
         all_last_posx = []
         if self._PageIndex <= 0:
             return
-        for i in range(0, Width * dur):
-            current_posx = easing.SineIn(current_time, start_posx, final_posx - start_posx, float(dur))
+        for i in range(0,Width*dur):
+            current_posx = easing.SineIn(current_time,start_posx,final_posx-start_posx,float(dur))
             if current_posx >= final_posx:
                 current_posx = final_posx
 
-            dx = current_posx - last_posx
+            dx  = current_posx - last_posx
             all_last_posx.append(int(dx))
-            current_time += 1
+            current_time+=1
             last_posx = current_posx
             if current_posx >= final_posx:
                 break
 
         c = 0
         for i in all_last_posx:
-            c += i
+            c+=i
         if c < final_posx - start_posx:
-            all_last_posx.append(final_posx - c)
+            all_last_posx.append( final_posx - c )
 
         for i in all_last_posx:
             self.ClearCanvas()
@@ -285,10 +294,11 @@ class MainScreen(object):
                 j._PosX += i
                 j.DrawIcons()
                 j._Screen.SwapAndShow()
-
+                
+        
         self._Pages[self._PageIndex]._OnShow = False
-
-        self._PageIndex -= 1
+        
+        self._PageIndex-=1
         if self._PageIndex < 0:
             self._PageIndex = 0
 
@@ -297,33 +307,33 @@ class MainScreen(object):
 
     def CurPage(self):
         return self._CurrentPage
-
+    
     def PushCurPage(self):
         self._MyPageStack.Push(self._CurrentPage)
-
-    def SetCurPage(self, page):
+        
+    def SetCurPage(self,page):
         self._CurrentPage = page
-        on_load_cb = getattr(self._CurrentPage, "OnLoadCb", None)
+        on_load_cb = getattr(self._CurrentPage,"OnLoadCb",None)
         if on_load_cb != None:
-            if callable(on_load_cb):
+            if callable( on_load_cb ):
                 self._CurrentPage.OnLoadCb()
 
-    def PushPage(self, page):
+    def PushPage(self,page):
         self.PushCurPage()
         self.SetCurPage(page)
-
-    def AppendPage(self, Page):
+        
+    def AppendPage(self,Page):
         self._Pages.append(Page)
 
     def ClearCanvas(self):
-        self._CanvasHWND.fill((255, 255, 255))
-
+        self._CanvasHWND.fill((255,255,255))
+        
     def SwapAndShow(self):
         if self._HWND != None:
-            self._HWND.blit(self._CanvasHWND, (self._PosX, self._PosY, self._Width, self._Height))
+            self._HWND.blit(self._CanvasHWND,(self._PosX,self._PosY,self._Width,self._Height))
             pygame.display.update()
-
-    def ExtraName(self, name):
+            
+    def ExtraName(self,name):
         ## extra name like 1_xxx to be => xxx, 
         parts = name.split("_")
         if len(parts) > 1:
@@ -333,83 +343,82 @@ class MainScreen(object):
         else:
             return name
 
-    def IsEmulatorPackage(self, dirname):
+    def IsEmulatorPackage(self,dirname):
         files = os.listdir(dirname)
         for i in sorted(files):
             if i.endswith(emulator_flag):
                 return True
         return False
-
-    def IsPythonPackage(self, dirname):
+    
+    def IsPythonPackage(self,dirname):
         files = os.listdir(dirname)
         for i in sorted(files):
             if i.endswith(python_package_flag):
                 return True
         return False
 
-    def ReadTheDirIntoPages(self, _dir, pglevel, cur_page):
-
+    def ReadTheDirIntoPages(self,_dir,pglevel,cur_page):
+        
         if FileExists(_dir) == False and os.path.isdir(_dir) == False:
             return
-
+        
         files = os.listdir(_dir)
         for i in sorted(files):
-            if os.path.isdir(_dir + "/" + i):  # TOPLEVEL only is dir
+            if os.path.isdir(_dir+"/"+i): # TOPLEVEL only is dir
                 if pglevel == 0:
                     page = Page()
                     page._Name = self.ExtraName(i)
                     page._Icons = []
                     self._Pages.append(page)
-                    self.ReadTheDirIntoPages(_dir + "/" + i, pglevel + 1, self._Pages[len(self._Pages) - 1])
-                else:  ## On CurPage now
+                    self.ReadTheDirIntoPages(_dir+"/"+i, pglevel+1 ,self._Pages[ len(self._Pages) -1])
+                else: ## On CurPage now
                     i2 = self.ExtraName(i)
                     iconitem = IconItem()
                     iconitem._CmdPath = ""
-                    iconitem.AddLabel(i2, self._IconFont)
-                    if FileExists(SkinMap(_dir + "/" + i2 + ".png")):
-                        iconitem._ImageName = SkinMap(_dir + "/" + i2 + ".png")
+                    iconitem.AddLabel(i2,self._IconFont)
+                    if FileExists( SkinMap(_dir+"/"+i2+".png") ):
+                        iconitem._ImageName = SkinMap(_dir+"/"+i2+".png")
                     else:
                         untitled = UntitledIcon()
                         untitled.Init()
                         if len(i2) > 1:
                             untitled.SetWords(i2[:2])
                         elif len(i2) == 1:
-                            untitled.SetWords([i2[0], i2[0]])
+                            untitled.SetWords([i2[0],i2[0]])
                         else:
-                            untitled.SetWords(["G", "s"])
-
+                            untitled.SetWords(["G","s"])
+                    
                         iconitem._ImgSurf = untitled.Surface()
                         iconitem._ImageName = ""
-
-                    if self.IsPythonPackage(_dir + "/" + i):
-                        iconitem._MyType = ICON_TYPES["FUNC"]
+                        
+                    if self.IsPythonPackage(_dir+"/"+i):
+                        iconitem._MyType  = ICON_TYPES["FUNC"]
                         sys.path.append(_dir)
                         iconitem._CmdPath = __import__(i)
-                        init_cb = getattr(iconitem._CmdPath, "Init", None)
-                        if init_cb is not None:
+                        init_cb  = getattr(iconitem._CmdPath,"Init",None)
+                        if init_cb != None:
                             if callable(init_cb):
-                                #                                iconitem._CmdPath.Init(self)
+                                iconitem._CmdPath.Init(self)
                                 cur_page._Icons.append(iconitem)
 
-                    elif self.IsEmulatorPackage(_dir + "/" + i):
+                    elif self.IsEmulatorPackage(_dir+"/"+i):
                         obj = {}
                         obj["ROM"] = ""
-                        obj["ROM_SO"] = ""
-                        obj["EXT"] = []
+                        obj["ROM_SO"] =""
+                        obj["EXT"]    = []
                         obj["LAUNCHER"] = ""
-                        obj["TITLE"] = "Game"
-                        obj["SO_URL"] = ""
-                        obj["RETRO_CONFIG"] = "" ##
-
+                        obj["TITLE"]    = "Game"
+                        obj["SO_URL"]   = ""
+                        obj["RETRO_CONFIG"] = "" ## 
                         try:
-                            f = open(_dir + "/" + i + "/" + emulator_flag)
+                            f = open(_dir+"/"+i+"/"+emulator_flag)
                         except IOError:
                             print("action config open failed")
                             return
                         else:
                             with f:
                                 content = f.readlines()
-                                content = [x.strip() for x in content]
+                                content = [x.strip() for x in content] 
                         for i in content:
                             pis = i.split("=")
                             if len(pis) > 1:
@@ -417,69 +426,69 @@ class MainScreen(object):
                                     obj[pis[0]] = pis[1].split(",")
                                 else:
                                     obj[pis[0]] = pis[1]
-
+                        
                         em = MyEmulator()
                         em._Emulator = obj
-
+                        
                         em.Init(self)
                         iconitem._CmdPath = em
-                        iconitem._MyType = ICON_TYPES["Emulator"]
+                        iconitem._MyType  = ICON_TYPES["Emulator"]
                         cur_page._Icons.append(iconitem)
-
-                    else:
-                        iconitem._MyType = ICON_TYPES["DIR"]
+                        
+                    else:                            
+                        iconitem._MyType  = ICON_TYPES["DIR"]
                         iconitem._LinkPage = Page()
                         iconitem._LinkPage._Name = i2
                         cur_page._Icons.append(iconitem)
-                        self.ReadTheDirIntoPages(_dir + "/" + i, pglevel + 1, iconitem._LinkPage)
-
-            elif os.path.isfile(_dir + "/" + i) and pglevel > 0:
+                        self.ReadTheDirIntoPages(_dir+"/"+i,pglevel+1,iconitem._LinkPage)
+                        
+            elif os.path.isfile(_dir+"/"+i) and pglevel > 0:
                 if i.lower().endswith(icon_ext):
                     i2 = self.ExtraName(i)
-
-                    # cmd      =  ReadTheFileContent(_dir+"/"+i)
+                    
+                    #cmd      =  ReadTheFileContent(_dir+"/"+i)
                     iconitem = IconItem()
-                    iconitem._CmdPath = _dir + "/" + i
+                    iconitem._CmdPath = _dir+"/"+i
                     MakeExecutable(iconitem._CmdPath)
-                    iconitem._MyType = ICON_TYPES["EXE"]
-                    if FileExists(SkinMap(_dir + "/" + ReplaceSuffix(i2, "png"))):
-                        iconitem._ImageName = SkinMap(_dir + "/" + ReplaceSuffix(i2, "png"))
+                    iconitem._MyType  = ICON_TYPES["EXE"]
+                    if FileExists( SkinMap( _dir+"/"+ReplaceSuffix(i2,"png"))):
+                        iconitem._ImageName = SkinMap(_dir+"/"+ReplaceSuffix(i2,"png"))
                     else:
                         untitled = UntitledIcon()
                         untitled.Init()
                         if len(i2) > 1:
                             untitled.SetWords(i2[:2])
                         elif len(i2) == 1:
-                            untitled.SetWords([i2[0], i2[0]])
+                            untitled.SetWords([i2[0],i2[0]])                            
                         else:
-                            untitled.SetWords(["G", "s"])
-
+                            untitled.SetWords(["G","s"])
+                        
                         iconitem._ImgSurf = untitled.Surface()
-
+                        
                         iconitem._ImageName = ""
-
-                    iconitem.AddLabel(i2.split(".")[0], self._IconFont)
+                        
+                    iconitem.AddLabel(i2.split(".")[0],self._IconFont)
                     iconitem._LinkPage = None
                     cur_page._Icons.append(iconitem)
 
-    def RunEXE(self, cmdpath):
+    def RunEXE(self,cmdpath):
         self.DrawRun()
         self.SwapAndShow()
         pygame.time.delay(1000)
         cmdpath = cmdpath.strip()
         cmdpath = CmdClean(cmdpath)
 
-        pygame.event.post(pygame.event.Event(RUNEVT, message=cmdpath))
+        pygame.event.post( pygame.event.Event(RUNEVT, message=cmdpath))
 
-    def OnExitCb(self, event):
+    def OnExitCb(self,event):
         ## leave rest to Pages
-        on_exit_cb = getattr(self._CurrentPage, "OnExitCb", None)
+        on_exit_cb = getattr(self._CurrentPage,"OnExitCb",None)
         if on_exit_cb != None:
-            if callable(on_exit_cb):
+            if callable( on_exit_cb ):
                 self._CurrentPage.OnExitCb(event)
         return
 
-    def KeyDown(self, event):
+    def KeyDown(self,event):
         """
         if event.key == pygame.K_PAGEUP:
             self.EasingAllPageLeft()
@@ -491,28 +500,30 @@ class MainScreen(object):
         if event.key == pygame.K_t:
             self.DrawRun()
             self.SwapAndShow()
-
+        
         if event.key == CurKeys["Space"]:
             self.Draw()
             self.SwapAndShow()
-
+            
         ## leave rest to Pages
-        current_page_key_down_cb = getattr(self._CurrentPage, "KeyDown", None)
+        current_page_key_down_cb = getattr(self._CurrentPage,"KeyDown",None)
         if current_page_key_down_cb != None:
-            if callable(current_page_key_down_cb):
+            if callable( current_page_key_down_cb ):
                 self._CurrentPage.KeyDown(event)
-
+                
+    
     def DrawRun(self):
         self._MsgBox.SetText("Launching....")
         self._MsgBox.Draw()
-
+    
     def Draw(self):
         self._CurrentPage.Draw()
-        # if self._HWND != None:
+        #if self._HWND != None:
         #    self._HWND.blit(self._CanvasHWND,(self._PosX,self._PosY,self._Width,self._Height))
         if self._TitleBar != None:
             self._TitleBar.Draw(self._CurrentPage._Name)
-        if self._FootBar != None:
-            if hasattr(self._CurrentPage, "_FootMsg"):
+        if self._FootBar  != None:
+            if hasattr(self._CurrentPage,"_FootMsg"):
                 self._FootBar.SetLabelTexts(self._CurrentPage._FootMsg)
                 self._FootBar.Draw()
+

+ 25 - 25
sys.py/UI/multi_icon_item.py

@@ -1,44 +1,44 @@
 # -*- coding: utf-8 -*- 
 
 import pygame
+#from beeprint import pp
 
 ## local import
-from .constants import ALIGN, Width, Height
-from .icon_item import IconItem
-from .util_funcs import midRect
-
-
-# from beeprint import pp
+from constants  import icon_width,icon_height,ICON_TYPES,ALIGN,icon_ext,Width,Height
+from util_funcs import color_surface,midRect
+from label      import Label
+from icon_item  import IconItem
 
 ##Resource file contains multi icons in single image
 ##usually the Image contains icons in Vertical, convert 1.png 2.png 3.png -append out.png
 
 class MultiIconItem(IconItem):
-    _IconWidth = 18
-    _IconHeight = 18
+    _IconWidth=18
+    _IconHeight=18
     _IconIndex = 0  # icon index on the resource Image 
-
-    def CreateImageSurf(self):
+    
+    def CreateImageSurf(self):        
         if self._ImgSurf == None and self._ImageName != "":
-            #            print(self._ImageName)
-            self._ImgSurf = pygame.image.load(self._ImageName).convert_alpha()
+#            print(self._ImageName)
+            self._ImgSurf = pygame.image.load( self._ImageName ).convert_alpha() 
+            
 
     def Draw(self):
-        if self._Align == ALIGN["VCenter"]:  # default
+        if self._Align==ALIGN["VCenter"]: #default
             if self._Label != None:
-                self._Label._PosX = self._PosX - self._Label._Width / 2 + self._Parent._PosX
-                self._Label._PosY = self._PosY + self._Height / 2 + 6 + self._Parent._PosY
-
-        elif self._Align == ALIGN["HLeft"]:
+                self._Label._PosX = self._PosX - self._Label._Width/2 + self._Parent._PosX
+                self._Label._PosY = self._PosY + self._Height/2 +6  + self._Parent._PosY
+                
+        elif self._Align ==ALIGN["HLeft"]:
             if self._Label != None:
-                self._Label._PosX = self._PosX + self._Width / 2 + 3 + self._Parent._PosX
-                self._Label._PosY = self._PosY - self._Label._Height / 2 + self._Parent._PosY
+                self._Label._PosX = self._PosX + self._Width/2 + 3 + self._Parent._PosX
+                self._Label._PosY = self._PosY - self._Label._Height/2 + self._Parent._PosY
 
-        if self._Label != None:
+        if self._Label!=None:
             self._Label.Draw()
-
+        
         if self._ImgSurf != None:
-            self._Parent._CanvasHWND.blit(self._ImgSurf, midRect(self._PosX + self._Parent._PosX,
-                                                                 self._PosY + self._Parent._PosY,
-                                                                 self._Width, self._Height, Width, Height),
-                                          (0, self._IconIndex * self._IconHeight, self._IconWidth, self._IconHeight))
+            self._Parent._CanvasHWND.blit(self._ImgSurf,midRect(self._PosX+self._Parent._PosX,
+                                                                self._PosY+self._Parent._PosY,
+                                                                self._Width,self._Height,Width,Height),
+                                          (0,self._IconIndex*self._IconHeight,self._IconWidth,self._IconHeight))

+ 37 - 36
sys.py/UI/multilabel.py

@@ -3,82 +3,83 @@
 import pygame
 
 
-class MultiLabel:  ##Multi Line Label
-    _PosX = 0
-    _PosY = 0
-    _Width = 135
-    _Height = 100
-    _Text = ""
-    _FontObj = None
-    _Color = pygame.Color(83, 83, 83)
+class MultiLabel: ##Multi Line Label 
+    _PosX=0
+    _PosY=0
+    _Width=135
+    _Height=100
+    _Text=""
+    _FontObj=None
+    _Color = pygame.Color(83,83,83)
     _CanvasHWND = None
     _TextSurf = None
     _MaxWidth = 0
-
+    
     def __init__(self):
         pass
-
-    def Init(self, text, font_obj, color=pygame.Color(83, 83, 83)):
+    
+    def Init(self,text,font_obj,color=pygame.Color(83,83,83)):
         self._Color = color
         self._FontObj = font_obj
         self._Text = text
-
-        self.blit_text(self._CanvasHWND, self._Text, (self._PosX, self._PosY), self._FontObj)
-
-    def NewCoord(self, x, y):
+        
+        self.blit_text(self._CanvasHWND,self._Text,(self._PosX,self._PosY),self._FontObj)
+        
+    def NewCoord(self,x,y):
         self._PosX = x
         self._PosY = y
 
-    def SetColor(self, color):
+    def SetColor(self,color):
         self._Color = color
-
+    
     def GetText(self):
         return self._Text
-
-    def SetText(self, text):
+    
+    def SetText(self,text):
         self._Text = text
-
-        self.blit_text(self._CanvasHWND, self._Text, (self._PosX, self._PosY), self._FontObj)
-
+        
+        self.blit_text(self._CanvasHWND,self._Text,(self._PosX,self._PosY),self._FontObj) 
+        
     def Width(self):
         return self._Width
-
-    def SetCanvasHWND(self, _canvashwnd):
+    
+    def SetCanvasHWND(self,_canvashwnd):
         self._CanvasHWND = _canvashwnd
 
-    def blit_text(self, surface, text, pos, font):
+    def blit_text(self, surface,text, pos, font):
         color = self._Color
         words = [word.split(' ') for word in text.splitlines()]
         space = font.size(' ')[0]
         max_width = self._Width
-        x, y = pos
+        x ,y = pos
         row_total_width = 0
-        lines = 0
-        for i, line in enumerate(words[:4]):
+        lines = 0 
+        for i,line in enumerate(words[:4]):
             for word in line[:12]:
                 word_surface = font.render(word, True, color)
                 word_width = word_surface.get_width()
                 word_height = word_surface.get_height()
                 row_total_width += word_width
-                if row_total_width + space >= max_width:
+                if row_total_width+space  >= max_width:
                     x = pos[0]  # Reset the x.
                     y += word_height  # Start on new row.
                     row_total_width = word_width
-
+                    
                     if lines == 0:
                         lines += word_height
                     else:
                         lines += word_height
-
+                    
                 surface.blit(word_surface, (x, y))
                 x += word_width + space
             x = pos[0]  # Reset the x.
             y += word_height  # Start on new row.
-            lines += word_height
+            lines += word_height        
         self._Height = lines
 
+    
     def Draw(self):
-        # my_text = self._FontObj.render( self._Text,True,self._Color)
-        self.blit_text(self._CanvasHWND, self._Text, (self._PosX, self._PosY), self._FontObj)
-        # pygame.draw.rect(self._CanvasHWND,(83,83,83), (self._PosX,self._PosY,self._Width,self._Height) , 1 )
-        # self._CanvasHWND.blit(my_text,(self._PosX,self._PosY,self._Width,self._Height))
+        #my_text = self._FontObj.render( self._Text,True,self._Color)
+        self.blit_text(self._CanvasHWND,self._Text,(self._PosX,self._PosY),self._FontObj)
+        #pygame.draw.rect(self._CanvasHWND,(83,83,83), (self._PosX,self._PosY,self._Width,self._Height) , 1 )
+        #self._CanvasHWND.blit(my_text,(self._PosX,self._PosY,self._Width,self._Height))

+ 260 - 247
sys.py/UI/page.py

@@ -1,213 +1,217 @@
 # -*- coding: utf-8 -*- 
 
+import pygame
+from pygame.locals import *
+from sys import exit
+import os
+import sys
 import math
 
-import pygame
 from libs import easing
 
-### local import
-from .constants import ALIGN, icon_width, icon_height, Width, ICON_TYPES
-from .icon_pool import MyIconPool
-from .keys_def import CurKeys
-from .util_funcs import midRect
-from .icon_pool import MyIconPool
+#import base64
+#from beeprint import pp
 
+### local import
+from constants    import ALIGN,icon_width,icon_height,Width,Height,ICON_TYPES
+from util_funcs   import midRect
+from keys_def     import CurKeys
+from icon_pool    import MyIconPool
 
 class PageStack:
     def __init__(self):
         self.stack = list()
 
-    def Push(self, data):
+    def Push(self,data):
         if data not in self.stack:
             self.stack.append(data)
             return True
         return False
 
     def Pop(self):
-        if len(self.stack) <= 0:
-            return None, False
-        return self.stack.pop(), True
-
+        if len(self.stack)<=0:
+            return None,False
+        return self.stack.pop(),True
+    
     def Length(self):
         return len(self.stack)
 
-
 class PageSelector:
     _PosX = 0
     _PosY = 0
     _Width = 0
     _Height = 0
     _Parent = None
-    _Alpha = 0
+    _Alpha  = 0
     _OnShow = True
-    _IconSurf = None
-
+    _IconSurf = None 
     def __init__(self):
         pass
 
-    def Init(self, x, y, w, h, alpha):
-        self._PosX = x
-        self._PosY = y
-        self._Width = w
-        self._Height = h
-        self._Alpha = alpha
+    def Init(self,x,y,w,h,alpha):
+        self._PosX   = x
+        self._PosY   = y
+        self._Width   = w
+        self._Height  = h
+        self._Alpha   = alpha
 
-    def Adjust(self, x, y, w, h, alpha):
-        self._PosX = x
-        self._PosY = y
-        self._Width = w
-        self._Height = h
-        self._Alpha = alpha
+    def Adjust(self,x,y,w,h,alpha):
+        self._PosX   = x
+        self._PosY   = y
+        self._Width   = w
+        self._Height  = h
+        self._Alpha   = alpha
 
     def Draw(self):
-        canvas = self._Parent._CanvasHWND
-        idx = self._Parent._PsIndex
+        canvas  = self._Parent._CanvasHWND
+        idx     = self._Parent._PsIndex
         iconidx = self._Parent._IconIndex
 
         if idx < len(self._Parent._Icons):
-            x = self._Parent._Icons[idx]._PosX + self._Parent._PosX
-            y = self._Parent._Icons[iconidx]._PosY  ## only use current icon's PosY
-
-            rect = midRect(x, y, self._Width, self._Height, self._Parent._Width, self._Parent._Height)
-            if rect.width <= 0 or rect.height <= 0:
+            x       = self._Parent._Icons[idx]._PosX+self._Parent._PosX
+            y       = self._Parent._Icons[iconidx]._PosY ## only use current icon's PosY
+        
+            rect    = midRect(x,y,self._Width,self._Height,self._Parent._Width,self._Parent._Height)
+            if rect.width <=0 or rect.height <= 0 :
                 return
 
+            #color = (244,197,66,50)
+            #pygame.draw.rect(canvas,color,rect,1)
             if self._IconSurf != None:
-                self._Parent._CanvasHWND.blit(self._IconSurf, rect)
-
-
+                self._Parent._CanvasHWND.blit(self._IconSurf,rect)
+            
 class Page(object):
-    _PosX = 0
-    _PosY = 0
-    _Width = 0
-    _Height = 0
+    _PosX=0
+    _PosY=0
+    _Width=0
+    _Height=0
     _Icons = []
     _Ps = None
     _PsIndex = 0
     _IconNumbers = 0
-    _IconIndex = 0  ## shows which icon current selected, the Selector can not move here
-    _PrevIconIndex = 0  ## for remember the  Highlighted Icon ,restore it's PosY to average
+    _IconIndex   = 0 ## shows which icon current selected, the Selector can not move here
+    _PrevIconIndex = 0 ## for remember the  Highlighted Icon ,restore it's PosY to average
     _Index = 0
     _Align = ALIGN["SLeft"]
-    _CanvasHWND = None  #
-    _HWND = None  #
-    _OnShow = False
-    _Name = ""
-    _Screen = None  ## Should be the Screen Class
+    _CanvasHWND = None # 
+    _HWND       = None # 
+    _OnShow     = False
+    _Name       = ""
+    _Screen     = None ## Should be the Screen Class
     _PageIconMargin = 20
-    _FootMsg = ["Nav.", "", "", "", "Enter"]  ## Default Page Foot info
-
-    _SelectedIconTopOffset = 20
-    _EasingDur = 30
+    _FootMsg    = ["Nav.","","","","Enter"] ## Default Page Foot info
 
+    _SelectedIconTopOffset=20
+    _EasingDur   = 30
+    
     def __init__(self):
         self._Icons = []
 
-    def AdjustHLeftAlign(self):  ## adjust coordinator and append the PageSelector
-        self._PosX = self._Index * self._Screen._Width
+
+    def AdjustHLeftAlign(self): ## adjust coordinator and append the PageSelector
+        self._PosX = self._Index*self._Screen._Width
         self._Width = self._Screen._Width
         self._Height = self._Screen._Height
-
-        cols = int(Width / icon_width)
-        rows = int((self._IconNumbers * icon_width) / Width + 1)
+        
+        cols = int(Width /icon_width)
+        rows = int( (self._IconNumbers * icon_width)/Width + 1)
         if rows < 1:
             rows = 1
             cnt = 0
-        for i in range(0, rows):
-            for j in range(0, cols):
-                start_x = icon_width / 2 + j * icon_width
-                start_y = icon_height / 2 + i * icon_height
+        for i in range(0,rows):
+            for j in range(0,cols):
+                start_x = icon_width/2  + j*icon_width
+                start_y = icon_height/2 + i*icon_height
                 icon = self._Icons[cnt]
-                icon.Adjust(start_x, start_y, icon_width - 4, icon_height - 4, 0)
+                icon.Adjust(start_x,start_y,icon_width-4,icon_height-4,0)
                 icon._Index = cnt
                 icon._Parent = self
-                if cnt >= (self._IconNumbers - 1):
+                if cnt >= (self._IconNumbers -1):
                     break
-                cnt += 1
-
+                cnt+=1
+        
         ps = PageSelector()
         ps._IconSurf = MyIconPool._Icons["blueselector"]
         ps._Parent = self
-        ps.Init(icon_width / 2, TitleBar._BarHeight + icon_height / 2, 92, 92, 128)
+        ps.Init(icon_width/2, TitleBar._BarHeight+icon_height/2,92,92,128)
         self._Ps = ps
         self._PsIndex = 0
         self._OnShow = False
 
-    def AdjustSLeftAlign(self):  ## adjust coordinator and append the PageSelector
-        self._PosX = self._Index * self._Screen._Width
+
+    def AdjustSLeftAlign(self): ## adjust coordinator and append the PageSelector
+        self._PosX = self._Index*self._Screen._Width
         self._Width = self._Screen._Width
         self._Height = self._Screen._Height
-
-        start_x = (self._PageIconMargin + icon_width + self._PageIconMargin) / 2
-        start_y = self._Height / 2
-
-        for i in range(0, self._IconNumbers):
+        
+        start_x = (self._PageIconMargin + icon_width+self._PageIconMargin) /2
+        start_y = self._Height/2
+        
+        for i in range(0,self._IconNumbers):
             it = self._Icons[i]
             it._Parent = self
             it._Index = i
-            it.Adjust(start_x + i * self._PageIconMargin + i * icon_width, start_y, icon_width - 6, icon_height - 6, 0)
-            it._ImgSurf = pygame.transform.smoothscale(it._ImgSurf, (it._Width, it._Height))
+            it.Adjust(start_x+i*self._PageIconMargin+i*icon_width,start_y,icon_width-6,icon_height-6,0)
+            it._ImgSurf = pygame.transform.smoothscale(it._ImgSurf,(it._Width,it._Height))
 
         ps = PageSelector()
         ps._IconSurf = MyIconPool._Icons["blueselector"]
         ps._Parent = self
-        ps.Init(start_x, start_y, 92, 92, 128)
-
+        ps.Init(start_x,start_y,92,92,128)
+        
         self._Ps = ps
         self._PsIndex = 0
         self._OnShow = False
-
+        
         if self._IconNumbers > 1:
             self._PsIndex = 1
             self._IconIndex = self._PsIndex
             self._PrevIconIndex = self._IconIndex
             self._Icons[self._IconIndex]._PosY -= self._SelectedIconTopOffset
 
-    def AdjustSAutoLeftAlign(self):  ## adjust coordinator and append the PageSelector
-        self._PosX = self._Index * self._Screen._Width
+    def AdjustSAutoLeftAlign(self): ## adjust coordinator and append the PageSelector
+        self._PosX = self._Index*self._Screen._Width
         self._Width = self._Screen._Width
         self._Height = self._Screen._Height
-
-        start_x = (self._PageIconMargin + icon_width + self._PageIconMargin) / 2
-        start_y = self._Height / 2
+        
+        start_x = (self._PageIconMargin + icon_width+self._PageIconMargin) /2
+        start_y = self._Height/2
 
         if self._IconNumbers == 1:
             start_x = self._Width / 2
-            start_y = self._Height / 2
-
+            start_y = self._Height/2
+            
             it = self._Icons[0]
             it._Parent = self
             it._Index = 0
-            it.Adjust(start_x, start_y, icon_width - 6, icon_height - 6, 0)
-            it._ImgSurf = pygame.transform.smoothscale(it._ImgSurf, (it._Width, it._Height))
+            it.Adjust(start_x,start_y,icon_width-6,icon_height-6,0)
+            it._ImgSurf = pygame.transform.smoothscale(it._ImgSurf,(it._Width,it._Height))
 
         elif self._IconNumbers == 2:
-            start_x = (self._Width - self._PageIconMargin - self._IconNumbers * icon_width) / 2 + icon_width / 2
-            start_y = self._Height / 2
+            start_x = (self._Width - self._PageIconMargin - self._IconNumbers*icon_width) / 2 + icon_width/2
+            start_y = self._Height /2
 
-            for i in range(0, self._IconNumbers):
+            for i in range(0,self._IconNumbers):
                 it = self._Icons[i]
                 it._Parent = self
                 it._Index = i
-                it.Adjust(start_x + i * self._PageIconMargin + i * icon_width, start_y, icon_width - 6, icon_height - 6,
-                          0)
-                it._ImgSurf = pygame.transform.smoothscale(it._ImgSurf, (it._Width, it._Height))
-
+                it.Adjust(start_x+i*self._PageIconMargin + i*icon_width,start_y, icon_width-6, icon_height-6,0)
+                it._ImgSurf = pygame.transform.smoothscale(it._ImgSurf,(it._Width,it._Height))
+                
         elif self._IconNumbers > 2:
-            for i in range(0, self._IconNumbers):
+            for i in range(0,self._IconNumbers):
                 it = self._Icons[i]
                 it._Parent = self
                 it._Index = i
-                it.Adjust(start_x + i * self._PageIconMargin + i * icon_width, start_y, icon_width - 6, icon_height - 6,
-                          0)
-
-                it._ImgSurf = pygame.transform.smoothscale(it._ImgSurf, (it._Width, it._Height))
+                it.Adjust(start_x+i*self._PageIconMargin + i*icon_width,start_y,icon_width-6,icon_height-6,0)
+                
+                it._ImgSurf = pygame.transform.smoothscale(it._ImgSurf,(it._Width,it._Height))
 
         ps = PageSelector()
         ps._IconSurf = MyIconPool._Icons["blueselector"]
         ps._Parent = self
-        ps.Init(start_x, start_y, 92, 92, 128)
-
+        ps.Init(start_x,start_y,92,92,128)
+        
         self._Ps = ps
         self._PsIndex = 0
         self._OnShow = False
@@ -219,130 +223,135 @@ class Page(object):
             self._Icons[self._IconIndex]._PosY -= self._SelectedIconTopOffset
 
     def InitLeftAlign(self):
-        self._PosX = self._Index * Width
+        self._PosX = self._Index*Width
         self._Width = self._Screen._Width
         self._Height = self._Screen._Height
-
-        cols = int(self._Width / icon_width)
-        rows = int((self._IconNumbers * icon_width) / self._Width + 1)
+        
+        cols = int(self._Width /icon_width)
+        rows = int((self._IconNumbers * icon_width)/self._Width + 1)
         if rows < 1:
             rows = 1
             cnt = 0
-        for i in range(0, rows):
-            for j in range(0, cols):
-                start_x = icon_width / 2 + j * icon_width
-                start_y = TitleBar._BarHeight + icon_height / 2 + i * icon_height
+        for i in range(0,rows):
+            for j in range(0,cols):
+                start_x = icon_width/2  + j*icon_width
+                start_y = TitleBar._BarHeight + icon_height/2 + i*icon_height
                 icon = IconItem()
-                icon.Init(start_x, start_y, icon_width - 4, icon_height - 4, 0)
+                icon.Init(start_x,start_y,icon_width-4,icon_height-4,0)
                 icon._Index = cnt
                 icon._Parent = self
                 self._Icons.append(icon)
-                if cnt >= (self._IconNumbers - 1):
+                if cnt >= (self._IconNumbers -1):
                     break
-                cnt += 1
+                cnt+=1
+                
         ps = PageSelector()
         ps._IconSurf = MyIconPool._Icons["blueselector"]
         ps._Parent = self
-        ps.Init(icon_width / 2, icon_height / 2, 92, 92, 128)
+        ps.Init(icon_width/2,icon_height/2,92,92,128)
         self._Ps = ps
         self._PsIndex = 0
         self._OnShow = False
 
-    def Adjust(self):  ## default init way,
-        self._PosX = self._Index * self._Screen._Width
-        self._Width = self._Screen._Width  ## equal to screen width
+    def Adjust(self): ## default init way, 
+        self._PosX = self._Index*self._Screen._Width 
+        self._Width = self._Screen._Width ## equal to screen width
         self._Height = self._Screen._Height
 
         if self._Align == ALIGN["HLeft"]:
-            start_x = (self._Width - self._IconNumbers * icon_width) / 2 + icon_width / 2
-            start_y = self._Height / 2
+            start_x = (self._Width - self._IconNumbers*icon_width)/2 + icon_width/2
+            start_y = self._Height/2
 
-            for i in range(0, self._IconNumbers):
+            for i in range(0,self._IconNumbers):
                 it = self._Icons[i]
                 it._Parent = self
                 it._Index = i
-                it.Adjust(start_x + i * icon_width, start_y, icon_width, icon_height, 0)
+                it.Adjust(start_x+i*icon_width,start_y,icon_width,icon_height,0)
                 ps = PageSelector()
                 ps._IconSurf = blueselector_surf
 
             ps._Parent = self
-            ps.Init(start_x, start_y, 92, 92, 128)
+            ps.Init(start_x,start_y,92,92,128)
             self._Ps = ps
             self._PsIndex = 0
             self._OnShow = False
         elif self._Align == ALIGN["SLeft"]:
-            start_x = (self._PageIconMargin + icon_width + self._PageIconMargin) / 2
-            start_y = self._Height / 2
-
-            for i in range(0, self._IconNumbers):
+            start_x = (self._PageIconMargin + icon_width+self._PageIconMargin) /2
+            start_y = self._Height/2
+            
+            for i in range(0,self._IconNumbers):
                 it = self._Icons[i]
                 it._Parent = self
                 it._Index = i
-                it.Adjust(start_x + i * self._PageIconMargin + i * icon_width, start_y, icon_width, icon_height, 0)
+                it.Adjust(start_x+i*self._PageIconMargin+i*icon_width,start_y,icon_width,icon_height,0)
+                
 
+       
             ps = PageSelector()
             ps._IconSurf = MyIconPool._Icons["blueselector"]
             ps._Parent = self
-            ps.Init(start_x, start_y - self._SelectedIconTopOffset, 92, 92, 128)
-
+            ps.Init(start_x,start_y-self._SelectedIconTopOffset,92,92,128)
+            
             self._Ps = ps
             self._PsIndex = 0
             self._OnShow = False
-
+            
             if self._IconNumbers > 1:
                 self._PsIndex = 1
                 self._IconIndex = self._PsIndex
                 self._PrevIconIndex = self._IconIndex
                 self._Icons[self._IconIndex]._PosY -= self._SelectedIconTopOffset
-
-    def Init(self):  ## default init way,
+                
+                
+    def Init(self): ## default init way, 
         if self._Screen != None:
             if self._Screen._CanvasHWND != None and self._CanvasHWND == None:
                 self._CanvasHWND = self._Screen._CanvasHWND
 
-        self._PosX = self._Index * self._Screen._Width
-        self._Width = self._Screen._Width  ## equal to screen width
+        self._PosX = self._Index*self._Screen._Width 
+        self._Width = self._Screen._Width ## equal to screen width
         self._Height = self._Screen._Height
 
-        start_x = (self._Width - self._IconNumbers * icon_width) / 2 + icon_width / 2
-        start_y = self._Height / 2
+        start_x = (self._Width - self._IconNumbers*icon_width)/2 + icon_width/2
+        start_y = self._Height/2
 
-        for i in range(0, self._IconNumbers):
+        for i in range(0,self._IconNumbers):
             it = IconItem()
             it._Parent = self
             it._Index = i
-            it.Init(start_x + i * icon_width, start_y, icon_width, icon_height, 0)
+            it.Init(start_x+i*icon_width,start_y,icon_width,icon_height,0)
             self._Icons.append(it)
+            
         if self._IconNumbers > 0:
             ps = PageSelector()
             ps._IconSurf = MyIconPool._Icons["blueselector"]
             ps._Parent = self
-            ps.Init(start_x, start_y, icon_width + 4, icon_height + 4, 128)
+            ps.Init(start_x,start_y,icon_width+4,icon_height+4,128)
             self._Ps = ps
             self._PsIndex = 0
             self._OnShow = False
-
-    def IconStepMoveData(self, icon_eh, cuts):  ## no Sine,No curve,plain movement steps data
+            
+    def IconStepMoveData(self,icon_eh,cuts):## no Sine,No curve,plain movement steps data
         all_pieces = []
         piece = icon_eh / cuts
 
         c = 0.0
         prev = 0.0
-        for i in range(0, cuts):
-            c += piece
-            dx = c - prev
+        for i in range(0,cuts):
+            c+=piece
+            dx = c-prev
             if dx < 0.5:
                 dx = 1.0
-
-            all_pieces.append(math.ceil(dx))
+                
+            all_pieces.append( math.ceil(dx) )
             if c >= icon_eh:
                 break
 
         c = 0
         bidx = 0
         for i in all_pieces:
-            c += i
-            bidx += 1
+            c+=i
+            bidx+=1
             if c >= icon_eh:
                 break
 
@@ -351,113 +360,113 @@ class Page(object):
         if len(all_pieces) < cuts:
             dff = cuts - len(all_pieces)
             diffa = []
-            for i in range(0, dff):
+            for i in range(0,dff):
                 diffa.append(0)
-                all_pieces.extend(diffa)
-
+                all_pieces.extend( diffa)
+                
         return all_pieces
 
-    def EasingData(self, start, distance):  ##generate easing steps data
-        current_time = 0.0
-        start_posx = 0.0
-        current_posx = start_posx
-        final_posx = float(distance)
-        posx_init = start
-        dur = self._EasingDur
-        last_posx = 0.0
+    def EasingData(self,start,distance):##generate easing steps data
+        current_time  = 0.0
+        start_posx    = 0.0
+        current_posx  = start_posx
+        final_posx    = float(distance)
+        posx_init     = start
+        dur           = self._EasingDur
+        last_posx     = 0.0
         all_last_posx = []
-        for i in range(0, distance * dur):
-            current_posx = easing.SineIn(current_time, start_posx, final_posx - start_posx, float(dur))
+        for i in range(0,distance*dur):
+            current_posx = easing.SineIn(current_time,start_posx,final_posx-start_posx,float(dur))
             if current_posx >= final_posx:
                 current_posx = final_posx
 
             dx = current_posx - last_posx
             all_last_posx.append(int(dx))
-            current_time += 1
+            current_time+=1
             last_posx = current_posx
             if current_posx >= final_posx:
                 break
             c = 0
         for i in all_last_posx:
-            c += i
-        if c < final_posx - start_posx:
+            c+=i
+        if c < final_posx -start_posx:
             all_last_posx.append(final_posx - c)
 
         return all_last_posx
 
-    def IconSmoothUp(self, icon_ew):
-        data = self.EasingData(self._PosX, icon_ew)
-        data2 = self.IconStepMoveData(self._SelectedIconTopOffset, len(data))
-
-        for i, v in enumerate(data):
-
+    def IconSmoothUp(self,icon_ew):
+        data = self.EasingData(self._PosX,icon_ew)
+        data2 = self.IconStepMoveData(self._SelectedIconTopOffset,len(data))
+        
+        for i,v in enumerate(data):
+            
             self.ClearCanvas()
-
+            
             self._Icons[self._IconIndex]._PosY -= data2[i]
-
-            if self._Icons[self._PrevIconIndex]._PosY < self._Height / 2:
-                self._Icons[self._PrevIconIndex]._PosY += data2[i]
+            
+            if self._Icons[self._PrevIconIndex]._PosY < self._Height/2:
+                self._Icons[self._PrevIconIndex]._PosY+=data2[i]
                 self.DrawIcons()
-                self._Screen.SwapAndShow()
-
-    def IconsEasingLeft(self, icon_ew):
-
-        data = self.EasingData(self._PosX, icon_ew)
-        data2 = self.IconStepMoveData(self._SelectedIconTopOffset, len(data))
-
-        for i, v in enumerate(data):
-
+                self._Screen.SwapAndShow()        
+                
+    def IconsEasingLeft(self,icon_ew):
+
+        data = self.EasingData(self._PosX,icon_ew)
+        data2 = self.IconStepMoveData(self._SelectedIconTopOffset,len(data))
+        
+        for i,v in enumerate(data):
+            
             self.ClearCanvas()
             self._PosX -= v
-
+            
             self._Icons[self._IconIndex]._PosY -= data2[i]
-
-            if self._Icons[self._PrevIconIndex]._PosY < self._Height / 2:
-                self._Icons[self._PrevIconIndex]._PosY += data2[i]
+            
+            if self._Icons[self._PrevIconIndex]._PosY < self._Height/2:
+                self._Icons[self._PrevIconIndex]._PosY+=data2[i]
             self.DrawIcons()
             self._Screen.SwapAndShow()
-
-    def IconsEasingRight(self, icon_ew):
-
-        data = self.EasingData(self._PosX, icon_ew)
-        data2 = self.IconStepMoveData(self._SelectedIconTopOffset, len(data))
-
-        for i, v in enumerate(data):
+                
+    def IconsEasingRight(self,icon_ew):
+        
+        data = self.EasingData(self._PosX,icon_ew)
+        data2 = self.IconStepMoveData(self._SelectedIconTopOffset,len(data))
+        
+        for i,v in enumerate(data):
             self.ClearCanvas()
             self._PosX += v
 
-            self._Icons[self._IconIndex]._PosY -= data2[i]
-
-            if self._Icons[self._PrevIconIndex]._PosY < self._Height / 2:
-                self._Icons[self._PrevIconIndex]._PosY += data2[i]
-
+            
+            self._Icons[self._IconIndex]._PosY-=data2[i]
+            
+            if self._Icons[self._PrevIconIndex]._PosY < self._Height/2:
+                self._Icons[self._PrevIconIndex]._PosY+=data2[i]
+                
             self.DrawIcons()
             self._Screen.SwapAndShow()
+            
+    def EasingLeft(self,ew): #ew int
 
-    def EasingLeft(self, ew):  # ew int
-
-        data = self.EasingData(self._PosX, ew)
-
+        data = self.EasingData(self._PosX,ew)
+        
         for i in data:
-            self._PosX -= i
+            self._PosX -=i
             self.Draw()
             self._Screen.SwapAndShow()
+            
+    def EasingRight(self,ew):
 
-    def EasingRight(self, ew):
-
-        data = self.EasingData(self._PosX, ew)
-
+        data = self.EasingData(self._PosX,ew)
+        
         for i in data:
             self._PosX += i
             self.Draw()
             self._Screen.SwapAndShow()
-
-    def MoveLeft(self, ew):
+            
+    def MoveLeft(self,ew):
         self._PosX -= ew
-
-    def MoveRight(self, ew):
+    def MoveRight(self,ew):
         self._PosX += ew
-
+        
     def ResetPageSelector(self):
         self._PsIndex = 0
         self._IconIndex = 0
@@ -466,39 +475,40 @@ class Page(object):
     def DrawPageSelector(self):
         if self._Ps._OnShow == True:
             self._Ps.Draw()
-
+            
     def MoveIconIndexPrev(self):
-
-        self._IconIndex -= 1
+        
+        self._IconIndex-=1
         if self._IconIndex < 0:
             self._IconIndex = 0
             self._PrevIconIndex = self._IconIndex
             return False
-        self._PrevIconIndex = self._IconIndex + 1
+        self._PrevIconIndex = self._IconIndex+1
         return True
-
+    
     def MoveIconIndexNext(self):
-        # True for Moved,False is boundary
-        self._IconIndex += 1
+        #True for Moved,False is boundary
+        self._IconIndex+=1
         if self._IconIndex > (self._IconNumbers - 1):
-            self._IconIndex = self._IconNumbers - 1
+            self._IconIndex = self._IconNumbers -1
             self._PrevIconIndex = self._IconIndex
             return False
-        self._PrevIconIndex = self._IconIndex - 1
+        self._PrevIconIndex = self._IconIndex-1
         return True
 
+    
     def IconClick(self):
-
-        if self._IconIndex > (len(self._Icons) - 1):
+        
+        if self._IconIndex > (len(self._Icons) -1):
             return
 
         cur_icon = self._Icons[self._IconIndex]
         if self._Ps._OnShow == False:
             return
         if cur_icon._MyType == ICON_TYPES["EXE"]:
-            print("IconClick: %s %d" % (cur_icon._CmdPath, cur_icon._Index))
+            print("IconClick: %s %d"%(cur_icon._CmdPath,cur_icon._Index))
             self._Screen.RunEXE(cur_icon._CmdPath)
-
+            
         elif cur_icon._MyType == ICON_TYPES["DIR"]:
             child_page = self._Icons[self._IconIndex]._LinkPage
             if child_page != None:
@@ -506,22 +516,22 @@ class Page(object):
                 self._Screen._MyPageStack.Push(self._Screen._CurrentPage)
                 self._Screen._CurrentPage = child_page
         elif cur_icon._MyType == ICON_TYPES["FUNC"]:
-            print("IconClick API: %d" % (cur_icon._Index))
-            print("%s" % cur_icon._CmdPath)
-            api_cb = getattr(cur_icon._CmdPath, "API", None)
+            print("IconClick API: %d"%(cur_icon._Index))
+            #print("%s"% cur_icon._CmdPath)
+            api_cb = getattr(cur_icon._CmdPath,"API",None)
             if api_cb != None:
                 if callable(api_cb):
                     cur_icon._CmdPath.API(self._Screen)
         elif cur_icon._MyType == ICON_TYPES["Emulator"]:
             cur_icon._CmdPath.API(self._Screen)
-
+            
     def ReturnToUpLevelPage(self):
-        pop_page, ok = self._Screen._MyPageStack.Pop()
+        pop_page,ok = self._Screen._MyPageStack.Pop()
         if ok == True:
-            # self._Screen._CurrentPage.ResetPageSelector()
+            #self._Screen._CurrentPage.ResetPageSelector()
             pop_page.Draw()
             self._Screen._CurrentPage = pop_page
-            on_return_back_cb = getattr(self._Screen._CurrentPage, "OnReturnBackCb", None)
+            on_return_back_cb = getattr(self._Screen._CurrentPage,"OnReturnBackCb",None)
             if on_return_back_cb != None:
                 if callable(on_return_back_cb):
                     self._Screen._CurrentPage.OnReturnBackCb()
@@ -530,27 +540,28 @@ class Page(object):
                 if len(self._Screen._Pages) > 0:
                     self._Screen._CurrentPage = self._Screen._Pages[self._Screen._PageIndex]
                     self._Screen._CurrentPage.Draw()
-                    print("OnTopLevel ", self._Screen._PageIndex)
+                    print("OnTopLevel ",self._Screen._PageIndex)
 
     def ClearCanvas(self):
-        self._CanvasHWND.fill(self._Screen._SkinManager.GiveColor("White"))
+        self._CanvasHWND.fill(self._Screen._SkinManager.GiveColor("White")) 
 
     def ClearIcons(self):
-        for i in range(0, self._IconNumbers):
+        for i in range(0,self._IconNumbers):
             self._Icons[i].Clear()
 
     def DrawIcons(self):
-        for i in range(0, self._IconNumbers):
+        for i in range(0,self._IconNumbers):
             self._Icons[i].Draw()
+            
 
-    def KeyDown(self, event):  ##default keydown,every inherited page class should have it's own KeyDown
+    def KeyDown(self,event):##default keydown,every inherited page class should have it's own KeyDown
         if event.key == CurKeys["A"]:
             if self._FootMsg[3] == "Back":
                 self.ReturnToUpLevelPage()
                 self._Screen.Draw()
                 self._Screen.SwapAndShow()
                 return
-
+    
         if event.key == CurKeys["Menu"]:
             self.ReturnToUpLevelPage()
             self._Screen.Draw()
@@ -558,27 +569,27 @@ class Page(object):
 
         if event.key == CurKeys["Right"]:
             if self.MoveIconIndexNext() == True:
-                if self._IconIndex == (self._IconNumbers - 1) or self._PrevIconIndex == 0:
-                    self.IconSmoothUp(
-                        icon_width + self._PageIconMargin)  # only move up selected icon,no horizontal translation
+                if self._IconIndex == (self._IconNumbers -1) or self._PrevIconIndex == 0:
+                    self.IconSmoothUp(icon_width+ self._PageIconMargin) # only move up selected icon,no horizontal translation
                 else:
                     self.IconsEasingLeft(icon_width + self._PageIconMargin)
 
-                self._PsIndex = self._IconIndex
+                self._PsIndex  = self._IconIndex
                 self._Screen.Draw()
                 self._Screen.SwapAndShow()
-
+                
+            
         if event.key == CurKeys["Left"]:
             if self.MoveIconIndexPrev() == True:
-                if self._IconIndex == 0 or self._PrevIconIndex == (self._IconNumbers - 1):
-                    self.IconSmoothUp(icon_width + self._PageIconMargin)
+                if self._IconIndex == 0 or self._PrevIconIndex == (self._IconNumbers -1):
+                    self.IconSmoothUp(icon_width+ self._PageIconMargin)
                 else:
                     self.IconsEasingRight(icon_width + self._PageIconMargin)
 
                 self._PsIndex = self._IconIndex
                 self._Screen.Draw()
                 self._Screen.SwapAndShow()
-
+                
         if event.key == CurKeys["Enter"]:
             self.IconClick()
             self._Screen.Draw()
@@ -588,3 +599,5 @@ class Page(object):
         self.ClearCanvas()
         self.DrawIcons()
         self.DrawPageSelector()
+
+

+ 31 - 32
sys.py/UI/scroller.py

@@ -1,62 +1,61 @@
 # -*- coding: utf-8 -*- 
 import pygame
-from libs.roundrects import aa_round_rect
 
-from .util_funcs import midRect
+from util_funcs  import midRect
 
+from libs.roundrects import aa_round_rect
 
 class ListScroller(object):
     _PosX = 0
     _PosY = 0
     _Width = 7
     _Height = 0
-    _MinHeight = 6  ## tested
-    _Parent = None
-    _Color = pygame.Color(131, 199, 219)
-
-    _StartX = 0
-    _StartY = 0
-    _EndX = 0
-    _EndY = 0
-    _Value = 0
+    _MinHeight = 6 ## tested 
+    _Parent    = None
+    _Color     = pygame.Color(131,199,219)
+    
+    _StartX   = 0
+    _StartY   = 0
+    _EndX     = 0
+    _EndY     = 0
+    _Value    = 0
     _CanvasHWND = None
-
+    
     def __init__(self):
         pass
 
     def Init(self):
         self.SetCanvasHWND(self._Parent._CanvasHWND)
 
-    def SetCanvasHWND(self, canvas):
+    def SetCanvasHWND(self,canvas):
         self._CanvasHWND = canvas
-
-    def AnimateDraw(self, x2, y2):
+        
+    def AnimateDraw(self,x2,y2):
         pass
 
-    def UpdateSize(self, bigheight, dirtyheight):
-        bodyheight = float(self._Parent._Height) / float(bigheight)
+    def UpdateSize(self,bigheight,dirtyheight):
+        bodyheight =  float(self._Parent._Height) / float(bigheight)
         if bodyheight > 1:
-            bodyheight = 1  ## 100%
+            bodyheight = 1 ## 100%
 
         margin = 4
-        self._Height = bodyheight * self._Parent._Height - margin  ## Draw body
-
+        self._Height  = bodyheight * self._Parent._Height - margin ## Draw body
+        
         if self._Height < self._MinHeight:
             self._Height = self._MinHeight
+        
+        self._StartX = self._Width/2
+        self._StartY = margin/2+self._Height/2
 
-        self._StartX = self._Width / 2
-        self._StartY = margin / 2 + self._Height / 2
-
-        self._EndX = self._Width / 2
-        self._EndY = self._Parent._Height - margin / 2 - self._Height / 2
+        self._EndX   = self._Width/2
+        self._EndY   = self._Parent._Height - margin/2 - self._Height/2
 
-        process = float(dirtyheight) / float(bigheight)
-        value = process * (self._EndY - self._StartY)
+        process  = float(dirtyheight) / float(bigheight)
+        value    = process* (self._EndY - self._StartY)
 
         self._Value = int(value)
-
+        
     def Draw(self):
-
-        start_rect = midRect(self._PosX + self._StartX, self._StartY + self._Value, self._Width, self._Height,
-                             self._Parent._Width, self._Parent._Height)
-        aa_round_rect(self._CanvasHWND, start_rect, self._Color, 3, 0, self._Color)
+        
+        start_rect = midRect(self._PosX+self._StartX,self._StartY+self._Value,self._Width,self._Height,self._Parent._Width,self._Parent._Height)
+        aa_round_rect(self._CanvasHWND,start_rect, self._Color,3,0, self._Color)

+ 1 - 0
sys.py/UI/simple_name_space.py

@@ -1,3 +1,4 @@
+
 class SimpleNamespace:
     def __init__(self, **kwargs):
         self.__dict__.update(kwargs)

+ 30 - 30
sys.py/UI/skin_manager.py

@@ -1,15 +1,13 @@
 # -*- coding: utf-8 -*-
 
-import configparser as ConfigParser
-import config
 import pygame
-
+import config
+import ConfigParser
 
 class CaseConfigParser(ConfigParser.SafeConfigParser):
     def optionxform(self, optionstr):
         return optionstr
 
-
 class SkinManager(object):
     """
     _HighColor = pygame.Color(51,166,255) # #33a6ff
@@ -20,55 +18,57 @@ class SkinManager(object):
     _TitleBgColor = pygame.Color(228,228,228)  # #e4e4e4
     _ActiveColor = pygame.Color(175,90,0) ## light brown  #af5a00
     """
-
+    
     _Colors = {}
     _Config = None
-
+    
     def __init__(self):
         pass
 
-    def ConvertToRGB(self, hexstr):
-
+    def ConvertToRGB(self,hexstr):
+        
         h = hexstr.lstrip('#')
-        return tuple(int(h[i:i + 2], 16) for i in (0, 2, 4))
-
+        return tuple(int(h[i:i+2], 16) for i in (0, 2 ,4))
+    
     def Init(self):
-
+        
         Colors = {}
-        Colors["High"] = pygame.Color(51, 166, 255)
-        Colors["Text"] = pygame.Color(83, 83, 83)
-        Colors["Front"] = pygame.Color(131, 199, 219)
-        Colors["URL"] = pygame.Color(51, 166, 255)
-        Colors["Line"] = pygame.Color(169, 169, 169)
-        Colors["TitleBg"] = pygame.Color(228, 228, 228)
-        Colors["Active"] = pygame.Color(175, 90, 0)
-        Colors["White"] = pygame.Color(255, 255, 255)
-
+        Colors["High"] = pygame.Color(51,166,255) 
+        Colors["Text"] = pygame.Color(83,83,83)
+        Colors["Front"] =  pygame.Color(131,199,219)
+        Colors["URL"]   = pygame.Color(51,166,255)
+        Colors["Line"]  =  pygame.Color(169,169,169)
+        Colors["TitleBg"] = pygame.Color(228,228,228)
+        Colors["Active"]  =  pygame.Color(175,90,0)
+        Colors["White"]  = pygame.Color(255,255,255)
+        
         self._Colors = Colors
-
+        
         self._Config = CaseConfigParser()
-
-        fname = "../skin/" + "default" + "/config.cfg"
-
+        
+        fname = "../skin/"+config.SKIN+"/config.cfg"
+        
         try:
             self._Config.read(fname)
-        except Exception as e:
+        except Exception,e:
             print("read skin config.cfg error %s" % str(e))
             return
         else:
             if "Colors" in self._Config.sections():
                 colour_opts = self._Config.options("Colors")
-                #                print(colour_opts)
+#                print(colour_opts)
                 for i in self._Colors:
                     if i in colour_opts:
                         try:
-                            self._Colors[i] = self.ConvertToRGB(self._Config.get("Colors", i))
-                        except Exception as e:
+                            self._Colors[i] = self.ConvertToRGB(self._Config.get("Colors",i))
+                        except Exception,e:
                             print("error in ConvertToRGB %s" % str(e))
                             continue
 
-    def GiveColor(self, name):
+    
+    def GiveColor(self,name):
         if name in self._Colors:
             return self._Colors[name]
         else:
-            return pygame.Color(255, 0, 0)
+            return  pygame.Color(255,0,0)
+    

+ 15 - 10
sys.py/UI/slider.py

@@ -1,35 +1,40 @@
+
+
 class Slider(object):
     _PosX = 0
     _PosY = 0
     _Width = 0
     _Height = 0
-
+        
     _Value = 0
     _CanvasHWND = None
-
+    
     _Range = []
-
+    
     def __init__(self):
-        self._Range = [0, 255]
+        self._Range = [0,255]
 
     def Init(self):
         self._Value = 0
-
-    def SetValue(self, v):
+        
+    def SetValue(self,v):
         self._Value = int(v)
 
-    def SetRange(self, m1, m2):
+    def SetRange(self,m1,m2):
         if m1 >= m2:
             return
-
+        
         self._Range[0] = m1
         self._Range[1] = m2
 
-    def SetCanvasHWND(self, cav):
-        self._CanvasHWND = cav
 
+    def SetCanvasHWND(self,cav):
+        self._CanvasHWND = cav
+        
     def KeyDown(self):
         pass
 
     def Draw(self):
         pass
+
+    

Some files were not shown because too many files changed in this diff