diff --git a/novelwriter/dialogs/preferences.py b/novelwriter/dialogs/preferences.py index 6236a2a5..6b9dbd9f 100644 --- a/novelwriter/dialogs/preferences.py +++ b/novelwriter/dialogs/preferences.py @@ -78,15 +78,35 @@ class GuiPreferences(PagedDialog): self.resize(*self.mainConf.getPreferencesSize()) # Settings - self.updateTheme = False - self.updateSyntax = False - self.needsRestart = False - self.refreshTree = False + self._updateTheme = False + self._updateSyntax = False + self._needsRestart = False + self._refreshTree = False logger.debug("GuiPreferences initialisation complete") return + ## + # Properties + ## + + @property + def updateTheme(self): + return self._updateTheme + + @property + def updateSyntax(self): + return self._updateSyntax + + @property + def needsRestart(self): + return self._needsRestart + + @property + def refreshTree(self): + return self._refreshTree + ## # Slots ## @@ -275,12 +295,12 @@ class GuiPreferencesGeneral(QWidget): emphLabels = self.emphLabels.isChecked() # Update Flags - self.prefsGui.updateTheme |= self.mainConf.guiTheme != guiTheme - self.prefsGui.updateSyntax |= self.mainConf.guiSyntax != guiSyntax - self.prefsGui.needsRestart |= self.mainConf.guiLang != guiLang - self.prefsGui.needsRestart |= self.mainConf.guiFont != guiFont - self.prefsGui.needsRestart |= self.mainConf.guiFontSize != guiFontSize - self.prefsGui.refreshTree |= self.mainConf.emphLabels != emphLabels + self.prefsGui._updateTheme |= self.mainConf.guiTheme != guiTheme + self.prefsGui._updateSyntax |= self.mainConf.guiSyntax != guiSyntax + self.prefsGui._needsRestart |= self.mainConf.guiLang != guiLang + self.prefsGui._needsRestart |= self.mainConf.guiFont != guiFont + self.prefsGui._needsRestart |= self.mainConf.guiFontSize != guiFontSize + self.prefsGui._refreshTree |= self.mainConf.emphLabels != emphLabels self.mainConf.guiLang = guiLang self.mainConf.guiTheme = guiTheme diff --git a/novelwriter/gui/doceditor.py b/novelwriter/gui/doceditor.py index 179cab17..3e4a965f 100644 --- a/novelwriter/gui/doceditor.py +++ b/novelwriter/gui/doceditor.py @@ -2526,12 +2526,14 @@ class GuiDocEditSearch(QFrame): # Slots ## + @pyqtSlot() def _doClose(self): """Hide the search/replace bar. """ self.closeSearch() return + @pyqtSlot() def _doSearch(self): """Call the search action function for the document editor. """ @@ -2542,12 +2544,14 @@ class GuiDocEditSearch(QFrame): self.docEditor.findNext() return + @pyqtSlot() def _doReplace(self): """Call the replace action function for the document editor. """ self.docEditor.replaceNext() return + @pyqtSlot(bool) def _doToggleReplace(self, theState): """Toggle the show/hide of the replace box. """ @@ -2562,36 +2566,42 @@ class GuiDocEditSearch(QFrame): self.docEditor.updateDocMargins() return + @pyqtSlot(bool) def _doToggleCase(self, theState): """Enable/disable case sensitive mode. """ self.isCaseSense = theState return + @pyqtSlot(bool) def _doToggleWord(self, theState): """Enable/disable whole word search mode. """ self.isWholeWord = theState return + @pyqtSlot(bool) def _doToggleRegEx(self, theState): """Enable/disable regular expression search mode. """ self.isRegEx = theState return + @pyqtSlot(bool) def _doToggleLoop(self, theState): """Enable/disable looping the search. """ self.doLoop = theState return + @pyqtSlot(bool) def _doToggleProject(self, theState): """Enable/disable continuing search in next project file. """ self.doNextFile = theState return + @pyqtSlot(bool) def _doToggleMatchCap(self, theState): """Enable/disable preserving capitalisation when replacing. """ @@ -2804,18 +2814,21 @@ class GuiDocEditHeader(QWidget): # Slots ## + @pyqtSlot() def _editDocument(self): """Open the edit item dialog from the main GUI. """ self.mainGui.editItemLabel(self._docHandle) return + @pyqtSlot() def _searchDocument(self): """Toggle the visibility of the search box. """ self.docEditor.toggleSearch() return + @pyqtSlot() def _closeDocument(self): """Trigger the close editor on the main window. """ @@ -2826,6 +2839,7 @@ class GuiDocEditHeader(QWidget): self.minmaxButton.setVisible(False) return + @pyqtSlot() def _minmaxDocument(self): """Switch on or off Focus Mode. """ diff --git a/novelwriter/gui/docviewer.py b/novelwriter/gui/docviewer.py index 1b1a5b53..0437363e 100644 --- a/novelwriter/gui/docviewer.py +++ b/novelwriter/gui/docviewer.py @@ -889,12 +889,14 @@ class GuiDocViewHeader(QWidget): # Slots ## + @pyqtSlot() def _closeDocument(self): """Trigger the close editor/viewer on the main window. """ self.mainGui.closeDocViewer() return + @pyqtSlot() def _refreshDocument(self): """Reload the content of the document. """ @@ -1124,6 +1126,7 @@ class GuiDocViewFooter(QWidget): # Slots ## + @pyqtSlot() def _doShowHide(self): """Toggle the expand/collapse of the panel. """ @@ -1131,6 +1134,7 @@ class GuiDocViewFooter(QWidget): self.viewMeta.setVisible(not isVisible) return + @pyqtSlot(bool) def _doToggleSticky(self, theState): """Toggle the sticky flag for the reference panel. """ @@ -1140,6 +1144,7 @@ class GuiDocViewFooter(QWidget): self.viewMeta.refreshReferences(self.docViewer.docHandle()) return + @pyqtSlot(bool) def _doToggleComments(self, theState): """Toggle the view comment button and reload the document. """ @@ -1147,6 +1152,7 @@ class GuiDocViewFooter(QWidget): self.docViewer.reloadText() return + @pyqtSlot(bool) def _doToggleSynopsis(self, theState): """Toggle the view synopsis button and reload the document. """ diff --git a/novelwriter/gui/theme.py b/novelwriter/gui/theme.py index a352636e..93c26440 100644 --- a/novelwriter/gui/theme.py +++ b/novelwriter/gui/theme.py @@ -246,12 +246,9 @@ class GuiTheme: # Icons self.iconCache.loadTheme(self.themeIcons) - # Apply Styles - qApp.setPalette(self._guiPalette) - # Update Dependant Colours - backCol = qApp.palette().window().color() - textCol = qApp.palette().windowText().color() + backCol = self._guiPalette.window().color() + textCol = self._guiPalette.windowText().color() backLCol = backCol.lightnessF() textLCol = textCol.lightnessF() @@ -263,6 +260,9 @@ class GuiTheme: self.helpText = [int(255*helpLCol)]*3 + # Apply Styles + qApp.setPalette(self._guiPalette) + return True def loadSyntax(self): diff --git a/novelwriter/guimain.py b/novelwriter/guimain.py index b1467695..58c1e72a 100644 --- a/novelwriter/guimain.py +++ b/novelwriter/guimain.py @@ -918,6 +918,8 @@ class GuiMain(QMainWindow): self.projView.populateTree() if dlgConf.updateTheme: + # We are doing this manually instead of connecting to + # qApp.paletteChanged since the processing order matters self.mainTheme.loadTheme() self.docEditor.updateTheme() self.docViewer.updateTheme() diff --git a/tests/test_dialogs/test_dlg_preferences.py b/tests/test_dialogs/test_dlg_preferences.py index 4b077699..17dd6246 100644 --- a/tests/test_dialogs/test_dlg_preferences.py +++ b/tests/test_dialogs/test_dlg_preferences.py @@ -69,14 +69,24 @@ def testDlgPreferences_Main(qtbot, monkeypatch, fncDir, outDir, refDir): monkeypatch.setattr(GuiPreferences, "result", lambda *a: QDialog.Accepted) monkeypatch.setattr(nwGUI.docEditor.spEnchant, "listDictionaries", lambda: [("en", "none")]) - nwGUI.mainMenu.aPreferences.activate(QAction.Trigger) - qtbot.waitUntil(lambda: getGuiItem("GuiPreferences") is not None, timeout=1000) + with monkeypatch.context() as mp: + mp.setattr(GuiPreferences, "updateTheme", lambda *a: True) + mp.setattr(GuiPreferences, "updateSyntax", lambda *a: True) + mp.setattr(GuiPreferences, "needsRestart", lambda *a: True) + mp.setattr(GuiPreferences, "refreshTree", lambda *a: True) + nwGUI.mainMenu.aPreferences.activate(QAction.Trigger) + qtbot.waitUntil(lambda: getGuiItem("GuiPreferences") is not None, timeout=1000) nwPrefs = getGuiItem("GuiPreferences") assert isinstance(nwPrefs, GuiPreferences) nwPrefs.show() assert nwPrefs.mainConf.confPath == fncDir + assert nwPrefs.updateTheme is False + assert nwPrefs.updateSyntax is False + assert nwPrefs.needsRestart is False + assert nwPrefs.refreshTree is False + # General Settings qtbot.wait(KEY_DELAY) tabGeneral = nwPrefs.tabGeneral @@ -220,7 +230,7 @@ def testDlgPreferences_Main(qtbot, monkeypatch, fncDir, outDir, refDir): nwPrefs._tabBox.setCurrentWidget(tabQuote) monkeypatch.setattr(GuiQuoteSelect, "selectedQuote", "'") - monkeypatch.setattr(GuiQuoteSelect, "exec_", lambda *args: QDialog.Accepted) + monkeypatch.setattr(GuiQuoteSelect, "exec_", lambda *a: QDialog.Accepted) qtbot.mouseClick(tabQuote.btnDoubleStyleC, Qt.LeftButton) # Save and Check Config