Make all theme colours actual QColor objects

This commit is contained in:
Veronica Berglyd Olsen
2024-01-19 16:13:12 +01:00
parent ae7c19f923
commit 82c63723a4
11 changed files with 149 additions and 194 deletions
+11 -9
View File
@@ -220,23 +220,25 @@ class GuiAbout(QDialog):
def _setStyleSheet(self) -> None: def _setStyleSheet(self) -> None:
"""Set stylesheet for all browser tabs.""" """Set stylesheet for all browser tabs."""
colHead = SHARED.theme.colHead
colKey = SHARED.theme.colKey
styleSheet = ( styleSheet = (
"h1, h2, h3, h4 {{" "h1, h2, h3, h4 {{"
" color: rgb({hColR},{hColG},{hColB});" " color: rgb({hColR}, {hColG}, {hColB});"
"}}\n" "}}\n"
"a {{" "a {{"
" color: rgb({hColR},{hColG},{hColB});" " color: rgb({hColR}, {hColG}, {hColB});"
"}}\n" "}}\n"
".alt {{" ".alt {{"
" color: rgb({kColR},{kColG},{kColB});" " color: rgb({kColR}, {kColG}, {kColB});"
"}}\n" "}}\n"
).format( ).format(
hColR=SHARED.theme.colHead[0], hColR=colHead.red(),
hColG=SHARED.theme.colHead[1], hColG=colHead.green(),
hColB=SHARED.theme.colHead[2], hColB=colHead.blue(),
kColR=SHARED.theme.colKey[0], kColR=colKey.red(),
kColG=SHARED.theme.colKey[1], kColG=colKey.green(),
kColB=SHARED.theme.colKey[2], kColB=colKey.blue(),
) )
self.pageAbout.document().setDefaultStyleSheet(styleSheet) self.pageAbout.document().setDefaultStyleSheet(styleSheet)
self.pageNotes.document().setDefaultStyleSheet(styleSheet) self.pageNotes.document().setDefaultStyleSheet(styleSheet)
+2 -2
View File
@@ -26,7 +26,7 @@ from __future__ import annotations
import logging import logging
from PyQt5.QtGui import QCloseEvent, QColor, QFont, QKeyEvent, QKeySequence, QPalette from PyQt5.QtGui import QCloseEvent, QFont, QKeyEvent, QKeySequence, QPalette
from PyQt5.QtCore import Qt, pyqtSignal, pyqtSlot from PyQt5.QtCore import Qt, pyqtSignal, pyqtSlot
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QAbstractButton, QComboBox, QCompleter, QDialog, QDialogButtonBox, QAbstractButton, QComboBox, QCompleter, QDialog, QDialogButtonBox,
@@ -62,7 +62,7 @@ class GuiPreferences(QDialog):
font.setPointSizeF(1.25*SHARED.theme.fontPointSize) font.setPointSizeF(1.25*SHARED.theme.fontPointSize)
palette = self.palette() palette = self.palette()
palette.setColor(QPalette.ColorRole.WindowText, QColor(*SHARED.theme.helpText)) palette.setColor(QPalette.ColorRole.WindowText, SHARED.theme.helpText)
self.titleLabel = QLabel(self.tr("Preferences"), self) self.titleLabel = QLabel(self.tr("Preferences"), self)
self.titleLabel.setFont(font) self.titleLabel.setFont(font)
+6 -9
View File
@@ -76,9 +76,9 @@ class NScrollableForm(QScrollArea):
# Setters # Setters
## ##
def setHelpTextStyle(self, color: QColor | list | tuple, scale: float = FONT_SCALE) -> None: def setHelpTextStyle(self, color: QColor, scale: float = FONT_SCALE) -> None:
"""Set the text color for the help text.""" """Set the text color for the help text."""
self._helpCol = color if isinstance(color, QColor) else QColor(*color) self._helpCol = color
self._fontScale = scale self._fontScale = scale
return return
@@ -187,7 +187,7 @@ class NConfigLayout(QGridLayout):
# Getters and Setters # Getters and Setters
## ##
def setHelpTextStyle(self, color: QColor | list | tuple, scale: float = FONT_SCALE) -> None: def setHelpTextStyle(self, color: QColor, scale: float = FONT_SCALE) -> None:
"""Set the text color for the help text.""" """Set the text color for the help text."""
self._helpCol = color if isinstance(color, QColor) else QColor(*color) self._helpCol = color if isinstance(color, QColor) else QColor(*color)
self._fontScale = scale self._fontScale = scale
@@ -328,18 +328,15 @@ class NSimpleLayout(QGridLayout):
class NHelpLabel(QLabel): class NHelpLabel(QLabel):
def __init__(self, text: str, color: QColor | list | tuple, def __init__(self, text: str, color: QColor, scale: float = FONT_SCALE) -> None:
fontSize: float = FONT_SCALE) -> None:
super().__init__(text) super().__init__(text)
qCol = color if isinstance(color, QColor) else QColor(*color)
lblCol = self.palette() lblCol = self.palette()
lblCol.setColor(QPalette.WindowText, qCol) lblCol.setColor(QPalette.WindowText, color)
self.setPalette(lblCol) self.setPalette(lblCol)
lblFont = self.font() lblFont = self.font()
lblFont.setPointSizeF(fontSize*lblFont.pointSizeF()) lblFont.setPointSizeF(scale*lblFont.pointSizeF())
self.setFont(lblFont) self.setFont(lblFont)
self.setWordWrap(True) self.setWordWrap(True)
+2 -2
View File
@@ -67,9 +67,9 @@ class NPagedSideBar(QToolBar):
"""Return a specific button.""" """Return a specific button."""
return self._buttons[buttonId] return self._buttons[buttonId]
def setLabelColor(self, color: list | QColor) -> None: def setLabelColor(self, color: QColor) -> None:
"""Set the text color for the labels.""" """Set the text color for the labels."""
self._labelCol = color if isinstance(color, QColor) else QColor(*color) self._labelCol = color
return return
def addSeparator(self) -> None: def addSeparator(self) -> None:
+17 -16
View File
@@ -276,14 +276,14 @@ class GuiDocEditor(QPlainTextEdit):
def updateSyntaxColours(self) -> None: def updateSyntaxColours(self) -> None:
"""Update the syntax highlighting theme.""" """Update the syntax highlighting theme."""
mainPalette = self.palette() mainPalette = self.palette()
mainPalette.setColor(QPalette.ColorRole.Window, QColor(*SHARED.theme.colBack)) mainPalette.setColor(QPalette.ColorRole.Window, SHARED.theme.colBack)
mainPalette.setColor(QPalette.ColorRole.Base, QColor(*SHARED.theme.colBack)) mainPalette.setColor(QPalette.ColorRole.Base, SHARED.theme.colBack)
mainPalette.setColor(QPalette.ColorRole.Text, QColor(*SHARED.theme.colText)) mainPalette.setColor(QPalette.ColorRole.Text, SHARED.theme.colText)
self.setPalette(mainPalette) self.setPalette(mainPalette)
docPalette = self.viewport().palette() docPalette = self.viewport().palette()
docPalette.setColor(QPalette.ColorRole.Base, QColor(*SHARED.theme.colBack)) docPalette.setColor(QPalette.ColorRole.Base, SHARED.theme.colBack)
docPalette.setColor(QPalette.ColorRole.Text, QColor(*SHARED.theme.colText)) docPalette.setColor(QPalette.ColorRole.Text, SHARED.theme.colText)
self.viewport().setPalette(docPalette) self.viewport().setPalette(docPalette)
self.docHeader.matchColours() self.docHeader.matchColours()
@@ -2326,9 +2326,9 @@ class GuiDocToolBar(QWidget):
def updateTheme(self) -> None: def updateTheme(self) -> None:
"""Initialise GUI elements that depend on specific settings.""" """Initialise GUI elements that depend on specific settings."""
palette = QPalette() palette = QPalette()
palette.setColor(QPalette.ColorRole.Window, QColor(*SHARED.theme.colBack)) palette.setColor(QPalette.ColorRole.Window, SHARED.theme.colBack)
palette.setColor(QPalette.ColorRole.WindowText, QColor(*SHARED.theme.colText)) palette.setColor(QPalette.ColorRole.WindowText, SHARED.theme.colText)
palette.setColor(QPalette.ColorRole.Text, QColor(*SHARED.theme.colText)) palette.setColor(QPalette.ColorRole.Text, SHARED.theme.colText)
self.setPalette(palette) self.setPalette(palette)
self.tbBoldMD.setIcon(SHARED.theme.getIcon("fmt_bold-md")) self.tbBoldMD.setIcon(SHARED.theme.getIcon("fmt_bold-md"))
@@ -2866,10 +2866,11 @@ class GuiDocEditHeader(QWidget):
self.minmaxButton.setIcon(SHARED.theme.getIcon("maximise")) self.minmaxButton.setIcon(SHARED.theme.getIcon("maximise"))
self.closeButton.setIcon(SHARED.theme.getIcon("close")) self.closeButton.setIcon(SHARED.theme.getIcon("close"))
colText = SHARED.theme.colText
buttonStyle = ( buttonStyle = (
"QToolButton {{border: none; background: transparent;}} " "QToolButton {{border: none; background: transparent;}} "
"QToolButton:hover {{border: none; background: rgba({0},{1},{2},0.2);}}" "QToolButton:hover {{border: none; background: rgba({0}, {1}, {2}, 0.2);}}"
).format(*SHARED.theme.colText) ).format(colText.red(), colText.green(), colText.blue())
self.tbButton.setStyleSheet(buttonStyle) self.tbButton.setStyleSheet(buttonStyle)
self.searchButton.setStyleSheet(buttonStyle) self.searchButton.setStyleSheet(buttonStyle)
@@ -2885,9 +2886,9 @@ class GuiDocEditHeader(QWidget):
theme rather than the main GUI. theme rather than the main GUI.
""" """
palette = QPalette() palette = QPalette()
palette.setColor(QPalette.ColorRole.Window, QColor(*SHARED.theme.colBack)) palette.setColor(QPalette.ColorRole.Window, SHARED.theme.colBack)
palette.setColor(QPalette.ColorRole.WindowText, QColor(*SHARED.theme.colText)) palette.setColor(QPalette.ColorRole.WindowText, SHARED.theme.colText)
palette.setColor(QPalette.ColorRole.Text, QColor(*SHARED.theme.colText)) palette.setColor(QPalette.ColorRole.Text, SHARED.theme.colText)
self.setPalette(palette) self.setPalette(palette)
self.itemTitle.setPalette(palette) self.itemTitle.setPalette(palette)
@@ -3093,9 +3094,9 @@ class GuiDocEditFooter(QWidget):
theme rather than the main GUI. theme rather than the main GUI.
""" """
palette = QPalette() palette = QPalette()
palette.setColor(QPalette.ColorRole.Window, QColor(*SHARED.theme.colBack)) palette.setColor(QPalette.ColorRole.Window, SHARED.theme.colBack)
palette.setColor(QPalette.ColorRole.WindowText, QColor(*SHARED.theme.colText)) palette.setColor(QPalette.ColorRole.WindowText, SHARED.theme.colText)
palette.setColor(QPalette.ColorRole.Text, QColor(*SHARED.theme.colText)) palette.setColor(QPalette.ColorRole.Text, SHARED.theme.colText)
self.setPalette(palette) self.setPalette(palette)
self.statusText.setPalette(palette) self.statusText.setPalette(palette)
+32 -66
View File
@@ -65,22 +65,6 @@ class GuiDocHighlighter(QSyntaxHighlighter):
self._hRules: list[tuple[str, dict]] = [] self._hRules: list[tuple[str, dict]] = []
self._hStyles: dict[str, QTextCharFormat] = {} self._hStyles: dict[str, QTextCharFormat] = {}
self._colHead = QColor(0, 0, 0)
self._colHeadH = QColor(0, 0, 0)
self._colEmph = QColor(0, 0, 0)
self._colDialN = QColor(0, 0, 0)
self._colDialD = QColor(0, 0, 0)
self._colDialS = QColor(0, 0, 0)
self._colHidden = QColor(0, 0, 0)
self._colCode = QColor(0, 0, 0)
self._colKey = QColor(0, 0, 0)
self._colVal = QColor(0, 0, 0)
self._colSpell = QColor(0, 0, 0)
self._colError = QColor(0, 0, 0)
self._colRepTag = QColor(0, 0, 0)
self._colMod = QColor(0, 0, 0)
self._colBreak = QColor(0, 0, 0)
self.initHighlighter() self.initHighlighter()
logger.debug("Ready: GuiDocHighlighter") logger.debug("Ready: GuiDocHighlighter")
@@ -93,54 +77,37 @@ class GuiDocHighlighter(QSyntaxHighlighter):
""" """
logger.debug("Setting up highlighting rules") logger.debug("Setting up highlighting rules")
self._colHead = QColor(*SHARED.theme.colHead) colEmph = SHARED.theme.colEmph if CONFIG.highlightEmph else None
self._colHeadH = QColor(*SHARED.theme.colHeadH) colBreak = QColor(SHARED.theme.colEmph)
self._colDialN = QColor(*SHARED.theme.colDialN) colBreak.setAlpha(64)
self._colDialD = QColor(*SHARED.theme.colDialD)
self._colDialS = QColor(*SHARED.theme.colDialS)
self._colHidden = QColor(*SHARED.theme.colHidden)
self._colCode = QColor(*SHARED.theme.colCode)
self._colKey = QColor(*SHARED.theme.colKey)
self._colVal = QColor(*SHARED.theme.colVal)
self._colSpell = QColor(*SHARED.theme.colSpell)
self._colError = QColor(*SHARED.theme.colError)
self._colRepTag = QColor(*SHARED.theme.colRepTag)
self._colMod = QColor(*SHARED.theme.colMod)
self._colBreak = QColor(*SHARED.theme.colEmph)
self._colBreak.setAlpha(64)
self._colEmph = None
if CONFIG.highlightEmph:
self._colEmph = QColor(*SHARED.theme.colEmph)
self._hStyles = {
"header1": self._makeFormat(self._colHead, "bold", 1.8),
"header2": self._makeFormat(self._colHead, "bold", 1.6),
"header3": self._makeFormat(self._colHead, "bold", 1.4),
"header4": self._makeFormat(self._colHead, "bold", 1.2),
"header1h": self._makeFormat(self._colHeadH, "bold", 1.8),
"header2h": self._makeFormat(self._colHeadH, "bold", 1.6),
"header3h": self._makeFormat(self._colHeadH, "bold", 1.4),
"header4h": self._makeFormat(self._colHeadH, "bold", 1.2),
"bold": self._makeFormat(self._colEmph, "bold"),
"italic": self._makeFormat(self._colEmph, "italic"),
"strike": self._makeFormat(self._colHidden, "strike"),
"mspaces": self._makeFormat(self._colError, "errline"),
"nobreak": self._makeFormat(self._colBreak, "background"),
"dialogue1": self._makeFormat(self._colDialN),
"dialogue2": self._makeFormat(self._colDialD),
"dialogue3": self._makeFormat(self._colDialS),
"replace": self._makeFormat(self._colRepTag),
"hidden": self._makeFormat(self._colHidden),
"code": self._makeFormat(self._colCode),
"keyword": self._makeFormat(self._colKey),
"modifier": self._makeFormat(self._colMod),
"value": self._makeFormat(self._colVal, "underline"),
"codevalue": self._makeFormat(self._colVal),
"codeinval": self._makeFormat(None, "errline"),
}
self._hRules = [] self._hRules = []
self._hStyles = {
"header1": self._makeFormat(SHARED.theme.colHead, "bold", 1.8),
"header2": self._makeFormat(SHARED.theme.colHead, "bold", 1.6),
"header3": self._makeFormat(SHARED.theme.colHead, "bold", 1.4),
"header4": self._makeFormat(SHARED.theme.colHead, "bold", 1.2),
"header1h": self._makeFormat(SHARED.theme.colHeadH, "bold", 1.8),
"header2h": self._makeFormat(SHARED.theme.colHeadH, "bold", 1.6),
"header3h": self._makeFormat(SHARED.theme.colHeadH, "bold", 1.4),
"header4h": self._makeFormat(SHARED.theme.colHeadH, "bold", 1.2),
"bold": self._makeFormat(colEmph, "bold"),
"italic": self._makeFormat(colEmph, "italic"),
"strike": self._makeFormat(SHARED.theme.colHidden, "strike"),
"mspaces": self._makeFormat(SHARED.theme.colError, "errline"),
"nobreak": self._makeFormat(colBreak, "background"),
"dialogue1": self._makeFormat(SHARED.theme.colDialN),
"dialogue2": self._makeFormat(SHARED.theme.colDialD),
"dialogue3": self._makeFormat(SHARED.theme.colDialS),
"replace": self._makeFormat(SHARED.theme.colRepTag),
"hidden": self._makeFormat(SHARED.theme.colHidden),
"code": self._makeFormat(SHARED.theme.colCode),
"keyword": self._makeFormat(SHARED.theme.colKey),
"modifier": self._makeFormat(SHARED.theme.colMod),
"value": self._makeFormat(SHARED.theme.colVal, "underline"),
"codevalue": self._makeFormat(SHARED.theme.colVal),
"codeinval": self._makeFormat(None, "errline"),
}
# Multiple or Trailing Spaces # Multiple or Trailing Spaces
if CONFIG.showMultiSpaces: if CONFIG.showMultiSpaces:
@@ -318,7 +285,7 @@ class GuiDocHighlighter(QSyntaxHighlighter):
self.setFormat(xPos, xLen, self._hStyles["value"]) self.setFormat(xPos, xLen, self._hStyles["value"])
else: else:
kwFmt = self.format(xPos) kwFmt = self.format(xPos)
kwFmt.setUnderlineColor(self._colError) kwFmt.setUnderlineColor(SHARED.theme.colError)
kwFmt.setUnderlineStyle(QTextCharFormat.SpellCheckUnderline) kwFmt.setUnderlineStyle(QTextCharFormat.SpellCheckUnderline)
self.setFormat(xPos, xLen, kwFmt) self.setFormat(xPos, xLen, kwFmt)
@@ -402,8 +369,7 @@ class GuiDocHighlighter(QSyntaxHighlighter):
for xPos, xLen in data.spellCheck(text): for xPos, xLen in data.spellCheck(text):
for x in range(xPos, xPos+xLen): for x in range(xPos, xPos+xLen):
spFmt = self.format(x) spFmt = self.format(x)
spFmt.setUnderlineColor(self._colSpell) spFmt.merge(self._hStyles["codeinval"])
spFmt.setUnderlineStyle(QTextCharFormat.SpellCheckUnderline)
self.setFormat(x, 1, spFmt) self.setFormat(x, 1, spFmt)
return return
@@ -431,7 +397,7 @@ class GuiDocHighlighter(QSyntaxHighlighter):
if "strike" in styles: if "strike" in styles:
charFormat.setFontStrikeOut(True) charFormat.setFontStrikeOut(True)
if "errline" in styles: if "errline" in styles:
charFormat.setUnderlineColor(self._colError) charFormat.setUnderlineColor(SHARED.theme.colError)
charFormat.setUnderlineStyle(QTextCharFormat.SpellCheckUnderline) charFormat.setUnderlineStyle(QTextCharFormat.SpellCheckUnderline)
if "underline" in styles: if "underline" in styles:
charFormat.setFontUnderline(True) charFormat.setFontUnderline(True)
+46 -39
View File
@@ -33,7 +33,7 @@ from typing import TYPE_CHECKING
from PyQt5.QtCore import pyqtSignal, pyqtSlot, QPoint, QSize, Qt, QUrl from PyQt5.QtCore import pyqtSignal, pyqtSlot, QPoint, QSize, Qt, QUrl
from PyQt5.QtGui import ( from PyQt5.QtGui import (
QColor, QCursor, QFont, QMouseEvent, QPalette, QResizeEvent, QTextCursor, QCursor, QFont, QMouseEvent, QPalette, QResizeEvent, QTextCursor,
QTextOption QTextOption
) )
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
@@ -149,14 +149,14 @@ class GuiDocViewer(QTextBrowser):
# Set the widget colours to match syntax theme # Set the widget colours to match syntax theme
mainPalette = self.palette() mainPalette = self.palette()
mainPalette.setColor(QPalette.ColorRole.Window, QColor(*SHARED.theme.colBack)) mainPalette.setColor(QPalette.ColorRole.Window, SHARED.theme.colBack)
mainPalette.setColor(QPalette.ColorRole.Base, QColor(*SHARED.theme.colBack)) mainPalette.setColor(QPalette.ColorRole.Base, SHARED.theme.colBack)
mainPalette.setColor(QPalette.ColorRole.Text, QColor(*SHARED.theme.colText)) mainPalette.setColor(QPalette.ColorRole.Text, SHARED.theme.colText)
self.setPalette(mainPalette) self.setPalette(mainPalette)
docPalette = self.viewport().palette() docPalette = self.viewport().palette()
docPalette.setColor(QPalette.ColorRole.Base, QColor(*SHARED.theme.colBack)) docPalette.setColor(QPalette.ColorRole.Base, SHARED.theme.colBack)
docPalette.setColor(QPalette.ColorRole.Text, QColor(*SHARED.theme.colText)) docPalette.setColor(QPalette.ColorRole.Text, SHARED.theme.colText)
self.viewport().setPalette(docPalette) self.viewport().setPalette(docPalette)
self.docHeader.matchColours() self.docHeader.matchColours()
@@ -463,7 +463,13 @@ class GuiDocViewer(QTextBrowser):
"""Generate an appropriate style sheet for the document viewer, """Generate an appropriate style sheet for the document viewer,
based on the current syntax highlighter theme, based on the current syntax highlighter theme,
""" """
pTheme = SHARED.theme colText = SHARED.theme.colText
colHead = SHARED.theme.colHead
colVal = SHARED.theme.colVal
colEmph = SHARED.theme.colEmph
colKey = SHARED.theme.colKey
colHidden = SHARED.theme.colHidden
colMod = SHARED.theme.colMod
styleSheet = ( styleSheet = (
"body {{" "body {{"
" color: rgb({tColR}, {tColG}, {tColB});" " color: rgb({tColR}, {tColG}, {tColB});"
@@ -490,27 +496,27 @@ class GuiDocViewer(QTextBrowser):
" text-align: center;" " text-align: center;"
"}}\n" "}}\n"
).format( ).format(
tColR=pTheme.colText[0], tColR=colText.red(),
tColG=pTheme.colText[1], tColG=colText.green(),
tColB=pTheme.colText[2], tColB=colText.blue(),
hColR=pTheme.colHead[0], hColR=colHead.red(),
hColG=pTheme.colHead[1], hColG=colHead.green(),
hColB=pTheme.colHead[2], hColB=colHead.blue(),
aColR=pTheme.colVal[0], aColR=colVal.red(),
aColG=pTheme.colVal[1], aColG=colVal.green(),
aColB=pTheme.colVal[2], aColB=colVal.blue(),
eColR=pTheme.colEmph[0], eColR=colEmph.red(),
eColG=pTheme.colEmph[1], eColG=colEmph.green(),
eColB=pTheme.colEmph[2], eColB=colEmph.blue(),
kColR=pTheme.colKey[0], kColR=colKey.red(),
kColG=pTheme.colKey[1], kColG=colKey.green(),
kColB=pTheme.colKey[2], kColB=colKey.blue(),
cColR=pTheme.colHidden[0], cColR=colHidden.red(),
cColG=pTheme.colHidden[1], cColG=colHidden.green(),
cColB=pTheme.colHidden[2], cColB=colHidden.blue(),
mColR=pTheme.colMod[0], mColR=colMod.red(),
mColG=pTheme.colMod[1], mColG=colMod.green(),
mColB=pTheme.colMod[2], mColB=colMod.blue(),
) )
self.document().setDefaultStyleSheet(styleSheet) self.document().setDefaultStyleSheet(styleSheet)
@@ -744,10 +750,11 @@ class GuiDocViewHeader(QWidget):
self.refreshButton.setIcon(SHARED.theme.getIcon("refresh")) self.refreshButton.setIcon(SHARED.theme.getIcon("refresh"))
self.closeButton.setIcon(SHARED.theme.getIcon("close")) self.closeButton.setIcon(SHARED.theme.getIcon("close"))
colText = SHARED.theme.colText
buttonStyle = ( buttonStyle = (
"QToolButton {{border: none; background: transparent;}} " "QToolButton {{border: none; background: transparent;}} "
"QToolButton:hover {{border: none; background: rgba({0},{1},{2},0.2);}}" "QToolButton:hover {{border: none; background: rgba({0}, {1}, {2}, 0.2);}}"
).format(*SHARED.theme.colText) ).format(colText.red(), colText.green(), colText.blue())
self.backButton.setStyleSheet(buttonStyle) self.backButton.setStyleSheet(buttonStyle)
self.forwardButton.setStyleSheet(buttonStyle) self.forwardButton.setStyleSheet(buttonStyle)
@@ -763,9 +770,9 @@ class GuiDocViewHeader(QWidget):
theme rather than the main GUI. theme rather than the main GUI.
""" """
palette = QPalette() palette = QPalette()
palette.setColor(QPalette.ColorRole.Window, QColor(*SHARED.theme.colBack)) palette.setColor(QPalette.ColorRole.Window, SHARED.theme.colBack)
palette.setColor(QPalette.ColorRole.WindowText, QColor(*SHARED.theme.colText)) palette.setColor(QPalette.ColorRole.WindowText, SHARED.theme.colText)
palette.setColor(QPalette.ColorRole.Text, QColor(*SHARED.theme.colText)) palette.setColor(QPalette.ColorRole.Text, SHARED.theme.colText)
self.setPalette(palette) self.setPalette(palette)
self.docTitle.setPalette(palette) self.docTitle.setPalette(palette)
return return
@@ -937,11 +944,11 @@ class GuiDocViewFooter(QWidget):
self.showComments.setIcon(bulletIcon) self.showComments.setIcon(bulletIcon)
self.showSynopsis.setIcon(bulletIcon) self.showSynopsis.setIcon(bulletIcon)
# StyleSheets colText = SHARED.theme.colText
buttonStyle = ( buttonStyle = (
"QToolButton {{border: none; background: transparent;}} " "QToolButton {{border: none; background: transparent;}} "
"QToolButton:hover {{border: none; background: rgba({0},{1},{2},0.2);}}" "QToolButton:hover {{border: none; background: rgba({0}, {1}, {2}, 0.2);}}"
).format(*SHARED.theme.colText) ).format(colText.red(), colText.green(), colText.blue())
self.showHide.setStyleSheet(buttonStyle) self.showHide.setStyleSheet(buttonStyle)
self.showComments.setStyleSheet(buttonStyle) self.showComments.setStyleSheet(buttonStyle)
@@ -956,9 +963,9 @@ class GuiDocViewFooter(QWidget):
theme rather than the main GUI. theme rather than the main GUI.
""" """
palette = QPalette() palette = QPalette()
palette.setColor(QPalette.ColorRole.Window, QColor(*SHARED.theme.colBack)) palette.setColor(QPalette.ColorRole.Window, SHARED.theme.colBack)
palette.setColor(QPalette.ColorRole.WindowText, QColor(*SHARED.theme.colText)) palette.setColor(QPalette.ColorRole.WindowText, SHARED.theme.colText)
palette.setColor(QPalette.ColorRole.Text, QColor(*SHARED.theme.colText)) palette.setColor(QPalette.ColorRole.Text, SHARED.theme.colText)
self.setPalette(palette) self.setPalette(palette)
return return
+3 -4
View File
@@ -29,7 +29,6 @@ from time import time
from typing import TYPE_CHECKING, Literal from typing import TYPE_CHECKING, Literal
from datetime import datetime from datetime import datetime
from PyQt5.QtGui import QColor
from PyQt5.QtCore import pyqtSlot, QLocale from PyQt5.QtCore import pyqtSlot, QLocale
from PyQt5.QtWidgets import qApp, QStatusBar, QLabel from PyQt5.QtWidgets import qApp, QStatusBar, QLabel
@@ -55,9 +54,9 @@ class GuiMainStatus(QStatusBar):
self._userIdle = False self._userIdle = False
self._debugInfo = False self._debugInfo = False
colNone = QColor(*SHARED.theme.statNone) colNone = SHARED.theme.statNone
colSaved = QColor(*SHARED.theme.statSaved) colSaved = SHARED.theme.statSaved
colUnsaved = QColor(*SHARED.theme.statUnsaved) colUnsaved = SHARED.theme.statUnsaved
iPx = SHARED.theme.baseIconSize iPx = SHARED.theme.baseIconSize
+26 -41
View File
@@ -70,10 +70,10 @@ class GuiTheme:
self.isLightTheme = True self.isLightTheme = True
# GUI # GUI
self.statNone = [120, 120, 120] self.statNone = QColor(120, 120, 120)
self.statUnsaved = [200, 15, 39] self.statUnsaved = QColor(200, 15, 39)
self.statSaved = [2, 133, 37] self.statSaved = QColor(2, 133, 37)
self.helpText = [0, 0, 0] self.helpText = QColor(0, 0, 0)
# Loaded Syntax Settings # Loaded Syntax Settings
# ====================== # ======================
@@ -88,23 +88,23 @@ class GuiTheme:
self.syntaxLicenseUrl = "" self.syntaxLicenseUrl = ""
# Colours # Colours
self.colBack = [255, 255, 255] self.colBack = QColor(255, 255, 255)
self.colText = [0, 0, 0] self.colText = QColor(0, 0, 0)
self.colLink = [0, 0, 0] self.colLink = QColor(0, 0, 0)
self.colHead = [0, 0, 0] self.colHead = QColor(0, 0, 0)
self.colHeadH = [0, 0, 0] self.colHeadH = QColor(0, 0, 0)
self.colEmph = [0, 0, 0] self.colEmph = QColor(0, 0, 0)
self.colDialN = [0, 0, 0] self.colDialN = QColor(0, 0, 0)
self.colDialD = [0, 0, 0] self.colDialD = QColor(0, 0, 0)
self.colDialS = [0, 0, 0] self.colDialS = QColor(0, 0, 0)
self.colHidden = [0, 0, 0] self.colHidden = QColor(0, 0, 0)
self.colCode = [0, 0, 0] self.colCode = QColor(0, 0, 0)
self.colKey = [0, 0, 0] self.colKey = QColor(0, 0, 0)
self.colVal = [0, 0, 0] self.colVal = QColor(0, 0, 0)
self.colSpell = [0, 0, 0] self.colSpell = QColor(0, 0, 0)
self.colError = [0, 0, 0] self.colError = QColor(0, 0, 0)
self.colRepTag = [0, 0, 0] self.colRepTag = QColor(0, 0, 0)
self.colMod = [0, 0, 0] self.colMod = QColor(0, 0, 0)
# Class Setup # Class Setup
# =========== # ===========
@@ -256,12 +256,12 @@ class GuiTheme:
backLNess = backCol.lightnessF() backLNess = backCol.lightnessF()
textLNess = textCol.lightnessF() textLNess = textCol.lightnessF()
self.isLightTheme = backLNess > textLNess self.isLightTheme = backLNess > textLNess
if self.helpText == [0, 0, 0]: if self.helpText == QColor(0, 0, 0):
if self.isLightTheme: if self.isLightTheme:
helpLCol = textLNess + 0.35*(backLNess - textLNess) helpLCol = textLNess + 0.35*(backLNess - textLNess)
else: else:
helpLCol = backLNess + 0.65*(textLNess - backLNess) helpLCol = backLNess + 0.65*(textLNess - backLNess)
self.helpText = [int(255*helpLCol)]*3 self.helpText = QColor.fromHsl(0, 0, int(255*helpLCol))
# Icons # Icons
defaultIcons = "typicons_light" if backLNess >= 0.5 else "typicons_dark" defaultIcons = "typicons_light" if backLNess >= 0.5 else "typicons_dark"
@@ -398,29 +398,14 @@ class GuiTheme:
return True return True
def _parseColour(self, parser: NWConfigParser, section: str, name: str) -> list[int]: def _parseColour(self, parser: NWConfigParser, section: str, name: str) -> QColor:
"""Parse a colour value from a config string.""" """Parse a colour value from a config string."""
if parser.has_option(section, name): return QColor(*parser.rdIntList(section, name, [0, 0, 0, 255]))
values = parser.get(section, name).split(",")
result = []
try:
result.append(minmax(int(values[0]), 0, 255))
result.append(minmax(int(values[1]), 0, 255))
result.append(minmax(int(values[2]), 0, 255))
except Exception:
logger.error("Could not load theme colours for '%s' from config file", name)
result = [0, 0, 0]
else:
logger.warning("Could not find theme colours for '%s' in config file", name)
result = [0, 0, 0]
return result
def _setPalette(self, parser: NWConfigParser, section: str, def _setPalette(self, parser: NWConfigParser, section: str,
name: str, value: QPalette.ColorRole) -> None: name: str, value: QPalette.ColorRole) -> None:
"""Set a palette colour value from a config string.""" """Set a palette colour value from a config string."""
self._guiPalette.setColor( self._guiPalette.setColor(value, self._parseColour(parser, section, name))
value, QColor(*self._parseColour(parser, section, name))
)
return return
# End Class GuiTheme # End Class GuiTheme
+3 -5
View File
@@ -27,9 +27,7 @@ import logging
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from PyQt5.QtGui import ( from PyQt5.QtGui import QFont, QIcon, QSyntaxHighlighter, QTextCharFormat, QTextDocument
QColor, QFont, QIcon, QSyntaxHighlighter, QTextCharFormat, QTextDocument
)
from PyQt5.QtCore import QEvent, QSize, Qt, pyqtSignal, pyqtSlot from PyQt5.QtCore import QEvent, QSize, Qt, pyqtSignal, pyqtSlot
from PyQt5.QtWidgets import ( from PyQt5.QtWidgets import (
QAbstractButton, QAbstractItemView, QComboBox, QDialog, QDialogButtonBox, QAbstractButton, QAbstractItemView, QComboBox, QDialog, QDialogButtonBox,
@@ -862,9 +860,9 @@ class _HeadingSyntaxHighlighter(QSyntaxHighlighter):
def __init__(self, document: QTextDocument) -> None: def __init__(self, document: QTextDocument) -> None:
super().__init__(document) super().__init__(document)
self._fmtSymbol = QTextCharFormat() self._fmtSymbol = QTextCharFormat()
self._fmtSymbol.setForeground(QColor(*SHARED.theme.colHead)) self._fmtSymbol.setForeground(SHARED.theme.colHead)
self._fmtFormat = QTextCharFormat() self._fmtFormat = QTextCharFormat()
self._fmtFormat.setForeground(QColor(*SHARED.theme.colEmph)) self._fmtFormat.setForeground(SHARED.theme.colEmph)
return return
def highlightBlock(self, text: str) -> None: def highlightBlock(self, text: str) -> None:
+1 -1
View File
@@ -343,7 +343,7 @@ class _ProjectListItem(QStyledItemDelegate):
self._dFont = qApp.font() self._dFont = qApp.font()
self._dFont.setPointSizeF(fPt) self._dFont.setPointSizeF(fPt)
self._dPen = QPen(QColor(*SHARED.theme.helpText)) self._dPen = QPen(SHARED.theme.helpText)
self._icon = SHARED.theme.getPixmap("proj_nwx", (iPx, iPx)) self._icon = SHARED.theme.getPixmap("proj_nwx", (iPx, iPx))