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):
|
def __init__(self):
|
||||||
self.Init()
|
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('#')
|
h = hexstr.lstrip('#')
|
||||||
return tuple(int(h[i:i+2], 16) for i in (0, 2 ,4))
|
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"
|
skinpath = config.SKIN+"/truetype"
|
||||||
fonts_path = {}
|
fonts_path = {}
|
||||||
fonts_path["varela"] = "%s/VarelaRound-Regular.ttf" % skinpath
|
fonts_path["varela"] = "%s/VarelaRound-Regular.ttf" % skinpath
|
||||||
print(fonts_path["varela"])
|
|
||||||
fonts_path["veramono"] = "%s/VeraMono.ttf" % skinpath
|
fonts_path["veramono"] = "%s/VeraMono.ttf" % skinpath
|
||||||
fonts_path["noto"] = "%s/NotoSansMono-Regular.ttf" % skinpath
|
fonts_path["noto"] = "%s/NotoSansMono-Regular.ttf" % skinpath
|
||||||
fonts_path["notocjk"] = "%s/NotoSansCJK-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):
|
for i in range(10,29):
|
||||||
self._Fonts["varela%d"%i] = pygame.font.Font(fonts_path["varela"],i)
|
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["White"] = pygame.Color(255, 255, 255)
|
||||||
Colors["Black"] = pygame.Color(0, 0, 0)
|
Colors["Black"] = pygame.Color(0, 0, 0)
|
||||||
|
|
||||||
SkinManager._Colors = Colors
|
if self.configExists():
|
||||||
|
|
||||||
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 "Colors" in self._Config.sections():
|
if "Colors" in self._Config.sections():
|
||||||
colour_opts = self._Config.options("Colors")
|
colour_opts = self._Config.options("Colors")
|
||||||
# print(colour_opts)
|
for i in Colors:
|
||||||
for i in SkinManager._Colors:
|
|
||||||
if i in colour_opts:
|
if i in colour_opts:
|
||||||
try:
|
try:
|
||||||
SkinManager._Colors[i] = self.ConvertToRGB(
|
Colors[i] = self.ConvertToRGB(
|
||||||
self._Config.get("Colors", i))
|
self._Config.get("Colors", i))
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
print("error in ConvertToRGB %s" % str(e))
|
print("error in ConvertToRGB %s" % str(e))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
SkinManager._Colors = Colors
|
||||||
|
|
||||||
def GiveFont(self,name):
|
def GiveFont(self,name):
|
||||||
return SkinManager._Fonts[name]
|
return SkinManager._Fonts[name]
|
||||||
|
|
||||||
@ -161,5 +173,3 @@ def InitMySkinManager():
|
|||||||
|
|
||||||
|
|
||||||
InitMySkinManager()
|
InitMySkinManager()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user