def Draw(self): _contWidth = 280 _contHeight = 40 _contRadius = 4 _segWidth = 20 _segHeight = 20 _segSpace = 10 _contX = (Width - _contWidth) / 2 _contY = Height - (_contHeight * 3) # Offset from bottom # Draw the container container_rect = pygame.Rect(_contX, _contY, _contWidth, _contHeight) aa_round_rect(self._CanvasHWND, container_rect, MySkinManager.GiveColor("UI_Base"), _contRadius) # Draw the empty segments for i in range(0, len(self.snd_segs)): segment_rect = pygame.Rect( _contX + _segSpace + (i * (_segWidth + _segSpace)), _contY + _segSpace, _segWidth, _segHeight) self._CanvasHWND.fill(MySkinManager.GiveColor("UI_Background"), segment_rect) # Draw the segments for the current volume for i in range(0, self._Needle + 1): segment_rect = pygame.Rect( _contX + _segSpace + (i * (_segWidth + _segSpace)), _contY + _segSpace, _segWidth, _segHeight) self._CanvasHWND.fill(MySkinManager.GiveColor("UI_Foreground"), segment_rect)
def Draw(self): if self._ReadOnly == True: self._Labels["Text"].SetColor( MySkinManager.GiveColor("ReadOnlyText")) else: self._Labels["Text"].SetColor(MySkinManager.GiveColor("Text")) self._Labels["Text"]._PosX = self._Labels["Text"]._PosX + self._PosX self._Labels["Text"]._PosY = self._PosY + ( self._Height - self._Labels["Text"]._Height) / 2 self._Labels["Text"].Draw() self._Labels["Text"]._PosX = self._Labels["Text"]._PosX - self._PosX 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"].Draw() pygame.draw.line( self._Parent._CanvasHWND, MySkinManager.GiveColor('Line'), (self._PosX, self._PosY + self._Height - 1), (self._PosX + self._Width, self._PosY + self._Height - 1), 1)
def DrawBG(self): _rect = pygame.Rect(self._BGPosX, self._BGPosY, self._BGWidth, self._BGHeight) pygame.draw.rect(self._CanvasHWND, MySkinManager.GiveColor('White'), _rect, 0) pygame.draw.rect(self._CanvasHWND, MySkinManager.GiveColor('Text'), _rect, 1)
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, MySkinManager.GiveColor("Front"), 3, 0, MySkinManager.GiveColor("Front"))
def DrawCross(self,topleft,top): start_x = topleft start_y = top width = 2 height = 10 padding = 4 rect1 = pygame.Rect(start_x+padding,start_y,width,height) rect2 = pygame.Rect(start_x,start_y+padding,height,width) pygame.draw.rect(self._CanvasHWND,MySkinManager.GiveColor('Text'),rect1, 0) pygame.draw.rect(self._CanvasHWND,MySkinManager.GiveColor('Text'),rect2, 0)
class AboveAllPatch(Widget): _PosX = Width / 2 _PosY = Height / 2 _Width = 50 _Height = 120 _Text = "" _FontObj = MyLangManager.TrFont("veramono20") _Parent = None _Color = MySkinManager.GiveColor('Text') _ValColor = MySkinManager.GiveColor('URL') _CanvasHWND = None _TextSurf = None _Icons = {} _Value = 0 def __init__(self): self._Icons = {} def Init(self): pass 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) 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) 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)
def Init(self, text, font_obj, color=MySkinManager.GiveColor('Text')): self._Color = color self._FontObj = font_obj self._Text = text self.blit_text(self._CanvasHWND, self._Text, (self._PosX, self._PosY), self._FontObj)
class ListPageSelector(PageSelector): _BackgroundColor = MySkinManager.GiveColor('Front') def __init__(self): self._Width = Width def AnimateDraw(self, x2, y2): pass def Draw(self): idx = self._Parent._PsIndex if idx > (len(self._Parent._MyList) - 1): idx = len(self._Parent._MyList) if idx > 0: 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 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 IconPool(object): _GameShellIconPath = MySkinManager.GiveIcon("gameshell/icons/") _Icons = {} _Sizes = {} def __init__(self): 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"): keyname = i.split(".")[0] self._Icons[keyname] = pygame.image.load( self._GameShellIconPath + "/" + i).convert_alpha() self._Sizes[keyname] = self._Icons[keyname].get_size() def Width(self, keyname): if keyname in self._Sizes: return self._Sizes[keyname][0] def Height(self, keyname): if keyname in self._Sizes: return self._Sizes[keyname][1]
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 Init(self, text, font_obj, color=MySkinManager.GiveColor('Text')): 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()
class ListScroller(object): _PosX = 0 _PosY = 0 _Width = 7 _Height = 0 _MinHeight = 6 ## tested _Parent = None _Color = MySkinManager.GiveColor('Front') _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): self._CanvasHWND = canvas def AnimateDraw(self, x2, y2): pass def UpdateSize(self, bigheight, dirtyheight): bodyheight = float(self._Parent._Height) / float(bigheight) if bodyheight > 1: bodyheight = 1 ## 100% margin = 4 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._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) 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)
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))
def DrawWith(self, x_,y_, withborder): self.PreDraw() x_ = x_ - self._Width/2 y_ = y_ - self._Height/2 padding = 5 pygame.draw.rect(self._HWND,MySkinManager.GiveColor('White'),(x_-padding,y_-padding, self._Width+padding*2,self._Height+padding*2)) if self._HWND != None: 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) if withborder == True: pygame.draw.rect(self._HWND,MySkinManager.GiveColor('Black'),(x_-padding,y_-padding, self._Width+padding*2,self._Height+padding*2),1)
def Init(self,text,font_obj,color=MySkinManager.GiveColor('Text')): 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
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
class Word: _T = "" _Color = MySkinManager.GiveColor('Text') ## default text color _FontObj = MyLangManager.TrFont("Eurostile12") ##default font _Size = 12 _Bold = False _UndLine = False def SetColor(self, color): self._Color = color def GetColor(self): return self._Color def SetFont(self, fnt): self._FontObj = fnt def SetBold(self, bd): self._Bold = bd def SetUnderLine(self, bd): self._UndLine = bd def __init__(self, v=""): self._T = v def __str__(self): return self._T def __unicode__(self): return self._T.encode("utf-8") def __add__(self, a): return self._T + a def __repr__(self): return self._T def __len__(self): return len(self._T) def __eq__(self, other): return self._T == other def FnHeight(self): return self._FontObj.get_height() def Render(self): self._FontObj.set_bold(self._Bold) self._FontObj.set_underline(self._UndLine) sur = self._FontObj.render(self._T, True, self._Color) self._FontObj.set_bold(False) self._FontObj.set_underline(False) return sur
class Label: _PosX=0 _PosY=0 _Width=0 _Height=0 _Text="" _FontObj=None _Color = MySkinManager.GiveColor('Text') _CanvasHWND = None _TextSurf = None def __init__(self): pass def Init(self, text, font_obj, color=MySkinManager.GiveColor('Text')): 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 DrawCenter(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,midRect(self._PosX,self._PosY,self._Width,self._Height,Width,Height)) 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))
class CreateByScreen(FullScreen): _BG = None _BGColor = MySkinManager.GiveColor('Black') def Init(self): basepath = os.path.dirname(os.path.realpath(__file__)) self._BG = pygame.image.load(basepath + "/egg.png") self._CanvasHWND = pygame.Surface((self._Width, self._Height)) def Draw(self): self._CanvasHWND.fill(self._BGColor) self._CanvasHWND.blit(self._BG, (0, 0, Width, Height))
def GiveIconSurface(self,imgname): ## imgname is the png file name without .png if imgname in self._Icons: return self._Icons[imgname] else: icon_file = MySkinManager.GiveIcon("gameshell/icons/"+imgname+".png") if os.path.isfile(icon_file): keyname = imgname self._Icons[keyname] = pygame.image.load(icon_file).convert_alpha() self._Sizes[keyname] = self._Icons[keyname].get_size() return self._Icons[keyname] return None # this will cause panic,if not found both in theme and default skin folder
class CreateByScreen(FullScreen): _BG = None _BGColor = MySkinManager.GiveColor('Black') def Init(self): # self._BG = pygame.image.frombuffer(base64.b64decode(createby_clockworkpi_b64 ),(Width,Height),"RGBA") self._CanvasHWND = pygame.Surface((self._Width,self._Height)) def Draw(self): self._CanvasHWND.fill( self._BGColor ) self._CanvasHWND.blit(self._BG,(0,0,Width,Height))
class IconPool(object): _GameShellIconPath = MySkinManager.GiveIcon("gameshell/icons/") _Icons = {} _Sizes = {} def __init__(self): 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"): keyname = i.split(".")[0] self._Icons[keyname] = pygame.image.load( self._GameShellIconPath + "/" + i).convert_alpha() self._Sizes[keyname] = self._Icons[keyname].get_size() def Width(self, keyname): if keyname in self._Sizes: return self._Sizes[keyname][0] def Height(self, keyname): if keyname in self._Sizes: return self._Sizes[keyname][1] def GiveIconSurface(self, imgname): ## imgname is the png file name without .png if imgname in self._Icons: return self._Icons[imgname] else: icon_file = MySkinManager.GiveIcon("gameshell/icons/" + imgname + ".png") if os.path.isfile(icon_file): keyname = imgname self._Icons[keyname] = pygame.image.load( icon_file).convert_alpha() self._Sizes[keyname] = self._Icons[keyname].get_size() return self._Icons[keyname] return None # this will cause panic,if not found both in theme and default skin folder
def PreDraw(self): self._Width = 0 self._Height = 0 self._CanvasHWND.fill(MySkinManager.GiveColor('White')) words = self._Text.split(' ') space = self._FontObj.size(' ')[0] max_width = self._Parent._Width - 40 x, y = (0, 0) row_total_width = 0 lines = 0 for word in words: word_surface = self._FontObj.render(word, True, self._Color) word_width = word_surface.get_width() word_height = word_surface.get_height() row_total_width += word_width if lines == 0: lines += word_height 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 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
class Textbulletinboard(Textarea): _TextLimit = 200 _BackgroundColor = MySkinManager.GiveColor("White") _Align = "Left" ## Left or Center _RowPitch = -1 ## for \n _BreakPitch = -1 ## for linebreak line wrapp def SetAndBlitText(self, words): # words => [] if self._TextFull != True: self._MyWords = words self._TextIndex = len(self._MyWords) else: print("is Full %s" % "".join(str(self._MyWords))) def BuildBlitText(self): blit_rows = [[]] w = 0 xmargin = 5 endmargin = 15 x = self._PosX + xmargin linenumber = 0 cursor_row = 0 #print(self._MyWords) for i, v in enumerate(self._MyWords): if str(v) == "\n": w = 0 x = self._PosX + xmargin linenumber += 2 blit_rows.append([]) blit_rows.append([]) else: t = v.Render() t_width = t.get_width() w += t_width del (t) blit_rows[linenumber].append(v) if i == self._TextIndex - 1: cursor_row = linenumber self._BlitWords = blit_rows self._BlitIndex = self._TextIndex def BlitText(self): # build up blitwords self.BuildBlitText() xmargin = 5 endmargin = 5 start_x = self._PosX + xmargin ##start_point_x start_y = self._PosY ## start_point_y x = self._PosX + xmargin ##start_point_x y = self._PosY ## start_point_y self._TextFull = len(self._MyWords) > self._TextLimit last_height = 0 for row_idx, row in enumerate(self._BlitWords): if len(row) == 0: if self._RowPitch > 0: y = y + self._RowPitch else: y = y + 16 w = 0 continue else: total_row_width = 0 for i, v in enumerate(row): t = v.Render() total_row_width += t.get_width() if total_row_width > self._Width - endmargin: start_x = self._PosX + xmargin else: if self._Align == "Center": start_x = (self._Width - total_row_width) / 2 last_height = 0 row_width = 0 x = start_x y = y + last_height for i, v in enumerate(row): t = v.Render() row_width += t.get_width() if last_height < v.FnHeight(): last_height = v.FnHeight() if row_width >= self._Width - endmargin: x = start_x if self._Align == "Center": whatisleft = total_row_width - row_width if whatisleft >= self._Width - endmargin: x = start_x else: x = (self._Width - whatisleft) / 2 - endmargin if self._BreakPitch > 0: y = y + self._BreakPitch else: y = y + last_height row_width = 0 self._CanvasHWND.blit(t, (x, y)) x += t.get_width() def Draw(self): #aa_round_rect(self._CanvasHWND, (4,24.5+6,312,60),self._BackgroundColor,4,0,self._BackgroundColor) aa_round_rect(self._CanvasHWND, (self._PosX, self._PosY, self._Width, self._Height), self._BackgroundColor, 4, 0, self._BackgroundColor) self.BlitText()
##local import from constants import ICON_TYPES, Width, Height from icon_item import IconItem from multi_icon_item import MultiIconItem from icon_pool import MyIconPool from lang_manager import MyLangManager from util_funcs import midRect, SwapAndShow, FileExists from skin_manager import MySkinManager from widget import Widget from config import Battery, RPC from libs.roundrects import aa_round_rect from libs.DBUS import is_wifi_connected_now, wifi_strength icon_base_path = MySkinManager.GiveIcon("gameshell/titlebar_icons/") class TitleBar(Widget): _Width = Width _Height = 25 _BarHeight = 24.5 _LOffset = 3 _ROffset = 3 _Icons = {} _icon_width = 18 _icon_height = 18 _BorderWidth = 1 _CanvasHWND = None _HWND = None _Title = ""
class MultiLabel(Widget): ##Multi Line Label _Width = 135 _Height = 100 _Text = "" _FontObj = None _Color = MySkinManager.GiveColor('Text') _CanvasHWND = None _TextSurf = None _MaxWidth = 0 def __init__(self): pass def Init(self, text, font_obj, color=MySkinManager.GiveColor('Text')): self._Color = color self._FontObj = font_obj self._Text = text self.blit_text(self._CanvasHWND, self._Text, (self._PosX, self._PosY), self._FontObj) def SetColor(self, color): self._Color = color def GetText(self): return self._Text def SetText(self, text): self._Text = text self.blit_text(self._CanvasHWND, self._Text, (self._PosX, self._PosY), self._FontObj) def SetCanvasHWND(self, _canvashwnd): self._CanvasHWND = _canvashwnd def blit_text(self, surface, text, pos, font): iscjk = MyLangManager.IsCJKMode() color = self._Color words = [word.split(' ') for word in text.splitlines()] space = font.size(' ')[0] if iscjk: space = 0 words = [list(word.decode("utf8")) for word in text.splitlines()] max_width = self._Width x, y = pos row_total_width = 0 lines = 0 line_max = 12 row_max = 4 if iscjk: line_max = line_max * 2 for i, line in enumerate(words[:row_max]): for word in line[:line_max]: 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: 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 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)
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 ReadTheDirIntoPages(self, _dir, pglevel, cur_page): global commercialsoftware_flag 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) and i.startswith( ".") == False: # 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 i2 = self.ExtraName(i) iconitem = IconItem() iconitem._FileName = i iconitem._CmdPath = "" iconitem.AddLabel(MyLangManager.Tr(i2), self._IconFont) if FileExists(_dir + "/" + i + "/" + i2 + ".png"): ### 20_Prog/Prog.png , cut 20_ iconitem._ImageName = _dir + "/" + i + "/" + i2 + ".png" elif FileExists( MySkinManager.GiveIcon(_dir + "/" + i2 + ".png")): iconitem._ImageName = MySkinManager.GiveIcon(_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]]) else: untitled.SetWords(["G", "s"]) iconitem._ImgSurf = untitled.Surface() iconitem._ImageName = "" 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 != None: if callable(init_cb): iconitem._CmdPath.Init(self) cur_page._Icons.append(iconitem) elif self.IsEmulatorPackage(_dir + "/" + i): obj = {} obj["ROM"] = "" obj["ROM_SO"] = "" obj["EXT"] = [] obj["EXCLUDE"] = [] obj["FILETYPE"] = "file" obj["LAUNCHER"] = "" obj["TITLE"] = "Game" obj["SO_URL"] = "" obj["RETRO_CONFIG"] = "" ## try: 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] for c in content: pis = c.split("=") if len(pis) > 1: if "EXT" in pis[0]: obj[pis[0]] = pis[1].split(",") elif "EXCLUDE" in pis[0]: obj[pis[0]] = pis[1].split(",") else: obj[pis[0]] = pis[1] if FileExists(_dir + "/" + i + "/retroarch-local.cfg"): obj["RETRO_CONFIG"] = CmdClean( os.path.abspath(_dir + "/" + i + "/retroarch-local.cfg")) print("a local retroarch cfg:", obj["RETRO_CONFIG"]) em = MyEmulator() em._Emulator = obj em.Init(self) iconitem._CmdPath = em iconitem._MyType = ICON_TYPES["Emulator"] cur_page._Icons.append(iconitem) elif self.IsCommercialPackage(os.path.join(_dir, i)): data = None em = MyCommercialSoftwarePackage() if FileExists(_dir + "/" + i + "/.done"): print(_dir + "/" + i + "/.done") em._Done = os.path.realpath(_dir + "/" + i + "/" + i2 + ".sh") else: with open( os.path.join(_dir, i) + "/" + commercialsoftware_flag) as f: data = json.load(f) em._ComPkgInfo = data em._Done = "" em._InvokeDir = os.path.realpath(os.path.join(_dir, i)) em.Init(self) iconitem._CmdPath = em iconitem._MyType = ICON_TYPES["Commercial"] cur_page._Icons.append(iconitem) elif self.IsExecPackage( _dir + "/" + i): ## ExecPackage is the last one to check iconitem._MyType = ICON_TYPES["EXE"] iconitem._CmdPath = os.path.realpath(_dir + "/" + i + "/" + i2 + ".sh") MakeExecutable(iconitem._CmdPath) cur_page._Icons.append(iconitem) 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 i.startswith( ".") == False and pglevel > 0: if i.lower().endswith(icon_ext): i2 = self.ExtraName(i) #cmd = ReadTheFileContent(_dir+"/"+i) iconitem = IconItem() iconitem._FileName = i iconitem._CmdPath = os.path.realpath(_dir + "/" + i) MakeExecutable(iconitem._CmdPath) iconitem._MyType = ICON_TYPES["EXE"] if FileExists( MySkinManager.GiveIcon(_dir + "/" + ReplaceSuffix(i2, "png"))): iconitem._ImageName = MySkinManager.GiveIcon( _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]]) else: untitled.SetWords(["G", "s"]) iconitem._ImgSurf = untitled.Surface() iconitem._ImageName = "" iconitem.AddLabel(MyLangManager.Tr(i2.split(".")[0]), self._IconFont) iconitem._LinkPage = None cur_page._Icons.append(iconitem)
from pygame.locals import * #from sys import exit #import os #import sys #from datetime import datetime #import base64 #from beeprint import pp #UI lib from skin_manager import MySkinManager Width = 1280 Height = 720 bg_color = MySkinManager.GiveColor('White') icon_width = 80 icon_height = 80 icon_ext = ".sh" ICON_TYPES = { "Commercial": 8, "Emulator": 7, "FILE": 6, "STAT": 5, "NAV": 4, "LETTER": 3, "FUNC": 2, "DIR": 1, "EXE": 0,
class CounterScreen(FullScreen): _CounterFont = fonts["varela120"] _TextFont1 = fonts["varela15"] _TextFont2 = fonts["varela12"] _TopLabel = None _BottomLabel = None _NumberLabel = None _BGColor = MySkinManager.GiveColor('Black') _FGColor = MySkinManager.GiveColor('White') _Counting = False _Number = 10 _GobjectIntervalId = -1 _inter_counter = 0 def GObjectInterval(self): self._inter_counter += 1 if self._Number == 0: self._Counting = False print("do the real shutdown") if config.CurKeySet != "PC": cmdpath = "feh --bg-center gameshell/wallpaper/seeyou.png;" cmdpath += "sleep 3;" cmdpath += "sudo halt -p" pygame.event.post( pygame.event.Event(RUNSYS, message=cmdpath))\ return False if self._inter_counter >= 2: self._Number -= 1 if self._Number < 0: self._Number = 0 print("sub Number %d " % self._Number) self._inter_counter = 0 self.Draw() self.SwapAndShow() return self._Counting def StartCounter(self): if self._Counting == True: return self._Number = 10 self._Counting = True self._GobjectIntervalId = gobject.timeout_add(500, self.GObjectInterval) def StopCounter(self): if self._Counting == False: return self._Counting = False self._Number = 10 self._inter_counter = 0 if self._GobjectIntervalId != -1: gobject.source_remove(self._GobjectIntervalId) self._GobjectIntervalId = -1 return def Init(self): self._CanvasHWND = pygame.Surface((self._Width, self._Height)) self._TopLabel = Label() self._TopLabel.SetCanvasHWND(self._CanvasHWND) self._TopLabel.Init("System shutdown in", self._TextFont1, self._FGColor) self._BottomLabel = Label() self._BottomLabel.SetCanvasHWND(self._CanvasHWND) self._BottomLabel.Init("Press any key to stop countdown", self._TextFont2, self._FGColor) self._NumberLabel = Label() self._NumberLabel.SetCanvasHWND(self._CanvasHWND) self._NumberLabel.Init(str(self._Number), self._CounterFont, self._FGColor) def Draw(self): self._CanvasHWND.fill(self._BGColor) self._TopLabel.NewCoord(Width / 2, 15) self._TopLabel.DrawCenter() self._BottomLabel.NewCoord(Width / 2, Height - 15) self._BottomLabel.DrawCenter() self._NumberLabel.NewCoord(Width / 2, Height / 2) self._NumberLabel.SetText(str(self._Number)) self._NumberLabel.DrawCenter()