|
@@ -4,6 +4,8 @@ import pygame
|
|
|
import config
|
|
|
import ConfigParser
|
|
|
|
|
|
+from util_funcs import FileExists
|
|
|
+
|
|
|
class CaseConfigParser(ConfigParser.SafeConfigParser):
|
|
|
def optionxform(self, optionstr):
|
|
|
return optionstr
|
|
@@ -21,7 +23,9 @@ class SkinManager(object):
|
|
|
|
|
|
_Colors = {}
|
|
|
_Config = None
|
|
|
-
|
|
|
+ _Fonts = {}
|
|
|
+ DefaultSkin = "../skin/default"
|
|
|
+
|
|
|
def __init__(self):
|
|
|
self.Init()
|
|
|
|
|
@@ -33,7 +37,39 @@ class SkinManager(object):
|
|
|
def Init(self):
|
|
|
if not SkinManager._Colors:
|
|
|
self.SetColors()
|
|
|
+ if not SkinManager._Fonts:
|
|
|
+ self.SetFonts()
|
|
|
+
|
|
|
+ def SetFonts(self):
|
|
|
+ if not pygame.font.get_init():
|
|
|
+ pygame.font.init()
|
|
|
+
|
|
|
+ skinpath = config.SKIN+"/truetype"
|
|
|
+ fonts_path = {}
|
|
|
+ fonts_path["varela"] = "%s/VarelaRound-Regular.ttf" % skinpath
|
|
|
+ print(fonts_path["varela"])
|
|
|
+ fonts_path["veramono"] = "%s/VeraMono.ttf" % skinpath
|
|
|
+ fonts_path["noto"] = "%s/NotoSansMono-Regular.ttf" % skinpath
|
|
|
+ fonts_path["notocjk"] = "%s/NotoSansCJK-Regular.ttf" % skinpath
|
|
|
+
|
|
|
+ for i in range(10,29):
|
|
|
+ self._Fonts["varela%d"%i] = pygame.font.Font(fonts_path["varela"],i)
|
|
|
+
|
|
|
+ self._Fonts["varela34"] = pygame.font.Font(fonts_path["varela"],34)
|
|
|
+ self._Fonts["varela40"] = pygame.font.Font(fonts_path["varela"],40)
|
|
|
+ self._Fonts["varela120"] = pygame.font.Font(fonts_path["varela"],120)
|
|
|
+
|
|
|
+ for i in range(10,26):
|
|
|
+ self._Fonts["veramono%d"%i] = pygame.font.Font(fonts_path["veramono"],i)
|
|
|
+
|
|
|
+ for i in range(10,28):
|
|
|
+ self._Fonts["notosansmono%d"%i] = pygame.font.Font(fonts_path["noto"],i)
|
|
|
|
|
|
+ for i in range(10,28):
|
|
|
+ self._Fonts["notosanscjk%d"%i] = pygame.font.Font(fonts_path["notocjk"],i)
|
|
|
+
|
|
|
+ self._Fonts["arial"] = pygame.font.SysFont("arial",16)
|
|
|
+
|
|
|
def SetColors(self):
|
|
|
Colors = {}
|
|
|
Colors["High"] = pygame.Color(51, 166, 255)
|
|
@@ -52,7 +88,7 @@ class SkinManager(object):
|
|
|
|
|
|
self._Config = CaseConfigParser()
|
|
|
|
|
|
- fname = "../skin/"+config.SKIN+"/config.cfg"
|
|
|
+ fname = config.SKIN+"/config.ini"
|
|
|
|
|
|
try:
|
|
|
self._Config.read(fname)
|
|
@@ -72,12 +108,33 @@ class SkinManager(object):
|
|
|
print("error in ConvertToRGB %s" % str(e))
|
|
|
continue
|
|
|
|
|
|
+ def GiveFont(self,name):
|
|
|
+ return SkinManager._Fonts[name]
|
|
|
+
|
|
|
def GiveColor(self,name):
|
|
|
if name in SkinManager._Colors:
|
|
|
return SkinManager._Colors[name]
|
|
|
else:
|
|
|
return pygame.Color(255,0,0)
|
|
|
|
|
|
+ def GiveIcon(self,orig_file_or_dir):
|
|
|
+ #doing a wrapper for items under /home/cpi/apps/Menu/*, to be like Menu/GameShell/*
|
|
|
+ if orig_file_or_dir.startswith("/home/cpi/apps/Menu"):
|
|
|
+ orig_file_or_dir = orig_file_or_dir.replace("/home/cpi/apps/Menu/","../Menu/GameShell/")
|
|
|
+
|
|
|
+ if orig_file_or_dir.startswith(".."):
|
|
|
+ ret = orig_file_or_dir.replace("..",config.SKIN)
|
|
|
+ if FileExists(ret) == False:
|
|
|
+ ret = orig_file_or_dir.replace("..",self.DefaultSkin)
|
|
|
+ else:
|
|
|
+ ret = config.SKIN+"/sys.py/"+orig_file_or_dir
|
|
|
+ if FileExists(ret) == False:
|
|
|
+ ret = self.DefaultSkin+"/sys.py/"+orig_file_or_dir
|
|
|
+
|
|
|
+ if FileExists( ret ):
|
|
|
+ return ret
|
|
|
+ else: ## if not existed both in default or custom skin ,return where it is
|
|
|
+ return orig_file_or_dir
|
|
|
|
|
|
##global MySkinManager Handler
|
|
|
MySkinManager = None
|