Merge pull request #15 from cuu/master

Add SkinManager to all parts
This commit is contained in:
clockworkpi 2018-05-31 23:43:21 +08:00 committed by GitHub
commit ee896f8202
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 116 additions and 38 deletions

View File

@ -65,7 +65,6 @@ class ListItem(object):
_PlayingProcess = 0 # 0 - 100
_Parent = None
_ActiveBackgroundColor = pygame.Color(232,232,232)
def __init__(self):
self._Labels = {}

3
skin/default/config.cfg Normal file
View File

@ -0,0 +1,3 @@
[Colors]
High = #33a6ff
White = #ffffff

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

File diff suppressed because one or more lines are too long

View File

@ -53,7 +53,8 @@ class FootBar:
_IconHeight = 18
_LabelFont = fonts["veramono10"]
_State = "normal"
_BgColor = pygame.Color(255,255,255)
_SkinManager = None
def __init__(self):
self._Icons = {}
@ -105,7 +106,7 @@ class FootBar:
def UpdateNavText(self,texts):
self._State = "tips"
my_text = self._LabelFont.render(texts,True,(83,83,83))
my_text = self._LabelFont.render(texts,True,self._SkinManager.GiveColor("Text"))
"""
_w = 0
for i, x in enumerate(("b","a","y","x")):
@ -120,7 +121,7 @@ class FootBar:
final_piece = ""
for i ,v in enumerate(texts):
text_slice = texts[:i+1]
my_text = self._LabelFont.render(text_slice,True,(83,83,83))
my_text = self._LabelFont.render(text_slice,True, self._SkinManager.GiveColor("Text"))
final_piece = text_slice
if my_text.get_width() >= left_width:
break
@ -139,7 +140,7 @@ class FootBar:
def ClearCanvas(self):
self._CanvasHWND.fill( self._BgColor )
self._CanvasHWND.fill( self._SkinManager.GiveColor("White") )
self._Icons["round_corners"].NewCoord(5,self._Height -5 )
self._Icons["round_corners"]._IconIndex = 2
@ -178,7 +179,7 @@ class FootBar:
self._Icons[x].Draw()
pygame.draw.line(self._CanvasHWND,(169,169,169),(0,0),(Width,0),self._BorderWidth)
pygame.draw.line(self._CanvasHWND,self._SkinManager.GiveColor("Line"),(0,0),(Width,0),self._BorderWidth)
if self._HWND != None:
self._HWND.blit(self._CanvasHWND,(self._PosX,Height - self._Height,Width,self._BarHeight))

View File

@ -9,7 +9,6 @@ import sys
from libs import easing
from datetime import datetime
import base64
from beeprint import pp
## local package import
@ -26,6 +25,8 @@ from label import Label
from untitled_icon import UntitledIcon
from Emulator import MyEmulator
from skin_manager import SkinManager
class MessageBox(Label):
_Parent = None
@ -122,6 +123,7 @@ class MainScreen(object):
_MsgBox = None
_MsgBoxFont = fonts["veramono20"]
_IconFont = fonts["varela15"]
_SkinManager = None
def __init__(self):
self._Pages = []
@ -132,6 +134,9 @@ class MainScreen(object):
self._MsgBox= MessageBox()
self._MsgBox._Parent= self
self._MsgBox.Init(" ", self._MsgBoxFont)
self._SkinManager = SkinManager()
self._SkinManager.Init()
def FartherPages(self):
self._PageMax = len(self._Pages)

View File

@ -9,18 +9,14 @@ import math
from libs import easing
import base64
from beeprint import pp
#import base64
#from beeprint import pp
### local import
from constants import ALIGN,icon_width,icon_height,Width,Height,ICON_TYPES
from util_funcs import midRect
from keys_def import CurKeys
from blueselector_b64 import blueselector
blueselector_surf = pygame.image.frombuffer(base64.b64decode(blueselector),(92,92),"RGBA")
from icon_pool import MyIconPool
class PageStack:
def __init__(self):
@ -107,6 +103,7 @@ class Page(object):
_SelectedIconTopOffset=20
_EasingDur = 30
def __init__(self):
self._Icons = []
@ -132,9 +129,9 @@ class Page(object):
if cnt >= (self._IconNumbers -1):
break
cnt+=1
#icon的实际surface是要另行赋值的,这儿只创建空的icon,输入了坐标等信息
ps = PageSelector()
ps._IconSurf = blueselector_surf
ps._IconSurf = MyIconPool._Icons["blueselector"]
ps._Parent = self
ps.Init(icon_width/2, TitleBar._BarHeight+icon_height/2,92,92,128)
self._Ps = ps
@ -158,7 +155,7 @@ class Page(object):
it._ImgSurf = pygame.transform.smoothscale(it._ImgSurf,(it._Width,it._Height))
ps = PageSelector()
ps._IconSurf = blueselector_surf
ps._IconSurf = MyIconPool._Icons["blueselector"]
ps._Parent = self
ps.Init(start_x,start_y,92,92,128)
@ -211,7 +208,7 @@ class Page(object):
it._ImgSurf = pygame.transform.smoothscale(it._ImgSurf,(it._Width,it._Height))
ps = PageSelector()
ps._IconSurf = blueselector_surf
ps._IconSurf = MyIconPool._Icons["blueselector"]
ps._Parent = self
ps.Init(start_x,start_y,92,92,128)
@ -247,9 +244,9 @@ class Page(object):
if cnt >= (self._IconNumbers -1):
break
cnt+=1
#icon的实际surface是要另行赋值的,这儿只创建空的icon,输入了坐标等信息
ps = PageSelector()
ps._IconSurf = blueselector_surf
ps._IconSurf = MyIconPool._Icons["blueselector"]
ps._Parent = self
ps.Init(icon_width/2,icon_height/2,92,92,128)
self._Ps = ps
@ -291,7 +288,7 @@ class Page(object):
ps = PageSelector()
ps._IconSurf = blueselector_surf
ps._IconSurf = MyIconPool._Icons["blueselector"]
ps._Parent = self
ps.Init(start_x,start_y-self._SelectedIconTopOffset,92,92,128)
@ -324,10 +321,10 @@ class Page(object):
it._Index = i
it.Init(start_x+i*icon_width,start_y,icon_width,icon_height,0)
self._Icons.append(it)
#icon的实际surface是要另行赋值的,这儿只创建空的icon,输入了坐标等信息
if self._IconNumbers > 0:
ps = PageSelector()
ps._IconSurf = blueselector_surf
ps._IconSurf = MyIconPool._Icons["blueselector"]
ps._Parent = self
ps.Init(start_x,start_y,icon_width+4,icon_height+4,128)
self._Ps = ps
@ -546,7 +543,7 @@ class Page(object):
print("OnTopLevel ",self._Screen._PageIndex)
def ClearCanvas(self):
self._CanvasHWND.fill((255,255,255))
self._CanvasHWND.fill(self._Screen._SkinManager.GiveColor("White"))
def ClearIcons(self):
for i in range(0,self._IconNumbers):

74
sys.py/UI/skin_manager.py Normal file
View File

@ -0,0 +1,74 @@
# -*- coding: utf-8 -*-
import pygame
import config
import ConfigParser
class CaseConfigParser(ConfigParser.SafeConfigParser):
def optionxform(self, optionstr):
return optionstr
class SkinManager(object):
"""
_HighColor = pygame.Color(51,166,255) # #33a6ff
_TextColor = pygame.Color(83,83,83) # #535353
_FrontColor = pygame.Color(131,199,219) ## light blue,#83c7db
_URLColor = pygame.Color(51,166,255) ## blue more #33a6ff
_LineColor = pygame.Color(169,169,169) # #a9a9a9
_TitleBgColor = pygame.Color(228,228,228) # #e4e4e4
_ActiveColor = pygame.Color(175,90,0) ## light brown #af5a00
"""
_Colors = {}
_Config = None
def __init__(self):
pass
def ConvertToRGB(self,hexstr):
h = hexstr.lstrip('#')
return tuple(int(h[i:i+2], 16) for i in (0, 2 ,4))
def Init(self):
Colors = {}
Colors["High"] = pygame.Color(51,166,255)
Colors["Text"] = pygame.Color(83,83,83)
Colors["Front"] = pygame.Color(131,199,219)
Colors["URL"] = pygame.Color(51,166,255)
Colors["Line"] = pygame.Color(169,169,169)
Colors["TitleBg"] = pygame.Color(228,228,228)
Colors["Active"] = pygame.Color(175,90,0)
Colors["White"] = pygame.Color(255,255,255)
self._Colors = Colors
self._Config = CaseConfigParser()
fname = "../skin/"+config.SKIN+"/config.cfg"
try:
self._Config.read(fname)
except Exception,e:
print("read skin config.cfg error %s" % str(e))
return
else:
if "Colors" in self._Config.sections():
colour_opts = self._Config.options("Colors")
# print(colour_opts)
for i in self._Colors:
if i in colour_opts:
try:
self._Colors[i] = self.ConvertToRGB(self._Config.get("Colors",i))
except Exception,e:
print("error in ConvertToRGB %s" % str(e))
continue
def GiveColor(self,name):
if name in self._Colors:
return self._Colors[name]
else:
return pygame.Color(255,0,0)

View File

@ -31,13 +31,9 @@ class TitleBar:
_PosY = 0
_Width = Width
_Height = 25
_IconColor = pygame.Color(114,114,144)
_BarHeight = 24.5
_LOffset = 3
_ROffset = 3
_BgColor = pygame.Color(228,228,228)
_TxtColor = pygame.Color(83,83,83)
_BottomLineColor = pygame.Color(169,169,169)
_Icons = {}
_icon_width = 18
_icon_height = 18
@ -45,8 +41,11 @@ class TitleBar:
_CanvasHWND = None
_HWND = None
_Title = ""
_InLowBackLight = -1
_SkinManager = None
def __init__(self):
self._Icons = {}
@ -240,7 +239,7 @@ class TitleBar:
print( wifi_strength())
def ClearCanvas(self):
self._CanvasHWND.fill( self._BgColor )
self._CanvasHWND.fill( self._SkinManager.GiveColor("TitleBg") )
self._Icons["round_corners"].NewCoord(5,5)
self._Icons["round_corners"]._IconIndex = 0
@ -267,10 +266,10 @@ class TitleBar:
time_text_size = fonts["varela12"].size(cur_time)
title_text_size = fonts["varela16"].size(title)
self._CanvasHWND.blit(fonts["varela16"].render(title,True,self._TxtColor),midRect(title_text_size[0]/2+self._LOffset,
self._CanvasHWND.blit(fonts["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(fonts["varela12"].render(cur_time,True,self._TxtColor),midRect(Width-time_text_size[0]/2-self._ROffset,
self._CanvasHWND.blit(fonts["varela12"].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))
@ -302,7 +301,7 @@ class TitleBar:
self._Icons["battery"].Draw()
pygame.draw.line(self._CanvasHWND,self._BottomLineColor,(0,self._BarHeight),(self._Width,self._BarHeight),self._BorderWidth)
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))

View File

@ -11,10 +11,10 @@ from datetime import datetime
import base64
from beeprint import pp
from util_funcs import midRect
from util_funcs import midRect,SkinMap
from fonts import fonts
BlankPng = "gameshell/blank.png" ## 80x80
BlankPng = SkinMap("gameshell/blank.png") ## 80x80
## use blank circle as bg, Two alpha As Icon Label
#Upper and Lower
class UntitledIcon(object):

View File

@ -322,7 +322,9 @@ def big_loop():
main_screen.ReadTheDirIntoPages("../Menu",0,None)
main_screen.FartherPages()
title_bar._SkinManager = main_screen._SkinManager
foot_bar._SkinManager = main_screen._SkinManager
sound_patch = SoundPatch()
sound_patch._Parent = main_screen
sound_patch.Init()