From a703e0bb7d6aa148dda4e8b57bf59822b466407c Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Sun, 26 Oct 2025 02:40:50 +0100 Subject: [PATCH] Update tests and add more debug output --- novelwriter/core/project.py | 2 ++ novelwriter/gui/doceditor.py | 12 ++++++++++-- novelwriter/gui/docviewer.py | 6 +++++- novelwriter/gui/docviewerpanel.py | 6 ++++++ novelwriter/gui/itemdetails.py | 1 + novelwriter/gui/noveltree.py | 5 +++-- novelwriter/gui/outline.py | 6 ++++++ novelwriter/gui/projtree.py | 3 +++ novelwriter/gui/search.py | 2 ++ novelwriter/gui/sidebar.py | 3 ++- novelwriter/gui/statusbar.py | 2 ++ novelwriter/tools/manuscript.py | 15 +++++++++++---- novelwriter/tools/manussettings.py | 9 ++++++++- tests/test_tools/test_tools_manuscript.py | 6 ++++++ 14 files changed, 67 insertions(+), 11 deletions(-) diff --git a/novelwriter/core/project.py b/novelwriter/core/project.py index 2a10fd92..44bf3590 100644 --- a/novelwriter/core/project.py +++ b/novelwriter/core/project.py @@ -552,6 +552,8 @@ class NWProject: def updateTheme(self) -> None: """Update theme elements.""" + logger.debug("Theme Update: NWProject") + self._data.itemStatus.refreshIcons() self._data.itemImport.refreshIcons() diff --git a/novelwriter/gui/doceditor.py b/novelwriter/gui/doceditor.py index 72e7577f..d7a96765 100644 --- a/novelwriter/gui/doceditor.py +++ b/novelwriter/gui/doceditor.py @@ -292,6 +292,8 @@ class GuiDocEditor(QPlainTextEdit): def updateTheme(self) -> None: """Update theme elements.""" + logger.debug("Theme Update: GuiDocEditor") + self.docSearch.updateTheme() self.docHeader.updateTheme() self.docFooter.updateTheme() @@ -2478,8 +2480,9 @@ class GuiDocToolBar(QWidget): def updateTheme(self) -> None: """Initialise GUI elements that depend on specific settings.""" - syntax = SHARED.theme.syntaxTheme + logger.debug("Theme Update: GuiDocToolBar") + syntax = SHARED.theme.syntaxTheme palette = self.palette() palette.setColor(QPalette.ColorRole.Window, syntax.back) palette.setColor(QPalette.ColorRole.WindowText, syntax.text) @@ -2716,8 +2719,9 @@ class GuiDocEditSearch(QFrame): def updateTheme(self) -> None: """Update theme elements.""" - palette = QApplication.palette() + logger.debug("Theme Update: GuiDocEditSearch") + palette = QApplication.palette() self.setPalette(palette) self.searchBox.setPalette(palette) self.replaceBox.setPalette(palette) @@ -2961,6 +2965,8 @@ class GuiDocEditHeader(QWidget): def updateTheme(self) -> None: """Update theme elements.""" + logger.debug("Theme Update: GuiDocEditHeader") + self.tbButton.setThemeIcon("fmt_toolbar", "blue") self.outlineButton.setThemeIcon("list", "blue") self.searchButton.setThemeIcon("search", "blue") @@ -3150,6 +3156,8 @@ class GuiDocEditFooter(QWidget): def updateTheme(self) -> None: """Update theme elements.""" + logger.debug("Theme Update: GuiDocEditFooter") + iPx = round(0.9*SHARED.theme.baseIconHeight) self.linesIcon.setPixmap(SHARED.theme.getPixmap("lines", (iPx, iPx))) self.wordsIcon.setPixmap(SHARED.theme.getPixmap("stats", (iPx, iPx))) diff --git a/novelwriter/gui/docviewer.py b/novelwriter/gui/docviewer.py index fc7bef81..5cd44e27 100644 --- a/novelwriter/gui/docviewer.py +++ b/novelwriter/gui/docviewer.py @@ -141,6 +141,7 @@ class GuiDocViewer(QTextBrowser): def updateTheme(self) -> None: """Update theme elements.""" + logger.debug("Theme Update: GuiDocViewer") self.docHeader.updateTheme() self.docFooter.updateTheme() @@ -724,6 +725,8 @@ class GuiDocViewHeader(QWidget): def updateTheme(self) -> None: """Update theme elements.""" + logger.debug("Theme Update: GuiDocViewHeader") + self.outlineButton.setThemeIcon("list", "blue") self.backButton.setThemeIcon("chevron_left", "blue") self.forwardButton.setThemeIcon("chevron_right", "blue") @@ -910,7 +913,8 @@ class GuiDocViewFooter(QWidget): def updateTheme(self) -> None: """Update theme elements.""" - # Icons + logger.debug("Theme Update: GuiDocViewFooter") + fPx = int(0.9*SHARED.theme.fontPixelSize) bulletIcon = SHARED.theme.getToggleIcon("bullet", (fPx, fPx), "blue") diff --git a/novelwriter/gui/docviewerpanel.py b/novelwriter/gui/docviewerpanel.py index 8ac9816a..9f3fd209 100644 --- a/novelwriter/gui/docviewerpanel.py +++ b/novelwriter/gui/docviewerpanel.py @@ -106,6 +106,8 @@ class GuiDocViewerPanel(QWidget): def updateTheme(self, updateTabs: bool = True) -> None: """Update theme elements.""" + logger.debug("Theme Update: GuiDocViewerPanel") + self.optsButton.setThemeIcon("more_vertical") self.optsButton.setStyleSheet(SHARED.theme.getStyleSheet(STYLES_MIN_TOOLBUTTON)) self.mainTabs.setStyleSheet(SHARED.theme.getStyleSheet(STYLES_FLAT_TABS)) @@ -270,6 +272,8 @@ class _ViewPanelBackRefs(QTreeWidget): def updateTheme(self) -> None: """Update theme elements.""" + logger.debug("Theme Update: _ViewPanelBackRefs") + self._editIcon = SHARED.theme.getIcon("edit", "green") self._viewIcon = SHARED.theme.getIcon("view", "blue") for i in range(self.topLevelItemCount()): @@ -400,6 +404,8 @@ class _ViewPanelKeyWords(QTreeWidget): def updateTheme(self) -> None: """Update theme elements.""" + logger.debug("Theme Update: _ViewPanelKeyWords") + self._classIcon = SHARED.theme.getIcon(nwLabels.CLASS_ICON[self._class], "root") self._editIcon = SHARED.theme.getIcon("edit", "green") self._viewIcon = SHARED.theme.getIcon("view", "blue") diff --git a/novelwriter/gui/itemdetails.py b/novelwriter/gui/itemdetails.py index d087f742..697d8b8c 100644 --- a/novelwriter/gui/itemdetails.py +++ b/novelwriter/gui/itemdetails.py @@ -216,6 +216,7 @@ class GuiItemDetails(QWidget): def updateTheme(self) -> None: """Update theme elements.""" + logger.debug("Theme Update: GuiItemDetails") self.updateViewBox(self._handle) def updateViewBox(self, tHandle: str | None) -> None: diff --git a/novelwriter/gui/noveltree.py b/novelwriter/gui/noveltree.py index a5521ef8..feb5e703 100644 --- a/novelwriter/gui/noveltree.py +++ b/novelwriter/gui/noveltree.py @@ -89,6 +89,7 @@ class GuiNovelView(QWidget): def updateTheme(self) -> None: """Update theme elements.""" + logger.debug("Theme Update: GuiNovelView") self.novelBar.updateTheme() def initSettings(self) -> None: @@ -244,12 +245,12 @@ class GuiNovelToolBar(QWidget): def updateTheme(self) -> None: """Update theme elements.""" - # Icons + logger.debug("Theme Update: GuiNovelToolBar") + self.tbNovel.setThemeIcon("cls_novel", "red") self.tbRefresh.setThemeIcon("refresh", "green") self.tbMore.setThemeIcon("more_vertical") - # StyleSheets buttonStyle = SHARED.theme.getStyleSheet(STYLES_MIN_TOOLBUTTON) self.tbNovel.setStyleSheet(buttonStyle) self.tbRefresh.setStyleSheet(buttonStyle) diff --git a/novelwriter/gui/outline.py b/novelwriter/gui/outline.py index 4a76712f..3a97ec35 100644 --- a/novelwriter/gui/outline.py +++ b/novelwriter/gui/outline.py @@ -103,6 +103,8 @@ class GuiOutlineView(QWidget): def updateTheme(self) -> None: """Update theme elements.""" + logger.debug("Theme Update: GuiOutlineView") + self.outlineBar.updateTheme() self.outlineTree.updateTheme() self.outlineTree.refreshTree( @@ -258,6 +260,8 @@ class GuiOutlineToolBar(QToolBar): def updateTheme(self) -> None: """Update theme elements.""" + logger.debug("Theme Update: GuiOutlineToolBar") + self.setStyleSheet("QToolBar {border: 0px;}") self.novelValue.refreshNovelList() self.aRefresh.setIcon(SHARED.theme.getIcon("refresh", "green")) @@ -454,6 +458,8 @@ class GuiOutlineTree(QTreeWidget): def updateTheme(self) -> None: """Update theme elements.""" + logger.debug("Theme Update: GuiOutlineTree") + iType = nwItemType.FILE iClass = nwItemClass.NO_CLASS iLayout = nwItemLayout.DOCUMENT diff --git a/novelwriter/gui/projtree.py b/novelwriter/gui/projtree.py index ab79cfb6..758b15cd 100644 --- a/novelwriter/gui/projtree.py +++ b/novelwriter/gui/projtree.py @@ -138,6 +138,7 @@ class GuiProjectView(QWidget): def updateTheme(self) -> None: """Update theme elements.""" + logger.debug("Theme Update: GuiProjectView") self.projBar.updateTheme() def initSettings(self) -> None: @@ -346,6 +347,8 @@ class GuiProjectToolBar(QWidget): def updateTheme(self) -> None: """Update theme elements.""" + logger.debug("Theme Update: GuiProjectToolBar") + buttonStyle = SHARED.theme.getStyleSheet(STYLES_MIN_TOOLBUTTON) self.tbQuick.setStyleSheet(buttonStyle) self.tbMoveU.setStyleSheet(buttonStyle) diff --git a/novelwriter/gui/search.py b/novelwriter/gui/search.py index 5313d676..e49770b3 100644 --- a/novelwriter/gui/search.py +++ b/novelwriter/gui/search.py @@ -158,6 +158,8 @@ class GuiProjectSearch(QWidget): def updateTheme(self) -> None: """Update theme elements.""" + logger.debug("Theme Update: GuiProjectSearch") + palette = QApplication.palette() colBase = palette.base().color().name(QtHexArgb) colFocus = palette.highlight().color().name(QtHexArgb) diff --git a/novelwriter/gui/sidebar.py b/novelwriter/gui/sidebar.py index 6440fc15..8e6acfd3 100644 --- a/novelwriter/gui/sidebar.py +++ b/novelwriter/gui/sidebar.py @@ -129,8 +129,9 @@ class GuiSideBar(QWidget): def updateTheme(self) -> None: """Initialise GUI elements that depend on specific settings.""" - buttonStyle = SHARED.theme.getStyleSheet(STYLES_BIG_TOOLBUTTON) + logger.debug("Theme Update: GuiSideBar") + buttonStyle = SHARED.theme.getStyleSheet(STYLES_BIG_TOOLBUTTON) self.tbProject.setStyleSheet(buttonStyle) self.tbNovel.setStyleSheet(buttonStyle) self.tbSearch.setStyleSheet(buttonStyle) diff --git a/novelwriter/gui/statusbar.py b/novelwriter/gui/statusbar.py index 0c8288b5..3578e3e0 100644 --- a/novelwriter/gui/statusbar.py +++ b/novelwriter/gui/statusbar.py @@ -133,6 +133,8 @@ class GuiMainStatus(QStatusBar): def updateTheme(self) -> None: """Update theme elements.""" + logger.debug("Theme Update: GuiMainStatus") + iPx = SHARED.theme.baseIconHeight self.langIcon.setPixmap(SHARED.theme.getPixmap("language", (iPx, iPx))) self.statsIcon.setPixmap(SHARED.theme.getPixmap("stats", (iPx, iPx))) diff --git a/novelwriter/tools/manuscript.py b/novelwriter/tools/manuscript.py index 9646140e..e3c5679b 100644 --- a/novelwriter/tools/manuscript.py +++ b/novelwriter/tools/manuscript.py @@ -263,10 +263,7 @@ class GuiManuscript(NToolDialog): def updateTheme(self, *, init: bool = False) -> None: """Update theme elements.""" - self.tbAdd.setThemeIcon("add", "green") - self.tbDel.setThemeIcon("remove", "red") - self.tbCopy.setThemeIcon("copy", "blue") - self.tbEdit.setThemeIcon("edit", "green") + logger.debug("Theme Update: GuiManuscript, init=%s", init) if not init: self.btnPreview.updateIcon() @@ -274,6 +271,11 @@ class GuiManuscript(NToolDialog): self.btnBuild.updateIcon() self.btnClose.updateIcon() + self.tbAdd.setThemeIcon("add", "green") + self.tbDel.setThemeIcon("remove", "red") + self.tbCopy.setThemeIcon("copy", "blue") + self.tbEdit.setThemeIcon("edit", "green") + buttonStyle = SHARED.theme.getStyleSheet(STYLES_MIN_TOOLBUTTON) self.tbAdd.setStyleSheet(buttonStyle) self.tbDel.setStyleSheet(buttonStyle) @@ -641,6 +643,7 @@ class _DetailsWidget(QWidget): def updateTheme(self) -> None: """Update theme elements.""" if self._build: + logger.debug("Theme Update: _DetailsWidget") self.updateInfo(self._build) @@ -709,6 +712,7 @@ class _OutlineWidget(QWidget): def updateTheme(self) -> None: """Update theme elements.""" + logger.debug("Theme Update: _OutlineWidget") self.updateOutline(self._outline, force=True) ## @@ -845,6 +849,8 @@ class _PreviewWidget(QTextBrowser): def updateTheme(self) -> None: """Update theme elements.""" + logger.debug("Theme Update: _PreviewWidget") + palette = QApplication.palette() palette.setColor(QPalette.ColorRole.Window, palette.toolTipBase().color()) palette.setColor(QPalette.ColorRole.WindowText, palette.toolTipText().color()) @@ -984,6 +990,7 @@ class _StatsWidget(QWidget): def updateTheme(self) -> None: """Update theme elements.""" + logger.debug("Theme Update: _StatsWidget") self.toggleButton.setThemeIcon("unfold") ## diff --git a/novelwriter/tools/manussettings.py b/novelwriter/tools/manussettings.py index 318c21f1..dd5bc50c 100644 --- a/novelwriter/tools/manussettings.py +++ b/novelwriter/tools/manussettings.py @@ -173,6 +173,8 @@ class GuiBuildSettings(NToolDialog): def updateTheme(self, *, init: bool = False) -> None: """Update theme elements.""" + logger.debug("Theme Update: GuiBuildSettings, init=%s", init) + if not init: self.btnApply.updateIcon() self.btnSave.updateIcon() @@ -405,6 +407,8 @@ class _FilterTab(NFixedPage): def updateTheme(self, *, init: bool = False) -> None: """Update theme elements.""" + logger.debug("Theme Update: _FilterTab, init=%s", init) + if not init: self._statusFlags[self.F_FILTERED] = SHARED.theme.getIcon("filter", "orange") self._statusFlags[self.F_INCLUDED] = SHARED.theme.getIcon("pin", "blue") @@ -805,6 +809,8 @@ class _HeadingsTab(NScrollablePage): def updateTheme(self) -> None: """Update theme elements.""" + logger.debug("Theme Update: _HeadingsTab") + self.btnPart.setThemeIcon("edit", "green") self.btnChapter.setThemeIcon("edit", "green") self.btnUnnumbered.setThemeIcon("edit", "green") @@ -1310,12 +1316,13 @@ class _FormattingTab(NScrollableForm): def updateTheme(self) -> None: """Update theme elements.""" - iPx = SHARED.theme.baseIconHeight + logger.debug("Theme Update: _FormattingTab") self.ignoredKeywordsButton.setThemeIcon("add", "green") self.btnTextFont.setThemeIcon("font") self.btnPageHeader.setThemeIcon("revert", "green") + iPx = SHARED.theme.baseIconHeight self.pixT.setPixmap(SHARED.theme.getPixmap("margin_top", (iPx, iPx))) self.pixB.setPixmap(SHARED.theme.getPixmap("margin_bottom", (iPx, iPx))) self.pixL.setPixmap(SHARED.theme.getPixmap("margin_left", (iPx, iPx))) diff --git a/tests/test_tools/test_tools_manuscript.py b/tests/test_tools/test_tools_manuscript.py index 0d74dbff..ac70c626 100644 --- a/tests/test_tools/test_tools_manuscript.py +++ b/tests/test_tools/test_tools_manuscript.py @@ -72,6 +72,9 @@ def testToolManuscript_Init(monkeypatch, qtbot, nwGUI, projPath, mockRnd): manus.btnPreview.click() assert manus.docPreview.toPlainText().strip() == allText + # Trigger a theme update, which is only a visual refresh, but it shouldn't crash + manus.updateTheme() + nwGUI.closeProject() # This should auto-close the manuscript tool # qtbot.stop() @@ -148,6 +151,9 @@ def testToolManuscript_Builds(qtbot, nwGUI, projPath): assert new is not None assert new.name == "Test Build 2" + # Trigger a theme update, which should propagate to settings + manus.updateTheme() + # Close the dialog should also close the child dialogs manus.btnClose.click() if isinstance(bSettings, GuiBuildSettings):