From 906cd60ff28a297055642d2ecec13599c24b7a73 Mon Sep 17 00:00:00 2001 From: anne Date: Sun, 25 Jun 2023 00:51:23 +0200 Subject: [PATCH 1/3] implemented theme loading with QFontDatabase by themes with the main/fonts key --- parsetools.py | 8 +++++++- pesterchum.py | 21 +++++++++++++++++++++ themes/pesterchum/style.js | 1 + user_profile.py | 23 +++++++++++++++++------ 4 files changed, 46 insertions(+), 7 deletions(-) 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("/") From 1f1db15075cb9e79dd1b1545d7014c663e3cf306 Mon Sep 17 00:00:00 2001 From: anne Date: Sun, 25 Jun 2023 00:59:59 +0200 Subject: [PATCH 2/3] just a thought :3 --- pesterchum.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pesterchum.py b/pesterchum.py index a523d06..1039bea 100755 --- a/pesterchum.py +++ b/pesterchum.py @@ -1992,11 +1992,9 @@ 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.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) @@ -2005,12 +2003,15 @@ class PesterWindow(MovingWindow): # ~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) + PchumLog.debug("Loading font " + font_path) fontID = QtGui.QFontDatabase.addApplicationFont(font_path) if fontID == -1: - PchumLog.error("Failed loading font: "+font_path) + PchumLog.error("Failed loading font: " + font_path) + # TODO? Maybe make this spawn an error popup else: - PchumLog.debug(f"Font families: {(QtGui.QFontDatabase.applicationFontFamilies(fontID))} (id: {fontID})") + PchumLog.debug( + f"Font families: {(QtGui.QFontDatabase.applicationFontFamilies(fontID))} (id: {fontID})" + ) self.resize(*theme["main/size"]) self.setWindowIcon(PesterIcon(theme["main/icon"])) From a5f3f2fe0ad4d9499e22f29bcd9a52fb3e37e1c7 Mon Sep 17 00:00:00 2001 From: anne Date: Sun, 25 Jun 2023 01:00:44 +0200 Subject: [PATCH 3/3] did git just donk up my commits --- parsetools.py | 2 +- user_profile.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/parsetools.py b/parsetools.py index e3c77e2..777cfe1 100644 --- a/parsetools.py +++ b/parsetools.py @@ -1107,7 +1107,7 @@ class ThemeException(Exception): def themeChecker(theme): - needs = [ + needs = [ "main/size", "main/icon", "main/windowtitle", diff --git a/user_profile.py b/user_profile.py index 143c92a..7076069 100644 --- a/user_profile.py +++ b/user_profile.py @@ -986,15 +986,15 @@ class pesterTheme(dict): def pathHook(self, dict): # This converts strings containing $path into the proper paths - # Honestly ive never even seen this Template stuff before. very funky! + # 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): + # 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