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 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 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)
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 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 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))
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 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 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()
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)
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()