mirror of
https://github.com/clockworkpi/launcher.git
synced 2025-12-12 09:48:50 +01:00
Merge pull request #311 from O4k/patch-1
Allows for new skin config.ini format(s)
This commit is contained in:
commit
18c1b186af
@ -29,8 +29,20 @@ class SkinManager(object):
|
||||
def __init__(self):
|
||||
self.Init()
|
||||
|
||||
def ConvertToRGB(self,hexstr):
|
||||
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))
|
||||
|
||||
@ -47,11 +59,21 @@ class SkinManager(object):
|
||||
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,30 +106,20 @@ 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()
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user