diff --git a/parsetools.py b/parsetools.py index 5c8003f..e3c77e2 100644 --- a/parsetools.py +++ b/parsetools.py @@ -1107,12 +1107,18 @@ class ThemeException(Exception): def themeChecker(theme): - needs = [ + needs = [ "main/size", "main/icon", "main/windowtitle", "main/style", + "main/fonts", "main/background-image", + "main/sounds/namealarm", + "main/sounds/alertsound", + "main/sounds/memosound", + "main/sounds/ceasesound", + "main/sounds/honk", "main/menubar/style", "main/menu/menuitem", "main/menu/style", diff --git a/pesterchum.py b/pesterchum.py index 1c4071e..a523d06 100755 --- a/pesterchum.py +++ b/pesterchum.py @@ -1540,6 +1540,8 @@ class PesterWindow(MovingWindow): # Load font QtGui.QFontDatabase.addApplicationFont( os.path.join("fonts", "alternian", "AllisDaedric-VYWz.otf") + # ~lisanne "alternian lol" TODO: make the parsetools 'alternianTagBegin' lex part use the theme's "main/alternian-font-family" value instead of just assuming "AllisDaedric" + # This way themes can change what the alternian font looks like ) self.pcUpdate[str, str].connect(self.updateMsg) @@ -1990,7 +1992,26 @@ class PesterWindow(MovingWindow): self.choosetheme = PesterChooseTheme(self.config, self.theme, self) self.choosetheme.exec() + + def initTheme(self, theme): + # First doing the fonts because any style may depend on it + QtGui.QFontDatabase.removeAllApplicationFonts() # GOODBYE previous fonts + QtGui.QFontDatabase.addApplicationFont( + os.path.join("fonts", "alternian", "AllisDaedric-VYWz.otf") + ) # haha oops we still need that one!!! for now!! (check `~lisanne "alternian lol" TODO` up above) + + for font_path in theme["main/fonts"]: + # ~lisanne : loads fonts from the `main/fonts` key in a theme + # Note that this wont load fonts from inherited themes + # that seems fine imo, esp since u could still load them through `$path/../inheritedtheme/somefont.ttf` + PchumLog.debug("Loading font "+ font_path) + fontID = QtGui.QFontDatabase.addApplicationFont(font_path) + if fontID == -1: + PchumLog.error("Failed loading font: "+font_path) + else: + PchumLog.debug(f"Font families: {(QtGui.QFontDatabase.applicationFontFamilies(fontID))} (id: {fontID})") + self.resize(*theme["main/size"]) self.setWindowIcon(PesterIcon(theme["main/icon"])) self.setWindowTitle(theme["main/windowtitle"]) diff --git a/themes/pesterchum/style.js b/themes/pesterchum/style.js index 4841a12..8cf9291 100755 --- a/themes/pesterchum/style.js +++ b/themes/pesterchum/style.js @@ -2,6 +2,7 @@ {"style": "background-repeat: no-repeat;", "background-image": "$path/pcbg.png", "size": [232, 380], + "fonts": [], "icon": "$path/trayicon.png", "newmsgicon": "$path/trayicon2.png", "windowtitle": "PESTERCHUM 6.0", diff --git a/user_profile.py b/user_profile.py index 25abf07..143c92a 100644 --- a/user_profile.py +++ b/user_profile.py @@ -984,12 +984,23 @@ class pesterTheme(dict): raise e return v - def pathHook(self, d): - for k, v in d.items(): - if isinstance(v, str): - s = Template(v) - d[k] = s.safe_substitute(path=self.path) - return d + def pathHook(self, dict): + # This converts strings containing $path into the proper paths + # Honestly ive never even seen this Template stuff before. very funky! + for key, value in dict.items(): + if isinstance(value, str): + templ = Template(value) + dict[key] = templ.safe_substitute(path=self.path) + elif isinstance(value, list): + # ~lisanne : for dealing with 'main/fonts' which is an array which contains filepaths with $ + # probably good to have for future additions + for idx,item in enumerate(value): + item = value[idx] + if isinstance(item, str): + # not very DRY of me >:3c + templ = Template(item) + value[idx] = templ.safe_substitute(path=self.path) + return dict def get(self, key, default): keys = key.split("/")