def Init(self): self._DskUsg = self.DiskUsage() self._CanvasHWND = self._Screen._CanvasHWND self._Width = self._Screen._Width self._Height = self._Screen._Height self._BGpng = IconItem() self._BGpng._ImgSurf = MyIconPool.GiveIconSurface("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]), MySkinManager.GiveFont("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), MySkinManager.GiveFont("varela25")) self._BGlabel.SetColor(self._HighColor) self._FreeLabel = Label() self._FreeLabel.SetCanvasHWND(self._CanvasHWND) self._FreeLabel.Init("Free", MySkinManager.GiveFont("varela13")) self._FreeLabel.SetColor(self._BGlabel._Color)
def Init(self): self._DskUsg = self.DiskUsage() self._CanvasHWND = self._Screen._CanvasHWND self._Width = self._Screen._Width self._Height = self._Screen._Height self._GBLabel = Label() self._GBLabel.SetCanvasHWND(self._CanvasHWND) self._GBLabel.Init( self._GBmsg % (self._DskUsg[1] - self._DskUsg[0], self._DskUsg[1]), MySkinManager.GiveFont("varela11")) self._GBLabel.SetColor(self._TextColor) self._PctLabel = Label() self._PctLabel.SetCanvasHWND(self._CanvasHWND) usage_percent = (self._DskUsg[0] / self._DskUsg[1]) * 100.0 self._PctLabel.Init("%d%%" % int(usage_percent), MySkinManager.GiveFont("EurostileBold30")) self._PctLabel.SetColor(self._TextColor) self._FreeLabel = Label() self._FreeLabel.SetCanvasHWND(self._CanvasHWND) self._FreeLabel.Init("FREE", MySkinManager.GiveFont("varela12")) self._FreeLabel.SetColor(self._PctLabel._Color)
def GenList(self): self._MyList = [] start_x = 0 start_y = 10 last_height = 0 for i,u in enumerate( ["processor","armcores","cpuscalemhz","features","memory","uname","launcher_ver","os_image_ver"] ): #for i,u in enumerate( ["processor","cpucores","cpumhz","flags","memory","uname"] ): if u not in self._AList: continue v = self._AList[u] li = InfoPageListItem() li._Parent = self li._PosX = start_x li._PosY = start_y + last_height li._Width = Width li._Fonts["normal"] = self._ListFontObj li._Fonts["small"] = MySkinManager.GiveFont("varela12") if self._AList[u]["label"] != "": li.Init( self._AList[u]["label"] ) else: li.Init( self._AList[u]["key"] ) li._Flag = self._AList[u]["key"] li.SetSmallText( self._AList[u]["value"] ) last_height += li._Height self._MyList.append(li)
def Init(self): self._Width = self._Parent._Width self._Height = self._Parent._Height self._BrightnessLabel = Label() self._BrightnessLabel.SetCanvasHWND(self._CanvasHWND) self._BrightnessLabel.Init("BRIGHT",MySkinManager.GiveFont("EurostileBold13")) self._BrightnessLabel.SetColor(MySkinManager.GiveColor('Text'))
def Init(self): self._CanvasHWND = self._Screen._CanvasHWND self._Width = self._Screen._Width self._Height = self._Screen._Height self._Label = Label() self._Label.SetCanvasHWND(self._CanvasHWND) self._Label.Init('', MySkinManager.GiveFont('varela25'))
def Init(self): self._SubPage = SelectPage() self._SubPage._Screen = self._Screen self._SubPage._Name = "Select Branch" self._SubPage.Init() self._ListFontObj = MyLangManager.TrFont("varela15") self._ListSmFontObj = MySkinManager.GiveFont("varela12") if self._Screen != None: if self._Screen._CanvasHWND != None and self._CanvasHWND == None: self._HWND = self._Screen._CanvasHWND 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 = GamePageSelector() ps._Parent = self self._Ps = ps self._PsIndex = 0 self._Scroller = ListScroller() self._Scroller._Parent = self self._Scroller._PosX = 2 self._Scroller._PosY = 2 self._Scroller.Init() start_x = 0 start_y = 0 i = 0 games = git.get_games() for game in games: li = InfoPageListItem() li._Parent = self li._PosX = start_x li._PosY = start_y + i*InfoPageListItem._Height li._Width = Width li._Fonts["normal"] = self._ListFontObj li._Fonts["small"] = self._ListSmFontObj li._LinkObj = game li.Init( game.split("/")[-1] ) sm_text = str(len(git.get_branches(game)[0])) li.SetSmallText(sm_text) li._PosX = 2 self._MyList.append(li) i = i + 1
def GenList(self): self._MyList = [] ## map ini to self._AList files_path = glob.glob(self._CORES_PATH+"/*") start_x = 10 start_y = 0 counter = 0 for i,v in enumerate( files_path): if os.path.basename(v) in self._HiddenSos: continue filename, file_extension = os.path.splitext(v) alias_file = filename+file_extension + ".alias" if file_extension in self._AllowedExts: li = InfoPageListItem() li._Parent = self li._PosX = start_x li._PosY = start_y + counter*InfoPageListItem._Height li._Width = Width-10 li._Fonts["normal"] = self._ListFontObj li._Fonts["small"] = MySkinManager.GiveFont("varela12") li._ReadOnly = True if os.path.isfile(alias_file): fp = open(alias_file, "r") alias = fp.read() alias = alias.strip() label_text = alias.decode("utf8") li.Init( label_text ) fp.close() else: li.Init( os.path.basename(v) ) li._Flag = v ##li.SetSmallText( v ) self._MyList.append(li) counter += 1
def GenList(self): self._MyList = [] start_x = 0 start_y = 10 last_height = 0 for i,u in enumerate( ["cpuscalemhz","memory","uname", "batteryinfo", "portinfo1","portinfo2","thankstimtam"] ): if u not in self._AList: continue v = self._AList[u] li = InfoPageListItem() li._Parent = self li._PosX = start_x li._PosY = start_y + last_height li._Width = Width li._Fonts["normal"] = self._ListFontObj li._Fonts["small"] = MySkinManager.GiveFont("varela12") if self._AList[u]["label"] != "": li.Init( self._AList[u]["label"] ) else: # li.Init( self._AList[u]["key"] ) li.Init("") li._Flag = self._AList[u]["key"] if self._AList[u]["value"] != "": li.SetSmallText( self._AList[u]["value"] ) else: li.SetSmallText("") last_height += li._Height self._MyList.append(li)
def Init(self): self._ListFontObj = MyLangManager.TrFont("varela15") self._ListSmFontObj = MySkinManager.GiveFont("varela12") if self._Screen != None: if self._Screen._CanvasHWND != None and self._CanvasHWND == None: self._HWND = self._Screen._CanvasHWND 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 = GamePageSelector() ps._Parent = self self._Ps = ps self._PsIndex = 0 self._Scroller = ListScroller() self._Scroller._Parent = self self._Scroller._PosX = 2 self._Scroller._PosY = 2 self._Scroller.Init()
def GenList(self): 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._Fonts["normal"] = self._ListFontObj li._Fonts["small"] = MySkinManager.GiveFont("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)
class BleInfoPage(Page): _FootMsg = ["Nav", "Forget", "Disconnect", "Back", ""] _MyList = [] _ListFontObj = MyLangManager.TrFont("varela15") _ListSmFontObj = MySkinManager.GiveFont("varela12") # small font _ListSm2FontObj = MySkinManager.GiveFont("varela11") _AList = {} _Path = "" 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 = BleInfoPageSelector() ps._Parent = self self._Ps = ps self._PsIndex = 0 #_AList is an object self.GenList() self._Scroller = ListScroller() self._Scroller._Parent = self self._Scroller._PosX = 2 self._Scroller._PosY = 2 self._Scroller.Init() self._ConfirmPage1 = BleForgetConfirmPage() self._ConfirmPage1._Screen = self._Screen self._ConfirmPage1._Name = "ConfirmForget" self._ConfirmPage1._Parent = self self._ConfirmPage1.Init() def GenList(self): if self._AList == None: return self._MyList = [] self._PsIndex = 0 start_x = 0 start_y = 0 for i, v in enumerate(self._AList): #print(i,v) # (0, dbus.String(u'AddressType')) li = InfoPageListItem() li._Parent = self li._PosX = start_x li._PosY = start_y + i * InfoPageListItem._Height li._Width = Width li._Fonts["normal"] = self._ListFontObj if v == "UUIDs": li._Fonts["small"] = self._ListSm2FontObj else: li._Fonts["small"] = self._ListSmFontObj li.Init(str(v)) li._Flag = v if v == "UUIDs": if len(self._AList[v]) > 1: pp(self._AList[v][0]) sm_text = str(self._AList[v][0]) else: sm_text = "<empty>" else: sm_text = str(self._AList[v]) if sm_text == "0": sm_text = "No" elif sm_text == "1": sm_text = "Yes" sm_text = sm_text[:20] li.SetSmallText(sm_text) li._PosX = 2 self._MyList.append(li) def TryToForget(self): global adapter proxy_obj = bus.get_object("org.bluez", self._Path) dev = dbus.Interface(proxy_obj, "org.bluez.Device1") self._Screen._MsgBox.SetText("Forgeting") self._Screen._MsgBox.Draw() self._Screen.SwapAndShow() try: adapter.RemoveDevice(dev) except Exception, e: err_name = e.get_dbus_name() if err_name == "org.freedesktop.DBus.Error.NoReply": self._Screen._MsgBox.SetText("DBus noreply") else: self._Screen._MsgBox.SetText("Forget failed") self._Screen._MsgBox.Draw() self._Screen.SwapAndShow() pygame.time.delay(500) self.ReturnToUpLevelPage() self._Screen.Draw() self._Screen.SwapAndShow()
def Init(self): self._CanvasHWND = self._Screen._CanvasHWND self.ReadLayoutFile(self._KeyboardLayoutFile) ## assign to _Secs self._SectionNumbers = len(self._Secs) self._PosX = self._Index * self._Screen._Width self._Width = self._Screen._Width self._Height = self._Screen._Height fontobj = MySkinManager.GiveFont("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_y = 0 cnt = 0 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]): ti = TextItem() ti._FontObj = fontobj ti._Parent = self if val == "_L" or val == "_R": it = KeyboardIcon() it._ImgSurf = MyIconPool.GiveIconSurface(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 self._SecsKeys[i][j].append(it) self._IconNumbers += 1 start_x = start_x + it._ImgSurf.get_width( ) + word_margin else: if val == "_S": val = "Space" ti._FontObj = MySkinManager.GiveFont("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) ti._Str = val 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._Height = 60 self._Textarea._CanvasHWND = self._CanvasHWND self._Textarea.Init() ps = KeyboardSelector() ps._Parent = self ps.Init(start_x, start_y, 25, 25, 128) self._Ps = ps self._PsIndex = 0 self._Ps._OnShow = True
class AboutPage(Page): _FootMsg = ["Nav.","","","Back",""] _MyList = [] #_ListFontObj = MyLangManager.TrFont("Eurostile13") _ListFontObj = MySkinManager.GiveFont("Eurostile13") _AList = {} _Scrolled = 0 _BGwidth = 320 _BGheight = 300 #_DrawOnce = False _Scroller = None def __init__(self): Page.__init__(self) self._Icons = {} def Uname(self): out = {} out["key"]="uname" out["label"]= "Kernel:" st = subprocess.check_output(["uname","-srmo"]) st = st.strip("\n") st = st.strip("\t") out["value"] = st self._AList["uname"] = out return def CpuMhz(self): try: with open("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq") as f: content = f.readlines() content = [x.strip() for x in content] except: print("open %s failed" % "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq") content = ["0"] mhz = int(content[0]) / 1000.0 cpuscalemhz = {} cpuscalemhz["key"] = "cpuscalemhz" cpuscalemhz["label"] = "CPU Mhz:" cpuscalemhz["value"] = str(mhz) self._AList["cpuscalemhz"] = cpuscalemhz return def CpuInfo(self): last_processor = 0 with open("/proc/cpuinfo") as f: for line in f: if line.startswith("processor"): parts = line.split(":") cur_processor_number = int( parts[1].strip()) if cur_processor_number > last_processor: last_processor = cur_processor_number if line.startswith("model name"): parts = line.split(":") #print( parts[1].strip() ) processor = {} processor["key"]="processor" processor["label"] = "Processor:" processor["value"] = parts[1].strip() self._AList["processor"] = processor if line.startswith("cpu MHz"): parts = line.split(":") #print(parts[1].strip() ) cpumhz = {} cpumhz["key"] = "cpumhz" cpumhz["label"] = "CPU MHz:" cpumhz["value"] = parts[1].strip() self._AList["cpumhz"] = cpumhz if line.startswith("cpu cores"): parts = line.split(":") #print(parts[1].strip() ) cpucores = {} cpucores["key"] = "cpucores" cpucores["label"] = "CPU cores:" cpucores["value"] = parts[1].strip() self._AList["cpucores"] = cpucores if line.startswith("Features"): parts = line.split(":") #print(parts[1].strip() ) f_ = {} f_["key"] = "features" f_["label"] = "Features:" f_["value"] = parts[1].strip() self._AList["features"] = f_ if line.startswith("flags"): parts = line.split(":") #print(parts[1].strip() ) flags = {} flags["key"] = "flags" flags["label"] = "Flags:" flags["value"] = parts[1].strip() self._AList["flags"] = flags if last_processor > 0: arm_cores = {} arm_cores["key"]= "armcores" arm_cores["label"] = "CPU cores:" arm_cores["value"] = str(last_processor + 1) self._AList["armcores"] = arm_cores def MemInfo(self): with open("/proc/meminfo") as f: for line in f: if line.startswith("MemTotal"): parts = line.split(":") parts[1] = parts[1].replace("kB","") #print( parts[1].strip() ) memory = {} memory["key"] = "memory" memory["label"] = "Memory:" memory["value"] = str( int(parts[1].strip())/1000.0) +" MB" self._AList["memory"] = memory break def LauncherVersion(self): launcher_version = {} launcher_version["key"] = "launcher_ver" launcher_version["label"] = "Launcher:" launcher_version["value"] = VERSION self._AList["launcher_ver"] = launcher_version def OsImageVersion(self): if FileExists("/etc/clockworkpi_os_image_version"): try: with open("/etc/clockworkpi_os_image_version") as f: content = f.readlines() content = [x.strip() for x in content] except: print("open %s failed" % "/etc/clockworkpi_os_image_version") content = None if content != None and len(content) > 0: os_image_ver = {} os_image_ver["key"] = "os_image_ver" os_image_ver["label"] = "OS Image:" os_image_ver["value"] = content[0][:12] self._AList["os_image_ver"] = os_image_ver def GenList(self): self._MyList = [] start_x = 0 start_y = 10 last_height = 0 for i,u in enumerate( ["processor","armcores","cpuscalemhz","features","memory","uname","launcher_ver","os_image_ver"] ): #for i,u in enumerate( ["processor","cpucores","cpumhz","flags","memory","uname"] ): if u not in self._AList: continue v = self._AList[u] li = InfoPageListItem() li._Parent = self li._PosX = start_x li._PosY = start_y + last_height li._Width = Width li._Fonts["normal"] = self._ListFontObj li._Fonts["small"] = MySkinManager.GiveFont("varela12") if self._AList[u]["label"] != "": li.Init( self._AList[u]["label"] ) else: li.Init( self._AList[u]["key"] ) li._Flag = self._AList[u]["key"] li.SetSmallText( self._AList[u]["value"] ) 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+50) ) self._PosX = self._Index*self._Screen._Width self._Width = self._Screen._Width ## equal to screen width self._Height = self._Screen._Height bgpng = MultiIconItem() bgpng._ImgSurf = MyIconPool.GiveIconSurface("about_bg") bgpng._MyType = ICON_TYPES["STAT"] bgpng._Parent = self bgpng.Adjust(0,0,self._BGwidth,self._BGheight,0) self._Icons["bg"] = bgpng self.CpuInfo() self.MemInfo() self.CpuMhz() self.Uname() self.LauncherVersion() self.OsImageVersion() 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 + 100: self._PosY -= dis self._Scrolled -= dis def ScrollUp(self): dis = 10 if self._PosY < 0: self._PosY += dis self._Scrolled += dis def OnLoadCb(self): self._Scrolled = 0 self._PosY = 0 #self._DrawOnce = False def OnReturnBackCb(self): self.ReturnToUpLevelPage() self._Screen.Draw() self._Screen.SwapAndShow() def KeyDown(self,event): if IsKeyMenuOrB(event.key): 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): # if self._DrawOnce == False: # self.ClearCanvas() ##self._Ps.Draw() # for i in self._MyList: # i.Draw() # self._DrawOnce = True # self._Icons["bg"].DrawRect((230,0,82,184),(228,0,82,184)) # y = self._MyList[len(self._MyList)-1]._PosY+30 # self._Icons["bg"].DrawRect(( (self._Width-191)/2,y,191,68),(65,232,191,68)) # always redraw if self._Wallpaper: self._CanvasHWND.blit(self._Wallpaper,(0, self._PosY * -1)) else: self.ClearCanvas() for i in self._MyList: i.Draw() self._Icons["bg"].DrawRect((230,0,82,184),(228,0,82,184)) y = self._MyList[len(self._MyList)-1]._PosY+30 self._Icons["bg"].DrawRect(( (self._Width-191)/2,y,191,68),(65,232,191,68)) if self._HWND != None: self._HWND.fill(MySkinManager.GiveColor("White")) 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()