From 8d7ebefa65fc353c40591eac003d8d318d87e56e Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Tue, 25 Oct 2022 23:56:07 +0200 Subject: [PATCH] Fix updating syntax colours (#1171) --- novelwriter/gui/doceditor.py | 40 ++++++++++++++++++++---------------- novelwriter/gui/theme.py | 20 ++++++++++++------ novelwriter/guimain.py | 3 ++- 3 files changed, 38 insertions(+), 25 deletions(-) diff --git a/novelwriter/gui/doceditor.py b/novelwriter/gui/doceditor.py index 8db3734a..179cab17 100644 --- a/novelwriter/gui/doceditor.py +++ b/novelwriter/gui/doceditor.py @@ -173,6 +173,7 @@ class GuiDocEditor(QTextEdit): self.wCounterSel.signals.countsReady.connect(self._updateSelCounts) # Finalise + self.updateSyntaxColours() self.initEditor() logger.debug("GuiDocEditor initialisation complete") @@ -214,6 +215,27 @@ class GuiDocEditor(QTextEdit): self.docFooter.updateTheme() return + def updateSyntaxColours(self): + """Update the syntax highlighting theme. + """ + mainPalette = self.palette() + mainPalette.setColor(QPalette.Window, QColor(*self.mainTheme.colBack)) + mainPalette.setColor(QPalette.Base, QColor(*self.mainTheme.colBack)) + mainPalette.setColor(QPalette.Text, QColor(*self.mainTheme.colText)) + self.setPalette(mainPalette) + + docPalette = self.viewport().palette() + docPalette.setColor(QPalette.Base, QColor(*self.mainTheme.colBack)) + docPalette.setColor(QPalette.Text, QColor(*self.mainTheme.colText)) + self.viewport().setPalette(docPalette) + + self.docHeader.matchColours() + self.docFooter.matchColours() + + self.highLight.initHighlighter() + + return + def initEditor(self): """Initialise or re-initialise the editor with the user's settings. This function is both called when the editor is @@ -260,21 +282,6 @@ class GuiDocEditor(QTextEdit): theFont.setPointSize(self.mainConf.textSize) self.setFont(theFont) - # Set the widget colours to match syntax theme - mainPalette = self.palette() - mainPalette.setColor(QPalette.Window, QColor(*self.mainTheme.colBack)) - mainPalette.setColor(QPalette.Base, QColor(*self.mainTheme.colBack)) - mainPalette.setColor(QPalette.Text, QColor(*self.mainTheme.colText)) - self.setPalette(mainPalette) - - docPalette = self.viewport().palette() - docPalette.setColor(QPalette.Base, QColor(*self.mainTheme.colBack)) - docPalette.setColor(QPalette.Text, QColor(*self.mainTheme.colText)) - self.viewport().setPalette(docPalette) - - self.docHeader.matchColours() - self.docFooter.matchColours() - # Set default text margins # Due to cursor visibility, a part of the margin must be # allocated to the document itself. See issue #1112. @@ -309,9 +316,6 @@ class GuiDocEditor(QTextEdit): # Refresh the tab stops self.setTabStopDistance(self.mainConf.getTabWidth()) - # Initialise the syntax highlighter - self.highLight.initHighlighter() - # Configure word count timer self.wcInterval = self.mainConf.wordCountTimer self.wcTimerDoc.setInterval(int(self.wcInterval*1000)) diff --git a/novelwriter/gui/theme.py b/novelwriter/gui/theme.py index 1c52f7dd..5761f28f 100644 --- a/novelwriter/gui/theme.py +++ b/novelwriter/gui/theme.py @@ -130,6 +130,7 @@ class GuiTheme: self.updateFont() self.updateTheme() + self.updateSyntax() # Icon Functions self.getIcon = self.iconCache.getIcon @@ -221,12 +222,6 @@ class GuiTheme: self.loadTheme() self.iconCache.updateTheme() - self.syntaxFile = self._availSyntax.get(self.guiSyntax, None) - if self.syntaxFile is None: - logger.error("Could not find syntax theme '%s'", self.guiSyntax) - else: - self.loadSyntax() - # Update dependant colours backCol = qApp.palette().window().color() textCol = qApp.palette().windowText().color() @@ -243,6 +238,19 @@ class GuiTheme: return True + def updateSyntax(self): + """Update the syntac theme from theme files. + """ + self.guiSyntax = self.mainConf.guiSyntax + + self.syntaxFile = self._availSyntax.get(self.guiSyntax, None) + if self.syntaxFile is None: + logger.error("Could not find syntax theme '%s'", self.guiSyntax) + else: + self.loadSyntax() + + return True + def loadTheme(self): """Load the currently specified GUI theme. """ diff --git a/novelwriter/guimain.py b/novelwriter/guimain.py index a6ac3407..93cdbcc2 100644 --- a/novelwriter/guimain.py +++ b/novelwriter/guimain.py @@ -929,7 +929,8 @@ class GuiMain(QMainWindow): self.mainStatus.updateTheme() if dlgConf.updateSyntax: - pass + self.mainTheme.updateSyntax() + self.docEditor.updateSyntaxColours() self.docEditor.initEditor() self.docViewer.initViewer()