From 639f4c17002a0f6f3922f0443fa652929265a091 Mon Sep 17 00:00:00 2001 From: O4k <47993923+O4k@users.noreply.github.com> Date: Sat, 21 Dec 2019 10:32:14 -0800 Subject: [PATCH] Allows for new skin config.ini format(s) The new code checks for a config.ini file in the Skin's folder. Then it checks for a "Font_Paths" section where it replaces the default fonts with the names of the new fonts listed in the Config. You will have to add the desired fonts to the truetype folder within the skin folder and update the config to match the fonts you have added. If you remove the existing fonts in that folder, the launcher will not load if there is a problem with the config file. Note that the system-wide font name variables do not change, but their referenced file does. The new Config file would look something like this: [Font_Paths] varela = Roboto-Black veramono = Roboto-Regular noto = Roboto-Bold notocjk = Roboto-Light [Colors] High = #f0ffff Text = #ffffff ReadOnlyText = #ffffff Front = #614f7d URL = #f0ffff Line = #614f7d TitleBg = #111013 Active = #ff70ba Disabled = #e6e6ff White = #111013 Black = #614f7d --- sys.py/UI/skin_manager.py | 54 +++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/sys.py/UI/skin_manager.py b/sys.py/UI/skin_manager.py index 7064d4e..7b8b441 100644 --- a/sys.py/UI/skin_manager.py +++ b/sys.py/UI/skin_manager.py @@ -28,9 +28,21 @@ class SkinManager(object): def __init__(self): self.Init() + + def configExists(self): + if FileExists(config.SKIN+"/config.ini"): + self._Config = CaseConfigParser() + fname = config.SKIN+"/config.ini" + try: + return self._Config.read(fname) + except Exception, e: + print("skin config.ini read error %s" % str(e)) + return + else: + print("no skin config.ini file to read") + return def ConvertToRGB(self,hexstr): - h = hexstr.lstrip('#') return tuple(int(h[i:i+2], 16) for i in (0, 2 ,4)) @@ -40,18 +52,28 @@ class SkinManager(object): if not SkinManager._Fonts: self.SetFonts() - def SetFonts(self): + 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 - + + if self.configExists(): + if "Font_Paths" in self._Config.sections(): + font_opts = self._Config.options("Font_Paths") + for i in fonts_path: + if i in font_opts: + try: + fonts_path[i] = skinpath+"/"+self._Config.get("Font_Paths", i)+".ttf" + except Exception, e: + print("error in Font_Paths %s" % str(e)) + continue + for i in range(10,29): self._Fonts["varela%d"%i] = pygame.font.Font(fonts_path["varela"],i) @@ -84,29 +106,19 @@ class SkinManager(object): Colors["White"] = pygame.Color(255, 255, 255) Colors["Black"] = pygame.Color(0, 0, 0) - SkinManager._Colors = Colors - - self._Config = CaseConfigParser() - - fname = config.SKIN+"/config.ini" - - try: - self._Config.read(fname) - except Exception, e: - print("read skin config.cfg error %s" % str(e)) - return - else: + if self.configExists(): if "Colors" in self._Config.sections(): colour_opts = self._Config.options("Colors") -# print(colour_opts) - for i in SkinManager._Colors: + for i in Colors: if i in colour_opts: try: - SkinManager._Colors[i] = self.ConvertToRGB( + Colors[i] = self.ConvertToRGB( self._Config.get("Colors", i)) except Exception, e: print("error in ConvertToRGB %s" % str(e)) continue + + SkinManager._Colors = Colors def GiveFont(self,name): return SkinManager._Fonts[name] @@ -161,5 +173,3 @@ def InitMySkinManager(): InitMySkinManager() - -