def TrFont(self, orig_font_str): try: font_size_number = int(filter(str.isdigit, orig_font_str)) except TypeError: font_size_number = int(filter(unicode.isdigit, orig_font_str)) if font_size_number > 120: raise Exception('font string format error') if "English.ini" in self._ConfigFileName: return MySkinManager.GiveFont(orig_font_str) else: if font_size_number > 28: # raise Exception('cjk font string format error '+ str(font_size_number)) return MySkinManager.GiveFont(orig_font_str) else: return MySkinManager.GiveFont("notosanscjk%d" % font_size_number)
def Draw(self,title): self.ClearCanvas() title = MyLangManager.Tr(title) self._Title = title cur_time = datetime.now().strftime("%H:%M") time_text_font = MySkinManager.GiveFont("varela12") time_text_size = time_text_font.size(cur_time) title_text_size = MyLangManager.TrFont("varela16").size(title) self._CanvasHWND.blit(MyLangManager.TrFont("varela16").render(title,True,self._SkinManager.GiveColor("Text")),midRect(title_text_size[0]/2+self._LOffset, title_text_size[1]/2+(self._BarHeight-title_text_size[1])/2, title_text_size[0],title_text_size[1],Width,Height)) self._CanvasHWND.blit( time_text_font.render(cur_time,True,self._SkinManager.GiveColor("Text")),midRect(Width-time_text_size[0]/2-self._ROffset, time_text_size[1]/2+(self._BarHeight-time_text_size[1])/2, time_text_size[0],time_text_size[1],Width,Height)) start_x = Width-time_text_size[0]-self._ROffset-self._icon_width*3 # near by the time_text self._Icons["bluetooth"].NewCoord(start_x - self._icon_width,self._icon_height/2+(self._BarHeight-self._icon_height)/2) self._Icons["sound"].NewCoord(start_x, self._icon_height/2+(self._BarHeight-self._icon_height)/2) #self._Icons["wifi"].NewCoord(start_x+self._icon_width+5, self._icon_height/2+(self._BarHeight-self._icon_height)/2) self._Icons["battery"].NewCoord(start_x+self._icon_width+self._icon_width+8,self._icon_height/2+(self._BarHeight-self._icon_height)/2) if is_wifi_connected_now(): ge = self.GetWifiStrength(wifi_strength()) if ge > 0: self._Icons["wifistatus"]._IconIndex = ge self._Icons["wifistatus"].NewCoord(start_x+self._icon_width+5,self._icon_height/2+(self._BarHeight-self._icon_height)/2) self._Icons["wifistatus"].Draw() else: self._Icons["wifistatus"]._IconIndex = 0 self._Icons["wifistatus"].Draw() print("wifi strength error") else: 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() self._Icons["sound"].Draw() self._Icons["battery"].Draw() self._Icons["bluetooth"].Draw() pygame.draw.line(self._CanvasHWND,self._SkinManager.GiveColor("Line"),(0,self._BarHeight),(self._Width,self._BarHeight),self._BorderWidth) if self._HWND != None: self._HWND.blit(self._CanvasHWND,(self._PosX,self._PosY,self._Width,self._Height))
class UntitledIcon(object): _PosX = 0 _PosY = 0 _Width = 80 _Height = 80 _Words = ["G", "s"] _FontObj = MySkinManager.GiveFont("varela40") _BG = None # initial surface _Color = MySkinManager.GiveColor('Text') def __init__(self): self._Words = ["G", "s"] def Init(self): self._BG = pygame.image.load(BlankPng).convert_alpha() def SetWords(self, TwoWords): if len(TwoWords) == 1: self._Words[0] = TwoWords[0].upper() if len(TwoWords) == 2: self._Words[0] = TwoWords[0].upper() self._Words[1] = TwoWords[1].lower() self._Text = self._FontObj.render("".join(self._Words), True, self._Color) def Draw(self): if self._BG != None: w_ = self._Text.get_width() h_ = self._Text.get_height() self._BG.blit( self._Text, midRect(self._Width / 2, self._Height / 2, w_, h_, self._Width, self._Height)) def Surface(self): self.Draw() return self._BG
def Draw(self, title): self.ClearCanvas() title = MyLangManager.Tr(title) self._Title = title # get battery percentage, but not for music spectrum(GameShell RTA) RTA_title = "GameShell RTA" bat_pct = "" if title != RTA_title and title != MyLangManager.Tr(RTA_title): out = commands.getstatusoutput( "upower -i /org/freedesktop/UPower/devices/battery_axp20x_battery | grep percentage | tail -c 5" ) bat_pct = "".join(out[1]).strip() + " " cur_time = datetime.now().strftime("%H:%M") cur_time = bat_pct + cur_time time_text_font = MySkinManager.GiveFont("Eurostile12") time_text_size = time_text_font.size(cur_time) title_text_size = MyLangManager.TrFont("Eurostile16").size(title) self._CanvasHWND.blit( MyLangManager.TrFont("Eurostile16").render( title, True, self._SkinManager.GiveColor("Text")), midRect( title_text_size[0] / 2 + self._LOffset, title_text_size[1] / 2 + (self._BarHeight - title_text_size[1]) / 2, title_text_size[0], title_text_size[1], Width, Height)) self._CanvasHWND.blit( time_text_font.render(cur_time, True, self._SkinManager.GiveColor("Text")), midRect( Width - time_text_size[0] / 2 - self._ROffset, time_text_size[1] / 2 + (self._BarHeight - time_text_size[1]) / 2, time_text_size[0], time_text_size[1], Width, Height)) start_x = Width - time_text_size[ 0] - self._ROffset - self._icon_width * 3 # near by the time_text self._Icons["dlstatus"].NewCoord( start_x - self._icon_width * 2, self._icon_height / 2 + (self._BarHeight - self._icon_height) / 2) self._Icons["bluetooth"].NewCoord( start_x - self._icon_width, self._icon_height / 2 + (self._BarHeight - self._icon_height) / 2) self._Icons["sound"].NewCoord( start_x, self._icon_height / 2 + (self._BarHeight - self._icon_height) / 2) #self._Icons["wifi"].NewCoord(start_x+self._icon_width+5, self._icon_height/2+(self._BarHeight-self._icon_height)/2) self._Icons["battery"].NewCoord( start_x + self._icon_width + self._icon_width + 8, self._icon_height / 2 + (self._BarHeight - self._icon_height) / 2) if is_wifi_connected_now(): ge = self.GetWifiStrength(wifi_strength()) if ge > 0: self._Icons["wifistatus"]._IconIndex = ge self._Icons["wifistatus"].NewCoord( start_x + self._icon_width + 5, self._icon_height / 2 + (self._BarHeight - self._icon_height) / 2) self._Icons["wifistatus"].Draw() else: self._Icons["wifistatus"]._IconIndex = 0 self._Icons["wifistatus"].Draw() print("wifi strength error") else: 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() self._Icons["sound"].Draw() self._Icons["battery"].Draw() self._Icons["bluetooth"].Draw() #self._Icons["dlstatus"].Draw() pygame.draw.line(self._CanvasHWND, self._SkinManager.GiveColor("Line"), (0, self._BarHeight), (self._Width, self._BarHeight), self._BorderWidth) if self._HWND != None: self._HWND.blit( self._CanvasHWND, (self._PosX, self._PosY, self._Width, self._Height))
def Draw(self, title): self.ClearCanvas() title = MyLangManager.Tr(title) # Couldn't see where to change this anywhere, so let's be super explicit if title == "GameShell": title = "PocketCHIP" self._Title = title title_text_size = MyLangManager.TrFont("varela16").size(title) self._CanvasHWND.blit( MyLangManager.TrFont("varela16").render( title, True, self._SkinManager.GiveColor("Text")), # x,y,width,height,canWidth,canHeight midRect( title_text_size[0] / 2 + self._LOffset, title_text_size[1] / 2 + (self._BarHeight - title_text_size[1]) / 2, title_text_size[0], title_text_size[1], Width, Height)) cur_time = datetime.now().strftime("%H:%M") time_text_font = MySkinManager.GiveFont("varela12") time_text_size = time_text_font.size(cur_time) self._CanvasHWND.blit( time_text_font.render(cur_time, True, self._SkinManager.GiveColor("Text")), # x,y,width,height,canWidth,canHeight midRect( Width - time_text_size[0] / 2 - self._ROffset, time_text_size[1] / 2 + (self._BarHeight - time_text_size[1]) / 2, time_text_size[0], time_text_size[1], Width, Height)) #### Debug: Output the battery value as text... # cur_batt = "Batt: %s, %s" % (str(BatteryAbstraction.AsPercentage()), str(BatteryAbstraction.IsCharging())) # batt_text_font = MySkinManager.GiveFont("varela12") # batt_text_size = batt_text_font.size(cur_batt) # self._CanvasHWND.blit(batt_text_font.render( # cur_batt, # True, # self._SkinManager.GiveColor("Text")), # # x,y,width,height,canWidth,canHeight # midRect( # # Width-batt_text_size[0]/2-self._ROffset, # 200, # batt_text_size[1]/2+(self._BarHeight-batt_text_size[1])/2, # batt_text_size[0], # batt_text_size[1], # Width, # Height # ) # ) start_x = Width - time_text_size[ 0] - self._ROffset - self._icon_width * 3 # near by the time_text self._Icons["bluetooth"].NewCoord( start_x - self._icon_width, self._icon_height / 2 + (self._BarHeight - self._icon_height) / 2) self._Icons["sound"].NewCoord( start_x, self._icon_height / 2 + (self._BarHeight - self._icon_height) / 2) #self._Icons["wifi"].NewCoord(start_x+self._icon_width+5, self._icon_height/2+(self._BarHeight-self._icon_height)/2) self._Icons["battery"].NewCoord( start_x + self._icon_width + self._icon_width + 8, self._icon_height / 2 + (self._BarHeight - self._icon_height) / 2) if is_wifi_connected_now(): ge = self.GetWifiStrength(wifi_strength()) if ge > 0: self._Icons["wifistatus"]._IconIndex = ge self._Icons["wifistatus"].NewCoord( start_x + self._icon_width + 5, self._icon_height / 2 + (self._BarHeight - self._icon_height) / 2) # self._Icons["wifistatus"].Draw() else: self._Icons["wifistatus"]._IconIndex = 0 # self._Icons["wifistatus"].Draw() print("wifi strength error") else: 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() # Draw the title bar icons self._Icons["wifistatus"].Draw() self._Icons["sound"].Draw() self._Icons["battery"].Draw() # self._Icons["bluetooth"].Draw() pygame.draw.line(self._CanvasHWND, self._SkinManager.GiveColor("Line"), (0, self._BarHeight), (self._Width, self._BarHeight), self._BorderWidth) if self._HWND != None: self._HWND.blit( self._CanvasHWND, (self._PosX, self._PosY, self._Width, self._Height))