Fix updating syntax colours (#1171)

This commit is contained in:
Veronica Berglyd Olsen
2022-10-25 23:56:07 +02:00
parent 88183cdc39
commit 8d7ebefa65
3 changed files with 38 additions and 25 deletions
+22 -18
View File
@@ -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))
+14 -6
View File
@@ -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.
"""
+2 -1
View File
@@ -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()