From fa046897dc7597e53890fe8fdd09f13e94e74cc8 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Wed, 8 Jan 2025 00:21:08 +0100 Subject: [PATCH] Fix a few icons and add icon theme setting --- novelwriter/config.py | 3 +++ novelwriter/gui/noveltree.py | 2 +- novelwriter/gui/theme.py | 25 +++++++++++++++---------- novelwriter/tools/manuscript.py | 2 +- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/novelwriter/config.py b/novelwriter/config.py index 5c7bf0a0..697dd711 100644 --- a/novelwriter/config.py +++ b/novelwriter/config.py @@ -114,6 +114,7 @@ class Config: self.guiLocale = self._qLocale.name() self.guiTheme = "default" # GUI theme self.guiSyntax = "default_light" # Syntax theme + self.guiIcons = "material_rounded_normal" # Icons theme self.guiFont = QFont() # Main GUI font self.guiScale = 1.0 # Set automatically by Theme class self.hideVScroll = False # Hide vertical scroll bars on main widgets @@ -605,6 +606,7 @@ class Config: self.setGuiFont(conf.rdStr(sec, "font", "")) self.guiTheme = conf.rdStr(sec, "theme", self.guiTheme) self.guiSyntax = conf.rdStr(sec, "syntax", self.guiSyntax) + self.guiIcons = conf.rdStr(sec, "icons", self.guiIcons) self.guiLocale = conf.rdStr(sec, "localisation", self.guiLocale) self.hideVScroll = conf.rdBool(sec, "hidevscroll", self.hideVScroll) self.hideHScroll = conf.rdBool(sec, "hidehscroll", self.hideHScroll) @@ -716,6 +718,7 @@ class Config: "font": self.guiFont.toString(), "theme": str(self.guiTheme), "syntax": str(self.guiSyntax), + "icons": str(self.guiIcons), "localisation": str(self.guiLocale), "hidevscroll": str(self.hideVScroll), "hidehscroll": str(self.hideHScroll), diff --git a/novelwriter/gui/noveltree.py b/novelwriter/gui/noveltree.py index d33e3d2e..96617d71 100644 --- a/novelwriter/gui/noveltree.py +++ b/novelwriter/gui/noveltree.py @@ -267,7 +267,7 @@ class GuiNovelToolBar(QWidget): def updateTheme(self) -> None: """Update theme elements.""" # Icons - self.tbNovel.setThemeIcon("cls_novel") + self.tbNovel.setThemeIcon("cls_novel", "red") self.tbRefresh.setThemeIcon("refresh", "green") self.tbMore.setThemeIcon("more_vertical") diff --git a/novelwriter/gui/theme.py b/novelwriter/gui/theme.py index 5dfc079b..f78dde59 100644 --- a/novelwriter/gui/theme.py +++ b/novelwriter/gui/theme.py @@ -307,7 +307,7 @@ class GuiTheme: # Icons defaultIcons = "typicons_light" if backLNess >= 0.5 else "typicons_dark" self.iconCache.loadTheme(self.themeIcons or defaultIcons) - self.iconCache.loadNewTheme("") + self.iconCache.loadNewTheme(CONFIG.guiIcons) # Apply Styles QApplication.setPalette(self._guiPalette) @@ -627,15 +627,20 @@ class GuiIcons: def loadNewTheme(self, iconTheme: str) -> bool: """Load new style theme.""" - themePath = self._iconPath / "material_rounded_normal.icons" - with open(themePath, mode="r", encoding="utf-8") as icons: - for icon in icons: - bits = icon.partition("=") - key = bits[0].strip() - value = bits[2].strip() - if key and value: - if key.startswith("icon:"): - self._svgData[key[5:]] = value.encode("utf-8") + themePath = self._iconPath / f"{iconTheme}.icons" + try: + with open(themePath, mode="r", encoding="utf-8") as icons: + for icon in icons: + bits = icon.partition("=") + key = bits[0].strip() + value = bits[2].strip() + if key and value: + if key.startswith("icon:"): + self._svgData[key[5:]] = value.encode("utf-8") + except Exception: + logger.error("Could not load icon theme settings from: %s", themePath) + logException() + return False return True diff --git a/novelwriter/tools/manuscript.py b/novelwriter/tools/manuscript.py index a5952c3b..7eccec55 100644 --- a/novelwriter/tools/manuscript.py +++ b/novelwriter/tools/manuscript.py @@ -113,7 +113,7 @@ class GuiManuscript(NToolDialog): self.tbAdd.setStyleSheet(buttonStyle) self.tbAdd.clicked.connect(self._createNewBuild) - self.tbDel = NIconToolButton(self, iSz, "remove") + self.tbDel = NIconToolButton(self, iSz, "remove", "red") self.tbDel.setToolTip(self.tr("Delete Selected Build")) self.tbDel.setStyleSheet(buttonStyle) self.tbDel.clicked.connect(self._deleteSelectedBuild)