Make some minor changes and update test coverage

This commit is contained in:
Veronica Berglyd Olsen
2022-10-29 00:38:32 +02:00
parent 9b1c3fece2
commit 4a9ea459fa
6 changed files with 70 additions and 18 deletions
+30 -10
View File
@@ -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
+14
View File
@@ -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.
"""
+6
View File
@@ -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.
"""
+5 -5
View File
@@ -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):
+2
View File
@@ -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()
+13 -3
View File
@@ -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