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, SkinManager().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, SkinManager().GiveColor('Black'), (x_ - padding, y_ - padding, self._Width + padding * 2, self._Height + padding * 2), 1)
def Draw(self): if self._ReadOnly == True: self._Labels["Text"].SetColor( SkinManager().GiveColor("ReadOnlyText")) else: self._Labels["Text"].SetColor(SkinManager().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, SkinManager().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, SkinManager().GiveColor('White'), _rect, 0) pygame.draw.rect(self._CanvasHWND, SkinManager().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, SkinManager().GiveColor("Front"), 3, 0, SkinManager().GiveColor("Front"))
class AboveAllPatch(object): _PosX = Width / 2 _PosY = Height / 2 _Width = 50 _Height = 120 _Text = "" _FontObj = fonts["veramono20"] _Parent = None _Color = SkinManager().GiveColor('Text') _ValColor = SkinManager().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)
class ListPageSelector(PageSelector): _BackgroundColor = SkinManager().GiveColor('Front') 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) - 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=SkinManager().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 Init(self): self._CanvasHWND = pygame.Surface((self._Width,self._Height)) self._MsgBox= MessageBox() self._MsgBox._Parent= self self._MsgBox.Init(" ", self._MsgBoxFont) self._SkinManager = SkinManager() self._SkinManager.Init()
def Init(self, text, font_obj, color=SkinManager().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 Label: _PosX=0 _PosY=0 _Width=0 _Height=0 _Text="" _FontObj=None _Color = SkinManager().GiveColor('Text') _CanvasHWND = None _TextSurf = None def __init__(self): pass def Init(self, text, font_obj, color=SkinManager().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 ListScroller(object): _PosX = 0 _PosY = 0 _Width = 7 _Height = 0 _MinHeight = 6 ## tested _Parent = None _Color = SkinManager().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)
class CreateByScreen(FullScreen): _BG = None _BGColor = SkinManager().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 = fonts["varela40"] _BG = None # initial surface _Color = SkinManager().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(SkinManager().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
def ClearCanvas(self): self._CanvasHWND.fill(SkinManager().GiveColor('White'))
class MultiLabel: ##Multi Line Label _PosX=0 _PosY=0 _Width=135 _Height=100 _Text="" _FontObj=None _Color = SkinManager().GiveColor('Text') _CanvasHWND = None _TextSurf = None _MaxWidth = 0 def __init__(self): pass def Init(self,text,font_obj,color=SkinManager().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 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 self.blit_text(self._CanvasHWND,self._Text,(self._PosX,self._PosY),self._FontObj) def Width(self): return self._Width def SetCanvasHWND(self,_canvashwnd): self._CanvasHWND = _canvashwnd def blit_text(self, surface,text, pos, font): color = self._Color words = [word.split(' ') for word in text.splitlines()] space = font.size(' ')[0] max_width = self._Width x ,y = pos row_total_width = 0 lines = 0 for i,line in enumerate(words[:4]): for word in line[:12]: 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 Init(self,text,font_obj,color=SkinManager().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 CounterScreen(FullScreen): _CounterFont = fonts["varela120"] _TextFont1 = fonts["varela15"] _TextFont2 = fonts["varela12"] _TopLabel = None _BottomLabel = None _NumberLabel = None _BGColor = SkinManager().GiveColor('Black') _FGColor = SkinManager().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 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()