Fix updating syntax colours (#1171)
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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.
|
||||
"""
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user