From ff85c6688f1183a4f67c97de52a54db1a11ade18 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Thu, 12 Jun 2025 17:59:38 +0200 Subject: [PATCH] Add methods to refresh status icons on theme change --- novelwriter/core/project.py | 22 ++++++++++++++-------- novelwriter/core/status.py | 10 ++++++++++ novelwriter/guimain.py | 1 + 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/novelwriter/core/project.py b/novelwriter/core/project.py index ed5a8284..e86b744b 100644 --- a/novelwriter/core/project.py +++ b/novelwriter/core/project.py @@ -483,14 +483,14 @@ class NWProject: def setDefaultStatusImport(self) -> None: """Set the default status and importance values.""" - self._data.itemStatus.add(None, self.tr("New"), (120, 120, 120), "STAR", 0) - self._data.itemStatus.add(None, self.tr("Note"), (205, 171, 143), "TRIANGLE", 0) - self._data.itemStatus.add(None, self.tr("Draft"), (143, 240, 164), "CIRCLE_T", 0) - self._data.itemStatus.add(None, self.tr("Finished"), (249, 240, 107), "STAR", 0) - self._data.itemImport.add(None, self.tr("New"), (120, 120, 120), "SQUARE", 0) - self._data.itemImport.add(None, self.tr("Minor"), (220, 138, 221), "BLOCK_2", 0) - self._data.itemImport.add(None, self.tr("Major"), (220, 138, 221), "BLOCK_3", 0) - self._data.itemImport.add(None, self.tr("Main"), (220, 138, 221), "BLOCK_4", 0) + self._data.itemStatus.add(None, self.tr("New"), "faded", "STAR", 0) + self._data.itemStatus.add(None, self.tr("Note"), "red", "TRIANGLE", 0) + self._data.itemStatus.add(None, self.tr("Draft"), "yellow", "CIRCLE_T", 0) + self._data.itemStatus.add(None, self.tr("Finished"), "green", "STAR", 0) + self._data.itemImport.add(None, self.tr("New"), "purple", "SQUARE", 0) + self._data.itemImport.add(None, self.tr("Minor"), "purple", "BLOCK_2", 0) + self._data.itemImport.add(None, self.tr("Major"), "purple", "BLOCK_3", 0) + self._data.itemImport.add(None, self.tr("Main"), "purple", "BLOCK_4", 0) return def setProjectLang(self, language: str | None) -> None: @@ -547,6 +547,12 @@ class NWProject: self._tree.refreshAllItems() return + def updateTheme(self) -> None: + """Update theme elements.""" + self._data.itemStatus.refreshIcons() + self._data.itemImport.refreshIcons() + return + def localLookup(self, word: str | int) -> str: """Look up a word or number in the translation map for the project and return it. The variable is cast to a string before diff --git a/novelwriter/core/status.py b/novelwriter/core/status.py index 1fdf5396..bcee828c 100644 --- a/novelwriter/core/status.py +++ b/novelwriter/core/status.py @@ -189,6 +189,16 @@ class NWStatus: logger.error("Could not parse entry %s", str(data)) return None + def refreshIcons(self) -> None: + """Refresh all icons.""" + for entry in self._store.values(): + if entry.theme != CUSTOM_COL: + print("<", entry.color.name(QColor.NameFormat.HexRgb)) + entry.color = SHARED.theme.parseColor(entry.theme) + print(">", entry.color.name(QColor.NameFormat.HexRgb)) + entry.icon = NWStatus.createIcon(self._height, entry.color, entry.shape) + return + @staticmethod def createIcon(height: int, color: QColor, shape: nwStatusShape) -> QIcon: """Generate an icon for a status label.""" diff --git a/novelwriter/guimain.py b/novelwriter/guimain.py index 25f997f6..680f35d5 100644 --- a/novelwriter/guimain.py +++ b/novelwriter/guimain.py @@ -913,6 +913,7 @@ class GuiMain(QMainWindow): def refreshThemeColors(self, syntax: bool = False, force: bool = False) -> None: """Refresh the GUI theme.""" SHARED.theme.loadTheme(force=force) + SHARED.project.updateTheme() self.setPalette(QApplication.palette()) self.docEditor.updateTheme() self.docViewer.updateTheme()