diff --git a/Menu/GameShell/10_Settings/Airplane/__init__.py b/Menu/GameShell/10_Settings/Airplane/__init__.py new file mode 100644 index 0000000..ba6e34b --- /dev/null +++ b/Menu/GameShell/10_Settings/Airplane/__init__.py @@ -0,0 +1,317 @@ +# -*- coding: utf-8 -*- + +import pygame +#import math +import commands + +#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,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.multi_icon_item import MultiIconItem + +from UI.multilabel import MultiLabel + +class InfoPageListItem(object): + _PosX = 0 + _PosY = 0 + _Width = 0 + _Height = 20 + + _Labels = {} + _Icons = {} + _Fonts = {} + + _LinkObj = None + + def __init__(self): + self._Labels = {} + self._Icons = {} + self._Fonts = {} + + def SetSmallText(self,text): + + l = MultiLabel() + l.SetCanvasHWND(self._Parent._CanvasHWND) + l.Init(text,self._Fonts["small"]) + + self._Labels["Small"] = l + + #if self._Labels["Small"]._Width > self._Width: + # self._Width = self._Labels["Small"]._Width + if self._Labels["Small"]._Height >= self._Height: + self._Height = self._Labels["Small"]._Height+10 + + def Init(self,text): + + #self._Fonts["normal"] = fonts["veramono12"] + + l = Label() + l._PosX = 10 + l.SetCanvasHWND(self._Parent._CanvasHWND) + + l.Init(text,self._Fonts["normal"]) + self._Labels["Text"] = l + + def Draw(self): + + self._Labels["Text"]._PosY = self._PosY + self._Labels["Text"].Draw() + + if "Small" in self._Labels: + self._Labels["Small"]._PosX = self._Labels["Text"]._Width + 16 + self._Labels["Small"]._PosY = self._PosY + self._Labels["Small"].Draw() + + + + +class AirplanePage(Page): + _FootMsg = ["Nav.","","","Back","Toggle"] + _MyList = [] + _ListFontObj = fonts["varela13"] + + _AList = {} + + _Scrolled = 0 + + _BGwidth = 320 + _BGheight = 240-24-20 + + _DrawOnce = False + _Scroller = None + + _EasingDur = 30 + + _airwire_y = 0 + _dialog_index = 0 + + def __init__(self): + Page.__init__(self) + self._Icons = {} + + def GenList(self): + + self._MyList = [] + + + + 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._BGheight) ) + + self._PosX = self._Index*self._Screen._Width + self._Width = self._Screen._Width ## equal to screen width + self._Height = self._Screen._Height + + + + airwire = IconItem() + airwire._ImgSurf = MyIconPool._Icons["airwire"] + airwire._MyType = ICON_TYPES["STAT"] + airwire._Parent = self + airwire.Adjust(0,0,5,43,0) + self._Icons["airwire"] = airwire + + GS = IconItem() + GS._ImgSurf = MyIconPool._Icons["GS"] + GS._MyType = ICON_TYPES["STAT"] + GS._Parent = self + GS.Adjust(0,0,72,95,0) + self._Icons["GS"] = GS + + DialogBoxs = MultiIconItem() + DialogBoxs._ImgSurf = MyIconPool._Icons["DialogBoxs"] + DialogBoxs._MyType = ICON_TYPES["STAT"] + DialogBoxs._Parent = self + DialogBoxs._IconWidth = 134 + DialogBoxs._IconHeight = 93 + DialogBoxs.Adjust(0,0,134,372,0) + self._Icons["DialogBoxs"] = DialogBoxs + + + """ + bgpng = MultiIconItem() + bgpng._ImgSurf = MyIconPool._Icons["about_bg"] + bgpng._MyType = ICON_TYPES["STAT"] + bgpng._Parent = self + bgpng.Adjust(0,0,self._BGwidth,self._BGheight,0) + self._Icons["bg"] = bgpng + """ + + + self.GenList() + + self._Scroller = ListScroller() + self._Scroller._Parent = self + self._Scroller._PosX = self._Width - 10 + self._Scroller._PosY = 2 + self._Scroller.Init() + self._Scroller.SetCanvasHWND(self._HWND) + + def ScrollDown(self): + dis = 10 + if abs(self._Scrolled) < (self._BGheight - self._Height)/2 + 0: + self._PosY -= dis + self._Scrolled -= dis + + def ScrollUp(self): + dis = 10 + if self._PosY < 0: + self._PosY += dis + self._Scrolled += dis + + def ToggleModeAni(self): ## with animation + out = commands.getstatusoutput('sudo rfkill list | grep yes | cut -d " " -f3') + if out[1] == "yes": + data = self.EasingData(0,43) + for _,v in enumerate(data): + self._airwire_y -= v + self._dialog_index = 2 + pygame.time.delay(40) + + self._Screen.Draw() + self._Screen.SwapAndShow() + + commands.getstatusoutput("sudo rfkill unblock all") + self._Screen._TitleBar._InAirPlaneMode = False + + else: + data = self.EasingData(0,43) + data.reverse() + for _,v in enumerate(data): + self._airwire_y += v + self._dialog_index = 3 + pygame.time.delay(40) + self._Screen.Draw() + self._Screen.SwapAndShow() + + commands.getstatusoutput("sudo rfkill block all") + self._Screen._TitleBar._InAirPlaneMode = True + + + def ToggleMode(self): + out = commands.getstatusoutput('sudo rfkill list | grep yes | cut -d " " -f3') + print out + if out[1] == "yes": + self._Screen._MsgBox.SetText("Turning On") + self._Screen._MsgBox.Draw() + commands.getstatusoutput("sudo rfkill unblock all") + self._Screen._TitleBar._InAirPlaneMode = False + + else: + self._Screen._MsgBox.SetText("Turning Off") + self._Screen._MsgBox.Draw() + commands.getstatusoutput("sudo rfkill block all") + self._Screen._TitleBar._InAirPlaneMode = True + + + def OnLoadCb(self): + self._Scrolled = 0 + self._PosY = 0 + self._DrawOnce = False + out = commands.getstatusoutput('sudo rfkill list | grep yes | cut -d " " -f3') + if out[1] == "yes": + self._Screen._TitleBar._InAirPlaneMode = True + self._airwire_y = 50+43 + self._dialog_index = 1 + else: + self._airwire_y = 50 + self._dialog_index = 0 + self._Screen._TitleBar._InAirPlaneMode = False + + + def OnReturnBackCb(self): + self.ReturnToUpLevelPage() + self._Screen.Draw() + self._Screen.SwapAndShow() + + 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["B"]: + self.ToggleModeAni() + """ + self.ToggleMode() + self._Screen.SwapAndShow() + + pygame.time.delay(1000) + + self._Screen.Draw() + self._Screen.SwapAndShow() + """ + """ + if event.key == CurKeys["Up"]: + self.ScrollUp() + self._Screen.Draw() + self._Screen.SwapAndShow() + if event.key == CurKeys["Down"]: + self.ScrollDown() + self._Screen.Draw() + self._Screen.SwapAndShow() + """ + + def Draw(self): + self.ClearCanvas() + + self._Icons["DialogBoxs"].NewCoord(145,23) + self._Icons["airwire"].NewCoord(80,self._airwire_y) + + self._Icons["DialogBoxs"]._IconIndex = self._dialog_index + + self._Icons["DialogBoxs"].DrawTopLeft() + self._Icons["airwire"].Draw() + + self._Icons["GS"].NewCoord(98,118) + self._Icons["GS"].Draw() + + if self._HWND != None: + self._HWND.fill((255,255,255)) + + self._HWND.blit(self._CanvasHWND,(self._PosX,self._PosY,self._Width, self._Height ) ) + +# self._Scroller.UpdateSize(self._BGheight,abs(self._Scrolled)*3) +# self._Scroller.Draw() + + + + +class APIOBJ(object): + + _Page = None + def __init__(self): + pass + def Init(self,main_screen): + self._Page = AirplanePage() + self._Page._Screen = main_screen + self._Page._Name ="Airplane Mode" + self._Page.Init() + + 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): + OBJ.Init(main_screen) +def API(main_screen): + OBJ.API(main_screen) + + diff --git a/Menu/GameShell/10_Settings/PowerOptions/__init__.py b/Menu/GameShell/10_Settings/PowerOptions/__init__.py new file mode 100644 index 0000000..5ebcd5d --- /dev/null +++ b/Menu/GameShell/10_Settings/PowerOptions/__init__.py @@ -0,0 +1,567 @@ +# -*- coding: utf-8 -*- + +import pygame +#import math +#mport 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,POWEROPT +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 config + +class ListPageSelector(PageSelector): + _BackgroundColor = pygame.Color(131,199,219) + + def __init__(self): + self._PosX = 0 + self._PosY = 0 + self._Height = 0 + self._Width = Width + + 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 + + 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) + + +class PageListItem(object): + _PosX = 0 + _PosY = 0 + _Width = 0 + _Height = 30 + + _Labels = {} + _Icons = {} + _Fonts = {} + + _LinkObj = None + + _Active = False + _Value = "" + + def __init__(self): + self._Labels = {} + self._Icons = {} + self._Fonts = {} + + def SetSmallText(self,text): + + l = Label() + l._PosX = 40 + l.SetCanvasHWND(self._Parent._CanvasHWND) + l.Init(text,self._Fonts["small"]) + self._Labels["Small"] = l + + def Init(self,text): + + l = Label() + l._PosX = 10 + l.SetCanvasHWND(self._Parent._CanvasHWND) + + 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 + + if self._Active == True: + self._Parent._Icons["done"].NewCoord( self._Parent._Width-30,self._PosY+5) + self._Parent._Icons["done"].Draw() + + self._Labels["Text"].Draw(self._Active) + + if "Small" in self._Labels: + self._Labels["Small"]._PosX = self._Width - self._Labels["Small"]._Width -10 + 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) + + +class InfoPage(Page): + _FootMsg = ["Nav.","","","Back",""] + _MyList = [] + _ListFontObj = fonts["varela15"] + _AList = {} + + _Time1 = 40 + _Time2 = 120 + _Time3 = 300 + + def ConvertSecToMin(self, secs): + sec_str = "" + min_str = "" + if secs > 60: + m = int(secs/60) + s = secs % 60 + if m > 1: + min_str = "%d minutes " % m + else: + min_str = "%d minute " % m + + if s == 1: + sec_str = "%d second" % s + elif s > 1: + sec_str = "%d seconds" % s + elif secs > 0: + if secs > 1: + sec_str = "%d seconds" % secs + else: + sec_str = "%d second" % secs + + elif secs == 0: + sec_str = "Never" + + return min_str + sec_str + + def RefreshList(self): + ## after GenList ,reuse + self._AList["time1"]["value"] = self.ConvertSecToMin(self._Time1) + self._AList["time2"]["value"] = self.ConvertSecToMin(self._Time2) + self._AList["time3"]["value"] = self.ConvertSecToMin(self._Time3) + + for i,v in enumerate( self._AList ): + self._MyList[i].SetSmallText( self._AList[v]["value"] ) + + def GenList(self): + + time1 = {} + time1["key"] = "time1" + if self._Time1 == 0: + time1["value"] = "Never" + else: + time1["value"] = "%d secs" % self._Time1 + time1["label"] = "Screen dimming" + + time2 = {} + time2["key"] = "time2" + if self._Time2 == 0: + time2["value"] = "Never" + else: + time2["value"] = "%d secs" % self._Time2 + + time2["label"] = "Screen OFF" + + time3 = {} + time3["key"] = "time3" + + if self._Time3 == 0: + time3["value"] = "Never" + else: + time3["value"] = "%d secs" % self._Time3 + time3["label"] = "Power OFF" + + self._AList["time1"] = time1 + self._AList["time2"] = time2 + self._AList["time3"] = time3 + + self._MyList = [] + + start_x = 0 + start_y = 0 + + for i,v in enumerate( self._AList): + print(v) + li = PageListItem() + li._Parent = self + li._PosX = start_x + li._PosY = start_y + i*PageListItem._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"] ) + else: + li.Init( self._AList[v]["key"] ) + + li._Flag = self._AList[v]["key"] + + 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._Height = self._Screen._Height + + ps = ListPageSelector() + ps._Parent = self + self._Ps = ps + self._PsIndex = 0 + + self.GenList() + + + 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)): + self._MyList[i]._PosY += self._MyList[i]._Height + + + def ScrollDown(self): + if len(self._MyList) == 0: + return + self._PsIndex +=1 + if self._PsIndex >= len(self._MyList): + 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)): + self._MyList[i]._PosY -= self._MyList[i]._Height + + def Click(self): + cur_li = self._MyList[self._PsIndex] + print(cur_li._Flag) + + + def OnLoadCb(self): + self.RefreshList() + + def OnReturnBackCb(self): + pass + """ + self.ReturnToUpLevelPage() + self._Screen.Draw() + self._Screen.SwapAndShow() + """ + + 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() + self._Screen.SwapAndShow() + if event.key == CurKeys["Down"]: + self.ScrollDown() + self._Screen.Draw() + self._Screen.SwapAndShow() + + def Draw(self): + self.ClearCanvas() + self._Ps.Draw() + + for i in self._MyList: + i.Draw() + +class PowerOptionsPage(Page): + _FootMsg = ["Nav.","","Detail","Back","Select"] + _MyList = [] + _ListFont = fonts["notosanscjk15"] + + _AList = {} + + _Scrolled = 0 + + _BGwidth = 320 + _BGheight = 240-24-20 + + _DrawOnce = False + _Scroller = None + _InfoPage = None + + def __init__(self): + Page.__init__(self) + self._Icons = {} + + def GenList(self): + + self._MyList = [] + + start_x = 0 + start_y = 0 + last_height = 0 + + + supersaving = {} + supersaving["key"] = "super" + supersaving["label"] = "Power saving" + supersaving["value"] = "supersaving" + + powersaving = {} + powersaving["key"] = "saving" + powersaving["label"] = "Balanced" + powersaving["value"] = "powersaving" + + balance_saving = {} + balance_saving["key"] = "balance" + balance_saving["label"] = "Performance" + balance_saving["value"] = "balance_saving" + + + self._AList["supersaving"] = supersaving + self._AList["powersaving"] = powersaving + self._AList["balance_saving"] = balance_saving + + for i,u in enumerate( ["supersaving","powersaving","balance_saving"] ): + if u not in self._AList: + continue + + v = self._AList[u] + + li = PageListItem() + li._Parent = self + li._PosX = start_x + li._PosY = start_y + last_height + li._Width = Width + li._Fonts["normal"] = self._ListFont + li._Active = False + li._Value = self._AList[u]["value"] + + if self._AList[u]["label"] != "": + li.Init( self._AList[u]["label"] ) + else: + li.Init( self._AList[u]["key"] ) + + last_height += li._Height + + self._MyList.append(li) + + 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._BGheight) ) + + self._PosX = self._Index*self._Screen._Width + self._Width = self._Screen._Width ## equal to screen width + self._Height = self._Screen._Height + + done = IconItem() + done._ImgSurf = MyIconPool._Icons["done"] + done._MyType = ICON_TYPES["STAT"] + done._Parent = self + self._Icons["done"] = done + + ps = ListPageSelector() + ps._Parent = self + self._Ps = ps + self._PsIndex = 0 + + self.GenList() + + self._Scroller = ListScroller() + self._Scroller._Parent = self + self._Scroller._PosX = self._Width - 10 + self._Scroller._PosY = 2 + self._Scroller.Init() + self._Scroller.SetCanvasHWND(self._HWND) + + self._InfoPage = InfoPage() + self._InfoPage._Screen = self._Screen + self._InfoPage._Name = "Power option detail" + self._InfoPage.Init() + + def ScrollDown(self): + if len(self._MyList) == 0: + return + self._PsIndex +=1 + if self._PsIndex >= len(self._MyList): + 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)): + self._MyList[i]._PosY -= self._MyList[i]._Height + + 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)): + self._MyList[i]._PosY += self._MyList[i]._Height + + + def Click(self): + if len(self._MyList) == 0: + return + + cur_li = self._MyList[self._PsIndex] + if cur_li._Active == True: + return + + for i in self._MyList: + i._Active = False + + cur_li._Active = True + print(cur_li._Value) + with open(".powerlevel","w") as f: + f.write(cur_li._Value) + + config.PowerLevel = cur_li._Value + + self._Screen._MsgBox.SetText("Applying...") + self._Screen._MsgBox.Draw() + self._Screen.SwapAndShow() + + pygame.event.post( pygame.event.Event(POWEROPT, message="")) + + pygame.time.delay(1000) + + self._Screen.Draw() + self._Screen.SwapAndShow() + + def OnLoadCb(self): + self._Scrolled = 0 + self._PosY = 0 + self._DrawOnce = False + with open(".powerlevel", "r") as f: + powerlevel = f.read() + + powerlevel = powerlevel.strip() + + if powerlevel == "": + powerlevel = "balance_saving" + + for i in self._MyList: + if i._Value == powerlevel: + i._Active = True + + def OnReturnBackCb(self): + pass + """ + self.ReturnToUpLevelPage() + self._Screen.Draw() + self._Screen.SwapAndShow() + """ + 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["B"]: + self.Click() + + if event.key == CurKeys["Up"]: + self.ScrollUp() + self._Screen.Draw() + self._Screen.SwapAndShow() + if event.key == CurKeys["Down"]: + self.ScrollDown() + self._Screen.Draw() + self._Screen.SwapAndShow() + + if event.key == CurKeys["Y"]: + cur_li = self._MyList[self._PsIndex] + time1 = config.PowerLevels[cur_li._Value][0] + time2 = config.PowerLevels[cur_li._Value][1] + time3 = config.PowerLevels[cur_li._Value][2] + + self._InfoPage._Time1 = time1 + self._InfoPage._Time2 = time2 + self._InfoPage._Time3 = time3 + + self._Screen.PushPage(self._InfoPage) + self._Screen.Draw() + self._Screen.SwapAndShow() + + def Draw(self): + + self.ClearCanvas() + if len(self._MyList) == 0: + return + + else: + if len(self._MyList) * PageListItem._Height > self._Height: + self._Ps._Width = self._Width - 11 + self._Ps.Draw() + for i in self._MyList: + if i._PosY > self._Height + self._Height/2: + break + if i._PosY < 0: + continue + i.Draw() + self._Scroller.UpdateSize( len(self._MyList)*PageListItem._Height, self._PsIndex*PageListItem._Height) + self._Scroller.Draw() + + else: + self._Ps._Width = self._Width + self._Ps.Draw() + for i in self._MyList: + if i._PosY > self._Height + self._Height/2: + break + if i._PosY < 0: + continue + i.Draw() + + if self._HWND != None: + self._HWND.fill((255,255,255)) + + self._HWND.blit(self._CanvasHWND,(self._PosX,self._PosY,self._Width, self._Height ) ) + + + + + +class APIOBJ(object): + + _Page = None + def __init__(self): + pass + def Init(self,main_screen): + self._Page = PowerOptionsPage() + self._Page._Screen = main_screen + self._Page._Name ="Power Options" + self._Page.Init() + + 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): + OBJ.Init(main_screen) +def API(main_screen): + OBJ.API(main_screen) + + diff --git a/Menu/GameShell/10_Settings/list_page.py b/Menu/GameShell/10_Settings/list_page.py index add612e..64e588a 100644 --- a/Menu/GameShell/10_Settings/list_page.py +++ b/Menu/GameShell/10_Settings/list_page.py @@ -10,7 +10,7 @@ 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.util_funcs import midRect,FileExists from UI.keys_def import CurKeys from UI.scroller import ListScroller @@ -76,19 +76,21 @@ class ListPage(Page): self._PsIndex = 0 # "" pkgname, label - alist = [["","Wifi","Wi-Fi"], + alist = [["","Airplane","Airplane Mode"], + ["","PowerOptions","Power Options"], + ["","Wifi","Wi-Fi"], ["","Sound","Sound Volume"], ["","Brightness","BackLight Brightness"], ["","Storage",""], ["","Update", ""], ["","About", "About"], - ["","PowerOFF","Power off"]] + ["","PowerOFF","Power off"],] start_x = 0 start_y = 0 - sys.path.append(myvars.basepath)# add self as import path + sys.path.append(myvars.basepath)# add self as import path for i,v in enumerate(alist): li = ListItem() li._Parent = self @@ -102,13 +104,15 @@ class ListPage(Page): 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" or v[1] == "HelloWorld": + if FileExists(myvars.basepath+"/"+ v[1]): li._LinkObj = __import__(v[1]) init_cb = getattr(li._LinkObj,"Init",None) if init_cb != None: if callable(init_cb): li._LinkObj.Init(self._Screen) - self._MyList.append(li) + + self._MyList.append(li) self._Scroller = ListScroller() self._Scroller._Parent = self diff --git a/Menu/GameShell/Music Player/mpd_spectrum_page.py b/Menu/GameShell/Music Player/mpd_spectrum_page.py index f544762..d12bccf 100644 --- a/Menu/GameShell/Music Player/mpd_spectrum_page.py +++ b/Menu/GameShell/Music Player/mpd_spectrum_page.py @@ -3,7 +3,7 @@ import time import pygame -from numpy import fromstring,ceil,abs,log10,isnan,isinf,int16 +from numpy import fromstring,ceil,abs,log10,isnan,isinf,int16,sqrt,mean from numpy import fft as Fft import gobject @@ -11,12 +11,14 @@ import gobject from beeprint import pp ## local UI import -from UI.constants import Width,Height +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 UI.keys_def import CurKeys +from UI.icon_item import IconItem +from UI.icon_pool import MyIconPool from Queue import Queue, Empty from threading import Thread @@ -37,6 +39,9 @@ class PIFI(object): count = 0 average = 0 + + rmscount=0 + rmsaverage=0 def __init__(self): self.sampleSize = self._SAMPLE_SIZE @@ -54,7 +59,14 @@ class PIFI(object): def resetSmoothing(self): self.count = 0 self.average = 0 - + self.rmscount = 0 + self.rmsaverage = 0 + + def rms_smoothOut(self, x): + self.rmscount += 1 + self.rmsaverage = (self.rmsaverage*self.rmscount + x) / (self.rmscount+1) + return self.rmsaverage + def smoothOut(self, x): self.count += 1 self.average = (self.average*self.count + x) / (self.count+1) @@ -75,7 +87,8 @@ class PIFI(object): # Compute the scaled list of values scaledList = [int(x*scaleFactor) for x in _list ] return scaledList - + + def computeSpectrum(self, fifoFile): # Read PCM samples from fifo @@ -91,6 +104,17 @@ class PIFI(object): # Normalize [-1; +1] pcm = pcm / (2.**15) + + # Compute RMS directly from signal + rms = sqrt(mean(pcm**2)) + # Compute a simple 'moving maximum' + maximum = 2*self.rms_smoothOut(rms) + if maximum == 0: + scaleFactor = 0.0 + else: + scaleFactor = self._SCALE_WIDTH/float(maximum) + + final_rms = int(rms*scaleFactor) # Compute FFT N = pcm.size @@ -127,8 +151,8 @@ class PIFI(object): # Scale the spectrum scaledSpectrum = self.scaleList(spectrum) - - return (self.bins, scaledSpectrum) + scaledSpectrum.append( final_rms) + return scaledSpectrum class MPDSpectrumPage(Page): @@ -140,11 +164,28 @@ class MPDSpectrumPage(Page): _ListFont = fonts["veramono12"] _PIFI = None - _FiFo = None + _FIFO = None _Color = pygame.Color(126,206,244) _GobjectIntervalId = -1 _Queue = None _KeepReading = True + + _BGpng = None + _BGwidth = 320 + _BGheight = 200 + + _SheepHead = None + _SheepHeadW = 69 + _SheepHeadH = 66 + + _SheepBody = None + _SheepBodyW = 105 + _SheepBodyH = 81 + + _freq_count = 0 + _head_dir = 0 + + _Neighbor = None def __init__(self): Page.__init__(self) @@ -160,8 +201,27 @@ class MPDSpectrumPage(Page): self._CanvasHWND = self._Screen._CanvasHWND - self.Start() + """ + self._BGpng = IconItem() + self._BGpng._ImgSurf = MyIconPool._Icons["sheep_bg"] + self._BGpng._MyType = ICON_TYPES["STAT"] + self._BGpng._Parent = self + self._BGpng.Adjust(0,0,self._BGwidth,self._BGheight,0) + + self._SheepHead = IconItem() + self._SheepHead._ImgSurf = MyIconPool._Icons["sheep_head"] + self._SheepHead._MyType = ICON_TYPES["STAT"] + self._SheepHead._Parent = self + self._SheepHead.Adjust(0,0,self._SheepHeadW,self._SheepHeadH,0) + self._SheepBody = IconItem() + self._SheepBody._ImgSurf = MyIconPool._Icons["sheep_body"] + self._SheepBody._MyType = ICON_TYPES["STAT"] + self._SheepBody._Parent = self + self._SheepBody.Adjust(0,0,self._SheepBodyW,self._SheepBodyH,0) + """ + + self.Start() self._GobjectIntervalId = gobject.timeout_add(50,self.Playing) def Start(self): @@ -186,7 +246,7 @@ class MPDSpectrumPage(Page): print("self._FIFO none") return - (bins,scaledSpectrum) = self._PIFI.computeSpectrum(self._FIFO) + scaledSpectrum = self._PIFI.computeSpectrum(self._FIFO) self._Queue.put( scaledSpectrum ) self._KeepReading = False @@ -212,7 +272,9 @@ class MPDSpectrumPage(Page): return True def OnLoadCb(self): - + if self._FIFO == None: + self.Start() + if self._Queue != None: with self._Queue.mutex: self._Queue.queue.clear() @@ -228,6 +290,14 @@ class MPDSpectrumPage(Page): def KeyDown(self,event): if event.key == CurKeys["Menu"] or event.key == CurKeys["A"]: + if self._FIFO != None and self._FIFO.closed == False: + try: + self._FIFO.close() + self._FIFO = None + except Exception, e: + print(e) + + self.ReturnToUpLevelPage() self._Screen.Draw() self._Screen.SwapAndShow() @@ -238,7 +308,6 @@ class MPDSpectrumPage(Page): if event.key == CurKeys["Enter"]: pass - def Draw(self): self.ClearCanvas() @@ -246,15 +315,18 @@ class MPDSpectrumPage(Page): bw = 10 spects = None try: - spects = self._Queue.get_nowait() + spects = self._Queue.get_nowait() ## last element is rms # print("get_nowait: " , spects) except Empty: return else: # got line if len(spects) == 0: return - w = self._Width / len(spects) + w = self._Width / len( spects[0:-1] ) left_margin = (w-bw)/2 - for i,v in enumerate(spects): + for i,v in enumerate(spects[0:-1]): pygame.draw.rect(self._CanvasHWND,self._Color,(i*w+left_margin,self._Height-v,bw,v),0) + + + diff --git a/Menu/GameShell/Music Player/play_list_page.py b/Menu/GameShell/Music Player/play_list_page.py index a8334c6..308a888 100644 --- a/Menu/GameShell/Music Player/play_list_page.py +++ b/Menu/GameShell/Music Player/play_list_page.py @@ -64,6 +64,7 @@ class PlayListPage(Page): _ListFont = fonts["notosanscjk15"] _Scroller = None + _CurSongTime="0:0" _BGpng = None _BGwidth = 75 @@ -110,12 +111,13 @@ class PlayListPage(Page): self.SyncPlaying() - def GObjectInterval(self): ## 250 ms + def GObjectInterval(self): ## 250 ms + self.SyncPlaying() + if self._Screen.CurPage() == self: - self.SyncPlaying() self._Screen.Draw() self._Screen.SwapAndShow() - + return True def SyncPlaying(self): @@ -138,13 +140,14 @@ class PlayListPage(Page): else: self._MyList[posid]._Playing = True if "time" in current_song: + self._CurSongTime = current_song["time"] times_ = current_song["time"].split(":") if len(times_)> 1: cur = float(times_[0]) end = float(times_[1]) pros = int((cur/end)*100.0) self._MyList[posid]._PlayingProcess = pros - + def InPlayList(self,path): for i,v in enumerate(self._MyList): @@ -271,6 +274,7 @@ class PlayListPage(Page): self.Click() if event.key == CurKeys["Start"]: # start spectrum + myvars.SpectrumPage._Neighbor = self self._Screen.PushPage(myvars.SpectrumPage) self._Screen.Draw() self._Screen.SwapAndShow() diff --git a/skin/default/sys.py/gameshell/icons/DialogBoxs.png b/skin/default/sys.py/gameshell/icons/DialogBoxs.png new file mode 100644 index 0000000..e38d227 Binary files /dev/null and b/skin/default/sys.py/gameshell/icons/DialogBoxs.png differ diff --git a/skin/default/sys.py/gameshell/icons/GS.png b/skin/default/sys.py/gameshell/icons/GS.png new file mode 100644 index 0000000..68b8aff Binary files /dev/null and b/skin/default/sys.py/gameshell/icons/GS.png differ diff --git a/skin/default/sys.py/gameshell/icons/airwire.png b/skin/default/sys.py/gameshell/icons/airwire.png new file mode 100644 index 0000000..625d004 Binary files /dev/null and b/skin/default/sys.py/gameshell/icons/airwire.png differ diff --git a/skin/default/sys.py/gameshell/icons/sheep_bg.png b/skin/default/sys.py/gameshell/icons/sheep_bg.png new file mode 100644 index 0000000..f373475 Binary files /dev/null and b/skin/default/sys.py/gameshell/icons/sheep_bg.png differ diff --git a/skin/default/sys.py/gameshell/icons/sheep_body.png b/skin/default/sys.py/gameshell/icons/sheep_body.png new file mode 100644 index 0000000..148ff46 Binary files /dev/null and b/skin/default/sys.py/gameshell/icons/sheep_body.png differ diff --git a/skin/default/sys.py/gameshell/icons/sheep_head.png b/skin/default/sys.py/gameshell/icons/sheep_head.png new file mode 100644 index 0000000..615246b Binary files /dev/null and b/skin/default/sys.py/gameshell/icons/sheep_head.png differ diff --git a/skin/default/sys.py/gameshell/titlebar_icons/wifi.png b/skin/default/sys.py/gameshell/titlebar_icons/wifi.png index 7384a71..bc1e2c6 100644 Binary files a/skin/default/sys.py/gameshell/titlebar_icons/wifi.png and b/skin/default/sys.py/gameshell/titlebar_icons/wifi.png differ diff --git a/sys.py/UI/Emulator/fav_list_page.py b/sys.py/UI/Emulator/fav_list_page.py index 1c0d857..bb95338 100644 --- a/sys.py/UI/Emulator/fav_list_page.py +++ b/sys.py/UI/Emulator/fav_list_page.py @@ -122,18 +122,18 @@ class FavListPage(Page): for i ,v in enumerate(files_path): dirmap = {} - #if os.path.isdir(v): - # continue - # dir_base_name = os.path.basename(v) - # if dir_base_name == ".Trash" or dir_base_name == ".Fav": - # pass - # else: - # dirmap["directory"] = v - # ret.append(dirmap) + if os.path.isdir(v) and self._Emulator["FILETYPE"] == "dir": ## like DOSBOX + gameshell_bat = self._Emulator["EXT"][0] + if FileExists(v+"/"+gameshell_bat): + stats = os.stat(v) + if stats.st_gid != self._Parent._FavGID: ## only favs + continue - if os.path.isfile(v): + dirmap["gamedir"] = v.decode("utf8") + ret.append(dirmap) + if os.path.isfile(v) and self._Emulator["FILETYPE"] == "file": stats = os.stat(v) - if stats.st_gid != self._Parent._FavGID: + if stats.st_gid != self._Parent._FavGID: ## only favs continue bname = os.path.basename(v) ### filter extension if len(bname)> 1: @@ -190,6 +190,9 @@ class FavListPage(Page): li.Init(v["directory"]) elif "file" in v: li.Init(v["file"]) + + elif "gamedir" in v: + li.Init(v["gamedir"]) else: li.Init("NoName") @@ -307,11 +310,16 @@ class FavListPage(Page): self._Screen._MsgBox.SetText("Launching...") self._Screen._MsgBox.Draw() self._Screen.SwapAndShow() - print("Run ",cur_li._Path) + if self._Emulator["FILETYPE"] == "dir": + path = cur_li._Path +"/"+self._Emulator["EXT"][0] + else: + path = cur_li._Path + + print("Run ",path) # check ROM_SO exists if FileExists(self._Emulator["ROM_SO"]): - escaped_path = CmdClean( cur_li._Path) + escaped_path = CmdClean( path) custom_config = "" if self._Emulator["RETRO_CONFIG"] != "" and len(self._Emulator["RETRO_CONFIG"]) > 5: diff --git a/sys.py/UI/Emulator/rom_list_page.py b/sys.py/UI/Emulator/rom_list_page.py index f094b5f..a8d38d5 100644 --- a/sys.py/UI/Emulator/rom_list_page.py +++ b/sys.py/UI/Emulator/rom_list_page.py @@ -133,16 +133,19 @@ class RomListPage(Page): for i ,v in enumerate(files_path): dirmap = {} - #if os.path.isdir(v): - # dir_base_name = os.path.basename(v) - # if dir_base_name == ".Trash" or dir_base_name == ".Fav": - # pass - # else: - # dirmap["directory"] = v - # ret.append(dirmap) - if os.path.isfile(v): + if os.path.isdir(v) and self._Emulator["FILETYPE"] == "dir": ## like DOSBOX + gameshell_bat = self._Emulator["EXT"][0] + stats = os.stat(v) - if stats.st_gid == self._Parent._FavGID: + if stats.st_gid == self._Parent._FavGID: ##skip fav roms + continue + + if FileExists(v+"/"+gameshell_bat): + dirmap["gamedir"] = v.decode("utf8") + ret.append(dirmap) + if os.path.isfile(v) and self._Emulator["FILETYPE"] == "file": + stats = os.stat(v) + if stats.st_gid == self._Parent._FavGID: ##skip fav roms continue bname = os.path.basename(v) ### filter extension @@ -199,6 +202,8 @@ class RomListPage(Page): li.Init(v["directory"]) elif "file" in v: li.Init(v["file"]) + elif "gamedir" in v: + li.Init(v["gamedir"]) else: li.Init("NoName") @@ -336,16 +341,25 @@ class RomListPage(Page): self._Screen._MsgBox.SetText("Launching...") self._Screen._MsgBox.Draw() self._Screen.SwapAndShow() - print("Run ",cur_li._Path) + + if self._Emulator["FILETYPE"] == "dir": + path = cur_li._Path +"/"+self._Emulator["EXT"][0] + else: + path = cur_li._Path + + print("Run ",path) # check ROM_SO exists if FileExists(self._Emulator["ROM_SO"]): - escaped_path = CmdClean( cur_li._Path) + if self._Emulator["FILETYPE"] == "dir": + escaped_path = CmdClean(path) + else: + escaped_path = CmdClean(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)) return diff --git a/sys.py/UI/constants.py b/sys.py/UI/constants.py index 941110e..3b43273 100644 --- a/sys.py/UI/constants.py +++ b/sys.py/UI/constants.py @@ -34,12 +34,10 @@ DT = pygame.time.Clock().tick(30) # fps in ms,eg:50 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 +FOOTMSG = pygame.USEREVENT+5 ## +POWEROPT = pygame.USEREVENT+6 diff --git a/sys.py/UI/label.py b/sys.py/UI/label.py index c7ad207..2fe65a6 100644 --- a/sys.py/UI/label.py +++ b/sys.py/UI/label.py @@ -50,8 +50,8 @@ class Label: def SetCanvasHWND(self,_canvashwnd): self._CanvasHWND = _canvashwnd - def Draw(self): - self._FontObj.set_bold(False) ## avoing same font tangling set_bold to others + def Draw(self,bold=False): + self._FontObj.set_bold(bold) ## 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)) diff --git a/sys.py/UI/main_screen.py b/sys.py/UI/main_screen.py index 9c9b885..6def24e 100644 --- a/sys.py/UI/main_screen.py +++ b/sys.py/UI/main_screen.py @@ -45,8 +45,8 @@ class MessageBox(Label): def SetText(self,text): self._Text = text - - def Draw(self): + + def PreDraw(self): self._Width = 0 self._Height = 0 self._CanvasHWND.fill( (255,255,255)) @@ -87,20 +87,31 @@ class MessageBox(Label): 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 )) + def DrawWith(self, x_,y_, withborder): - pygame.draw.rect(self._HWND,(255,255,255),(x-padding,y-padding, self._Width+padding*2,self._Height+padding*2)) + self.PreDraw() + + x_ = x_ - self._Width/2 + y_ = y_ - self._Height/2 + + padding = 5 + + 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) + rect = pygame.Rect(x_,y_,self._Width,self._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) - + + if withborder == True: + pygame.draw.rect(self._HWND,(0,0,0),(x_-padding,y_-padding, self._Width+padding*2,self._Height+padding*2),1) + + def Draw(self): + x = (self._Parent._Width)/2 + y = (self._Parent._Height)/2 + + self.DrawWith(x,y,True) + python_package_flag = "__init__.py" emulator_flag = "action.config" @@ -125,6 +136,7 @@ class MainScreen(object): _IconFont = fonts["varela15"] _SkinManager = None + def __init__(self): self._Pages = [] self._MyPageStack = PageStack() @@ -406,6 +418,7 @@ class MainScreen(object): obj["ROM"] = "" obj["ROM_SO"] ="" obj["EXT"] = [] + obj["FILETYPE"] = "file" obj["LAUNCHER"] = "" obj["TITLE"] = "Game" obj["SO_URL"] = "" diff --git a/sys.py/UI/multi_icon_item.py b/sys.py/UI/multi_icon_item.py index 4690aca..58b2af1 100644 --- a/sys.py/UI/multi_icon_item.py +++ b/sys.py/UI/multi_icon_item.py @@ -23,6 +23,27 @@ class MultiIconItem(IconItem): self._ImgSurf = pygame.image.load( self._ImageName ).convert_alpha() + def DrawTopLeft(self): + 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"]: + 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 + + if self._Label!=None: + self._Label.Draw() + + + if self._ImgSurf != None: + self._Parent._CanvasHWND.blit(self._ImgSurf,pygame.Rect(self._PosX+self._Parent._PosX, + self._PosY+self._Parent._PosY, + self._Width,self._Height), + (0,self._IconIndex*self._IconHeight,self._IconWidth,self._IconHeight)) + def Draw(self): if self._Align==ALIGN["VCenter"]: #default if self._Label != None: @@ -36,9 +57,11 @@ class MultiIconItem(IconItem): 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)) + diff --git a/sys.py/UI/page.py b/sys.py/UI/page.py index e5e2422..9a14168 100644 --- a/sys.py/UI/page.py +++ b/sys.py/UI/page.py @@ -117,7 +117,9 @@ class Page(object): rows = int( (self._IconNumbers * icon_width)/Width + 1) if rows < 1: rows = 1 - cnt = 0 + + cnt = 0 + for i in range(0,rows): for j in range(0,cols): start_x = icon_width/2 + j*icon_width @@ -184,8 +186,8 @@ class Page(object): 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,icon_height,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 @@ -195,17 +197,16 @@ class Page(object): 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, icon_height,0) + #it._ImgSurf = pygame.transform.smoothscale(it._ImgSurf,(it._Width,it._Height)) elif self._IconNumbers > 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,icon_height,0) + #it._ImgSurf = pygame.transform.smoothscale(it._ImgSurf,(it._Width,it._Height)) ps = PageSelector() ps._IconSurf = MyIconPool._Icons["blueselector"] @@ -231,7 +232,7 @@ class Page(object): rows = int((self._IconNumbers * icon_width)/self._Width + 1) if rows < 1: rows = 1 - cnt = 0 + cnt = 0 for i in range(0,rows): for j in range(0,cols): start_x = icon_width/2 + j*icon_width @@ -267,9 +268,9 @@ class Page(object): it._Parent = self it._Index = i it.Adjust(start_x+i*icon_width,start_y,icon_width,icon_height,0) - ps = PageSelector() - ps._IconSurf = blueselector_surf + ps = PageSelector() + ps._IconSurf = MyIconPool._Icons["blueselector"] ps._Parent = self ps.Init(start_x,start_y,92,92,128) self._Ps = ps @@ -362,7 +363,7 @@ class Page(object): diffa = [] for i in range(0,dff): diffa.append(0) - all_pieces.extend( diffa) + all_pieces.extend( diffa) return all_pieces @@ -406,8 +407,9 @@ class Page(object): if self._Icons[self._PrevIconIndex]._PosY < self._Height/2: self._Icons[self._PrevIconIndex]._PosY+=data2[i] - self.DrawIcons() - self._Screen.SwapAndShow() + + self.DrawIcons() + self._Screen.SwapAndShow() def IconsEasingLeft(self,icon_ew): diff --git a/sys.py/UI/title_bar.py b/sys.py/UI/title_bar.py index eda0378..81ca4fb 100644 --- a/sys.py/UI/title_bar.py +++ b/sys.py/UI/title_bar.py @@ -3,6 +3,7 @@ import pygame import os import sys +import commands from datetime import datetime @@ -46,6 +47,7 @@ class TitleBar: _SkinManager = None + _InAirPlaneMode = False def __init__(self): self._Icons = {} @@ -237,7 +239,13 @@ class TitleBar: if is_wifi_connected_now(): print("wifi is connected") print( wifi_strength()) - + else: + out = commands.getstatusoutput('sudo rfkill list | grep yes | cut -d " " -f3') + if out[1] == "yes": + self._InAirPlaneMode = True + else: + self._InAirPlaneMode = False + def ClearCanvas(self): self._CanvasHWND.fill( self._SkinManager.GiveColor("TitleBg") ) @@ -291,9 +299,13 @@ class TitleBar: else: self._Icons["wifistatus"]._IconIndex = 0 self._Icons["wifistatus"].Draw() - print("strength error") + print("wifi strength error") else: - self._Icons["wifistatus"]._IconIndex = 0 + if self._InAirPlaneMode == False: + self._Icons["wifistatus"]._IconIndex = 0 + else: + self._Icons["wifistatus"]._IconIndex = 5 ## airplane mode icon + self._Icons["wifistatus"].NewCoord(start_x+self._icon_width+5,self._icon_height/2+(self._BarHeight-self._icon_height)/2) self._Icons["wifistatus"].Draw() diff --git a/sys.py/config.py b/sys.py/config.py index 5e40c83..044eca7 100644 --- a/sys.py/config.py +++ b/sys.py/config.py @@ -15,3 +15,15 @@ UPDATE_URL="https://raw.githubusercontent.com/clockworkpi/CPI/master/launcher_ve VERSION="stable 1.0" SKIN="default" + +## three timer values in seconds: dim screen, close screen,PowerOff +## zero means no action +PowerLevels = {} +PowerLevels["supersaving"] = [10,30,100] +PowerLevels["powersaving"] = [40,120,300] +PowerLevels["balance_saving"] = [40,0,0] + +PowerLevel = "balance_saving" + +##sys.py/.powerlevel + diff --git a/sys.py/run.py b/sys.py/run.py index 490d24e..207e469 100644 --- a/sys.py/run.py +++ b/sys.py/run.py @@ -30,7 +30,7 @@ else: #local UI import -from UI.constants import Width,Height,bg_color,icon_width,icon_height,DT,GMEVT,RUNEVT,RUNSYS,ICON_TYPES +from UI.constants import Width,Height,bg_color,icon_width,icon_height,DT,GMEVT,RUNEVT,RUNSYS,ICON_TYPES,POWEROPT from UI.util_funcs import ReplaceSuffix,FileExists, ReadTheFileContent,midRect,color_surface,SwapAndShow,GetExePath,X_center_mouse from UI.page import PageStack,PageSelector,Page from UI.label import Label @@ -59,6 +59,8 @@ myscriptname = os.path.basename(os.path.realpath(__file__)) everytime_keydown = time.time() +passout_time_stage = 0 + last_brt = -1 def gobject_loop(): @@ -73,7 +75,7 @@ def gobject_loop(): def RestoreLastBackLightBrightness(main_screen): - global last_brt + global last_brt,passout_time_stage if last_brt == -1: return @@ -95,17 +97,21 @@ def RestoreLastBackLightBrightness(main_screen): f.close() last_brt = -1 main_screen._TitleBar._InLowBackLight = -1 + passout_time_stage = 0 else: f.close() return def InspectionTeam(main_screen): - global everytime_keydown,last_brt + global everytime_keydown,last_brt,passout_time_stage cur_time = time.time() - - if cur_time - everytime_keydown > 40: + time_1 = config.PowerLevels[config.PowerLevel][0] + time_2 = config.PowerLevels[config.PowerLevel][1] + time_3 = config.PowerLevels[config.PowerLevel][2] + + if cur_time - everytime_keydown > time_1 and passout_time_stage == 0: print("timeout, dim screen %d" % int(cur_time - everytime_keydown)) try: @@ -117,8 +123,9 @@ def InspectionTeam(main_screen): content = f.readlines() content = [x.strip() for x in content] brt=int(content[0]) - if brt > 1: + if brt > 0: last_brt = brt ## remember brt for restore + brt = 1 f.seek(0) f.write(str(brt)) @@ -126,7 +133,39 @@ def InspectionTeam(main_screen): f.close() main_screen._TitleBar._InLowBackLight = 0 - + + if time_2 != 0: + passout_time_stage = 1 # next + everytime_keydown = cur_time + + elif cur_time - everytime_keydown > time_2 and passout_time_stage == 1: + print("timeout, close screen %d" % int(cur_time - everytime_keydown)) + + try: + f = open(config.BackLight,"r+") + except IOError: + pass + else: + with f: + brt = 0 + f.seek(0) + f.write(str(brt)) + f.truncate() + f.close() + main_screen._TitleBar._InLowBackLight = 0 + + if time_3 != 0: + passout_time_stage = 2 # next + everytime_keydown = cur_time + + elif cur_time - everytime_keydown > time_3 and passout_time_stage == 2: + print("Power Off now") + + if config.CurKeySet != "PC": + cmdpath = "sudo halt -p" + pygame.event.post( pygame.event.Event(RUNSYS, message=cmdpath)) + + passout_time_stage = 0 everytime_keydown = cur_time return True @@ -184,6 +223,12 @@ def event_process(event,main_screen): os.chdir( GetExePath()) os.exelp("python","python"," "+myscriptname) return + + if event.type == POWEROPT: + everytime_keydown = time.time() + RestoreLastBackLightBrightness(main_screen) + + return if event.type == pygame.KEYUP: pygame.event.clear(pygame.KEYDOWN) @@ -377,6 +422,16 @@ if __name__ == '__main__': print("This pygame does not support PNG") exit() + + if FileExists(".powerlevel") == False: + os.system("touch .powerlevel") + + with open(".powerlevel","r") as f: + powerlevel = f.read() + + powerlevel = powerlevel.strip() + if powerlevel != "": + config.PowerLevel = powerlevel big_loop()