Use data classes for theme values

This commit is contained in:
Veronica Berglyd Olsen
2025-01-12 19:31:30 +01:00
parent 4c2185fa1e
commit 1878adf78c
8 changed files with 196 additions and 157 deletions
+3
View File
@@ -29,6 +29,8 @@ from enum import Flag, IntEnum
from PyQt6.QtGui import QColor from PyQt6.QtGui import QColor
from novelwriter.types import nwDataClass
ESCAPES = {r"\*": "*", r"\~": "~", r"\_": "_", r"\[": "[", r"\]": "]", r"\ ": ""} ESCAPES = {r"\*": "*", r"\~": "~", r"\_": "_", r"\[": "[", r"\]": "]", r"\ ": ""}
RX_ESC = re.compile("|".join([re.escape(k) for k in ESCAPES.keys()]), flags=re.DOTALL) RX_ESC = re.compile("|".join([re.escape(k) for k in ESCAPES.keys()]), flags=re.DOTALL)
@@ -40,6 +42,7 @@ def stripEscape(text: str) -> str:
return text return text
@nwDataClass
class TextDocumentTheme: class TextDocumentTheme:
"""Default document theme.""" """Default document theme."""
+31 -23
View File
@@ -287,16 +287,18 @@ class GuiDocEditor(QPlainTextEdit):
def updateSyntaxColours(self) -> None: def updateSyntaxColours(self) -> None:
"""Update the syntax highlighting theme.""" """Update the syntax highlighting theme."""
mainPalette = self.palette() syntax = SHARED.theme.syntaxTheme
mainPalette.setColor(QPalette.ColorRole.Window, SHARED.theme.colBack)
mainPalette.setColor(QPalette.ColorRole.Base, SHARED.theme.colBack)
mainPalette.setColor(QPalette.ColorRole.Text, SHARED.theme.colText)
self.setPalette(mainPalette)
docPalette = self.viewport().palette() palette = self.palette()
docPalette.setColor(QPalette.ColorRole.Base, SHARED.theme.colBack) palette.setColor(QPalette.ColorRole.Window, syntax.back)
docPalette.setColor(QPalette.ColorRole.Text, SHARED.theme.colText) palette.setColor(QPalette.ColorRole.Base, syntax.back)
self.viewport().setPalette(docPalette) palette.setColor(QPalette.ColorRole.Text, syntax.text)
self.setPalette(palette)
palette = self.viewport().palette()
palette.setColor(QPalette.ColorRole.Base, syntax.back)
palette.setColor(QPalette.ColorRole.Text, syntax.text)
self.viewport().setPalette(palette)
self.docHeader.matchColours() self.docHeader.matchColours()
self.docFooter.matchColours() self.docFooter.matchColours()
@@ -2032,8 +2034,9 @@ class GuiDocEditor(QPlainTextEdit):
return cursor return cursor
def _makeSelection(self, mode: QTextCursor.SelectionType, def _makeSelection(
cursor: QTextCursor | None = None) -> None: self, mode: QTextCursor.SelectionType, cursor: QTextCursor | None = None
) -> None:
"""Select text based on selection mode.""" """Select text based on selection mode."""
if cursor is None: if cursor is None:
cursor = self.textCursor() cursor = self.textCursor()
@@ -2432,10 +2435,12 @@ 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() syntax = SHARED.theme.syntaxTheme
palette.setColor(QPalette.ColorRole.Window, SHARED.theme.colBack)
palette.setColor(QPalette.ColorRole.WindowText, SHARED.theme.colText) palette = self.palette()
palette.setColor(QPalette.ColorRole.Text, SHARED.theme.colText) palette.setColor(QPalette.ColorRole.Window, syntax.back)
palette.setColor(QPalette.ColorRole.WindowText, syntax.text)
palette.setColor(QPalette.ColorRole.Text, syntax.text)
self.setPalette(palette) self.setPalette(palette)
self.tbBoldMD.setThemeIcon("fmt_bold", "orange") self.tbBoldMD.setThemeIcon("fmt_bold", "orange")
@@ -2975,10 +2980,11 @@ class GuiDocEditHeader(QWidget):
"""Update the colours of the widget to match those of the syntax """Update the colours of the widget to match those of the syntax
theme rather than the main GUI. theme rather than the main GUI.
""" """
palette = QPalette() syntax = SHARED.theme.syntaxTheme
palette.setColor(QPalette.ColorRole.Window, SHARED.theme.colBack) palette = self.palette()
palette.setColor(QPalette.ColorRole.WindowText, SHARED.theme.colText) palette.setColor(QPalette.ColorRole.Window, syntax.back)
palette.setColor(QPalette.ColorRole.Text, SHARED.theme.colText) palette.setColor(QPalette.ColorRole.WindowText, syntax.text)
palette.setColor(QPalette.ColorRole.Text, syntax.text)
self.setPalette(palette) self.setPalette(palette)
self.itemTitle.setTextColors( self.itemTitle.setTextColors(
color=palette.windowText().color(), faded=SHARED.theme.fadedText color=palette.windowText().color(), faded=SHARED.theme.fadedText
@@ -3174,10 +3180,12 @@ class GuiDocEditFooter(QWidget):
"""Update the colours of the widget to match those of the syntax """Update the colours of the widget to match those of the syntax
theme rather than the main GUI. theme rather than the main GUI.
""" """
palette = QPalette() syntax = SHARED.theme.syntaxTheme
palette.setColor(QPalette.ColorRole.Window, SHARED.theme.colBack)
palette.setColor(QPalette.ColorRole.WindowText, SHARED.theme.colText) palette = self.palette()
palette.setColor(QPalette.ColorRole.Text, SHARED.theme.colText) palette.setColor(QPalette.ColorRole.Window, syntax.back)
palette.setColor(QPalette.ColorRole.WindowText, syntax.text)
palette.setColor(QPalette.ColorRole.Text, syntax.text)
self.setPalette(palette) self.setPalette(palette)
self.statusText.setPalette(palette) self.statusText.setPalette(palette)
+29 -28
View File
@@ -91,44 +91,45 @@ class GuiDocHighlighter(QSyntaxHighlighter):
rules and building the RegExes. rules and building the RegExes.
""" """
logger.debug("Setting up highlighting rules") logger.debug("Setting up highlighting rules")
syntax = SHARED.theme.syntaxTheme
colEmph = SHARED.theme.colEmph if CONFIG.highlightEmph else None colEmph = syntax.emph if CONFIG.highlightEmph else None
colBreak = QColor(SHARED.theme.colEmph) colBreak = QColor(syntax.emph)
colBreak.setAlpha(64) colBreak.setAlpha(64)
# Create Character Formats # Create Character Formats
self._addCharFormat("text", SHARED.theme.colText) self._addCharFormat("text", syntax.text)
self._addCharFormat("header1", SHARED.theme.colHead, "b", nwStyles.H_SIZES[1]) self._addCharFormat("header1", syntax.head, "b", nwStyles.H_SIZES[1])
self._addCharFormat("header2", SHARED.theme.colHead, "b", nwStyles.H_SIZES[2]) self._addCharFormat("header2", syntax.head, "b", nwStyles.H_SIZES[2])
self._addCharFormat("header3", SHARED.theme.colHead, "b", nwStyles.H_SIZES[3]) self._addCharFormat("header3", syntax.head, "b", nwStyles.H_SIZES[3])
self._addCharFormat("header4", SHARED.theme.colHead, "b", nwStyles.H_SIZES[4]) self._addCharFormat("header4", syntax.head, "b", nwStyles.H_SIZES[4])
self._addCharFormat("head1h", SHARED.theme.colHeadH, "b", nwStyles.H_SIZES[1]) self._addCharFormat("head1h", syntax.headH, "b", nwStyles.H_SIZES[1])
self._addCharFormat("head2h", SHARED.theme.colHeadH, "b", nwStyles.H_SIZES[2]) self._addCharFormat("head2h", syntax.headH, "b", nwStyles.H_SIZES[2])
self._addCharFormat("head3h", SHARED.theme.colHeadH, "b", nwStyles.H_SIZES[3]) self._addCharFormat("head3h", syntax.headH, "b", nwStyles.H_SIZES[3])
self._addCharFormat("head4h", SHARED.theme.colHeadH, "b", nwStyles.H_SIZES[4]) self._addCharFormat("head4h", syntax.headH, "b", nwStyles.H_SIZES[4])
self._addCharFormat("bold", colEmph, "b") self._addCharFormat("bold", colEmph, "b")
self._addCharFormat("italic", colEmph, "i") self._addCharFormat("italic", colEmph, "i")
self._addCharFormat("strike", SHARED.theme.colHidden, "s") self._addCharFormat("strike", syntax.hidden, "s")
self._addCharFormat("mspaces", SHARED.theme.colError, "err") self._addCharFormat("mspaces", syntax.error, "err")
self._addCharFormat("nobreak", colBreak, "bg") self._addCharFormat("nobreak", colBreak, "bg")
self._addCharFormat("altdialog", SHARED.theme.colDialA) self._addCharFormat("altdialog", syntax.dialA)
self._addCharFormat("dialog", SHARED.theme.colDialN) self._addCharFormat("dialog", syntax.dialN)
self._addCharFormat("replace", SHARED.theme.colRepTag) self._addCharFormat("replace", syntax.repTag)
self._addCharFormat("hidden", SHARED.theme.colHidden) self._addCharFormat("hidden", syntax.hidden)
self._addCharFormat("markup", SHARED.theme.colHidden) self._addCharFormat("markup", syntax.hidden)
self._addCharFormat("link", SHARED.theme.colLink, "u") self._addCharFormat("link", syntax.link, "u")
self._addCharFormat("note", SHARED.theme.colNote) self._addCharFormat("note", syntax.note)
self._addCharFormat("code", SHARED.theme.colCode) self._addCharFormat("code", syntax.code)
self._addCharFormat("keyword", SHARED.theme.colKey) self._addCharFormat("keyword", syntax.key)
self._addCharFormat("tag", SHARED.theme.colTag, "u") self._addCharFormat("tag", syntax.tag, "u")
self._addCharFormat("modifier", SHARED.theme.colMod) self._addCharFormat("modifier", syntax.mod)
self._addCharFormat("value", SHARED.theme.colVal) self._addCharFormat("value", syntax.val)
self._addCharFormat("optional", SHARED.theme.colOpt) self._addCharFormat("optional", syntax.opt)
self._addCharFormat("invalid", None, "err") self._addCharFormat("invalid", None, "err")
# Cache Spell Error Format # Cache Spell Error Format
self._spellErr = QTextCharFormat() self._spellErr = QTextCharFormat()
self._spellErr.setUnderlineColor(SHARED.theme.colSpell) self._spellErr.setUnderlineColor(syntax.spell)
self._spellErr.setUnderlineStyle(QTextCharFormat.UnderlineStyle.SpellCheckUnderline) self._spellErr.setUnderlineStyle(QTextCharFormat.UnderlineStyle.SpellCheckUnderline)
self._txtRules.clear() self._txtRules.clear()
@@ -450,7 +451,7 @@ class GuiDocHighlighter(QSyntaxHighlighter):
if "s" in styles: if "s" in styles:
charFormat.setFontStrikeOut(True) charFormat.setFontStrikeOut(True)
if "err" in styles: if "err" in styles:
charFormat.setUnderlineColor(SHARED.theme.colError) charFormat.setUnderlineColor(SHARED.theme.syntaxTheme.error)
charFormat.setUnderlineStyle(QTextCharFormat.UnderlineStyle.SpellCheckUnderline) charFormat.setUnderlineStyle(QTextCharFormat.UnderlineStyle.SpellCheckUnderline)
if "bg" in styles and color is not None: if "bg" in styles and color is not None:
charFormat.setBackground(QBrush(color, Qt.BrushStyle.SolidPattern)) charFormat.setBackground(QBrush(color, Qt.BrushStyle.SolidPattern))
+34 -30
View File
@@ -155,33 +155,35 @@ class GuiDocViewer(QTextBrowser):
self.docFooter.updateFont() self.docFooter.updateFont()
# Set the widget colours to match syntax theme # Set the widget colours to match syntax theme
mainPalette = self.palette() syntax = SHARED.theme.syntaxTheme
mainPalette.setColor(QPalette.ColorRole.Window, SHARED.theme.colBack)
mainPalette.setColor(QPalette.ColorRole.Base, SHARED.theme.colBack)
mainPalette.setColor(QPalette.ColorRole.Text, SHARED.theme.colText)
self.setPalette(mainPalette)
docPalette = self.viewport().palette() palette = self.palette()
docPalette.setColor(QPalette.ColorRole.Base, SHARED.theme.colBack) palette.setColor(QPalette.ColorRole.Window, syntax.back)
docPalette.setColor(QPalette.ColorRole.Text, SHARED.theme.colText) palette.setColor(QPalette.ColorRole.Base, syntax.back)
self.viewport().setPalette(docPalette) palette.setColor(QPalette.ColorRole.Text, syntax.text)
self.setPalette(palette)
palette = self.viewport().palette()
palette.setColor(QPalette.ColorRole.Base, syntax.back)
palette.setColor(QPalette.ColorRole.Text, syntax.text)
self.viewport().setPalette(palette)
self.docHeader.matchColours() self.docHeader.matchColours()
self.docFooter.matchColours() self.docFooter.matchColours()
# Update theme colours # Update theme colours
self._docTheme.text = SHARED.theme.colText self._docTheme.text = syntax.text
self._docTheme.highlight = SHARED.theme.colMark self._docTheme.highlight = syntax.mark
self._docTheme.head = SHARED.theme.colHead self._docTheme.head = syntax.head
self._docTheme.link = SHARED.theme.colLink self._docTheme.link = syntax.link
self._docTheme.comment = SHARED.theme.colHidden self._docTheme.comment = syntax.hidden
self._docTheme.note = SHARED.theme.colNote self._docTheme.note = syntax.note
self._docTheme.code = SHARED.theme.colCode self._docTheme.code = syntax.code
self._docTheme.modifier = SHARED.theme.colMod self._docTheme.modifier = syntax.mod
self._docTheme.keyword = SHARED.theme.colKey self._docTheme.keyword = syntax.key
self._docTheme.tag = SHARED.theme.colTag self._docTheme.tag = syntax.tag
self._docTheme.optional = SHARED.theme.colOpt self._docTheme.optional = syntax.opt
self._docTheme.dialog = SHARED.theme.colDialN self._docTheme.dialog = syntax.dialN
self._docTheme.altdialog = SHARED.theme.colDialA self._docTheme.altdialog = syntax.dialA
# Set default text margins # Set default text margins
self.document().setDocumentMargin(0) self.document().setDocumentMargin(0)
@@ -783,10 +785,11 @@ class GuiDocViewHeader(QWidget):
"""Update the colours of the widget to match those of the syntax """Update the colours of the widget to match those of the syntax
theme rather than the main GUI. theme rather than the main GUI.
""" """
palette = QPalette() syntax = SHARED.theme.syntaxTheme
palette.setColor(QPalette.ColorRole.Window, SHARED.theme.colBack) palette = self.palette()
palette.setColor(QPalette.ColorRole.WindowText, SHARED.theme.colText) palette.setColor(QPalette.ColorRole.Window, syntax.back)
palette.setColor(QPalette.ColorRole.Text, SHARED.theme.colText) palette.setColor(QPalette.ColorRole.WindowText, syntax.text)
palette.setColor(QPalette.ColorRole.Text, syntax.text)
self.setPalette(palette) self.setPalette(palette)
self.itemTitle.setTextColors( self.itemTitle.setTextColors(
color=palette.windowText().color(), faded=SHARED.theme.fadedText color=palette.windowText().color(), faded=SHARED.theme.fadedText
@@ -970,10 +973,11 @@ class GuiDocViewFooter(QWidget):
"""Update the colours of the widget to match those of the syntax """Update the colours of the widget to match those of the syntax
theme rather than the main GUI. theme rather than the main GUI.
""" """
palette = QPalette() syntax = SHARED.theme.syntaxTheme
palette.setColor(QPalette.ColorRole.Window, SHARED.theme.colBack) palette = self.palette()
palette.setColor(QPalette.ColorRole.WindowText, SHARED.theme.colText) palette.setColor(QPalette.ColorRole.Window, syntax.back)
palette.setColor(QPalette.ColorRole.Text, SHARED.theme.colText) palette.setColor(QPalette.ColorRole.WindowText, syntax.text)
palette.setColor(QPalette.ColorRole.Text, syntax.text)
self.setPalette(palette) self.setPalette(palette)
return return
+85 -63
View File
@@ -41,7 +41,7 @@ from novelwriter.common import NWConfigParser, cssCol, minmax
from novelwriter.constants import nwLabels from novelwriter.constants import nwLabels
from novelwriter.enum import nwItemClass, nwItemLayout, nwItemType from novelwriter.enum import nwItemClass, nwItemLayout, nwItemType
from novelwriter.error import logException from novelwriter.error import logException
from novelwriter.types import QtPaintAntiAlias, QtTransparent from novelwriter.types import QtPaintAntiAlias, QtTransparent, nwDataClass
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -50,15 +50,41 @@ STYLES_MIN_TOOLBUTTON = "minimalToolButton"
STYLES_BIG_TOOLBUTTON = "bigToolButton" STYLES_BIG_TOOLBUTTON = "bigToolButton"
@nwDataClass
class ThemeMeta: class ThemeMeta:
name = "" name: str = ""
description = "" description: str = ""
author = "" author: str = ""
credit = "" credit: str = ""
url = "" url: str = ""
license = "" license: str = ""
licenseUrl = "" licenseUrl: str = ""
@nwDataClass
class SyntaxColors:
back: QColor = QColor(255, 255, 255)
text: QColor = QColor(0, 0, 0)
link: QColor = QColor(0, 0, 0)
head: QColor = QColor(0, 0, 0)
headH: QColor = QColor(0, 0, 0)
emph: QColor = QColor(0, 0, 0)
dialN: QColor = QColor(0, 0, 0)
dialA: QColor = QColor(0, 0, 0)
hidden: QColor = QColor(0, 0, 0)
note: QColor = QColor(0, 0, 0)
code: QColor = QColor(0, 0, 0)
key: QColor = QColor(0, 0, 0)
tag: QColor = QColor(0, 0, 0)
val: QColor = QColor(0, 0, 0)
opt: QColor = QColor(0, 0, 0)
spell: QColor = QColor(0, 0, 0)
error: QColor = QColor(0, 0, 0)
repTag: QColor = QColor(0, 0, 0)
mod: QColor = QColor(0, 0, 0)
mark: QColor = QColor(255, 255, 255, 128)
class GuiTheme: class GuiTheme:
@@ -67,13 +93,29 @@ class GuiTheme:
Handles the look and feel of novelWriter. Handles the look and feel of novelWriter.
""" """
__slots__ = (
# Attributes
"iconCache", "themeMeta", "isDarkTheme", "statNone", "statUnsaved",
"statSaved", "helpText", "fadedText", "errorText", "syntaxMeta",
"syntaxTheme", "guiFont", "guiFontB", "guiFontBU", "guiFontSmall",
"fontPointSize", "fontPixelSize", "baseIconHeight", "baseButtonHeight",
"textNHeight", "textNWidth", "baseIconSize", "buttonIconSize",
"guiFontFixed",
# Functions
"getIcon", "getPixmap", "getItemIcon", "getToggleIcon",
"loadDecoration", "getHeaderDecoration", "getHeaderDecorationNarrow",
# Internal
"_guiPalette", "_themeList", "_syntaxList", "_availThemes",
"_availSyntax", "_styleSheets",
)
def __init__(self) -> None: def __init__(self) -> None:
self.iconCache = GuiIcons(self) self.iconCache = GuiIcons(self)
# Loaded Theme Settings # GUI Theme
# =====================
self.themeMeta = ThemeMeta() self.themeMeta = ThemeMeta()
self.isDarkTheme = False self.isDarkTheme = False
@@ -84,34 +126,9 @@ class GuiTheme:
self.fadedText = QColor(0, 0, 0) self.fadedText = QColor(0, 0, 0)
self.errorText = QColor(255, 0, 0) self.errorText = QColor(255, 0, 0)
# Loaded Syntax Settings # Syntax Theme
# ======================
self.syntaxMeta = ThemeMeta() self.syntaxMeta = ThemeMeta()
self.syntaxTheme = SyntaxColors()
self.colBack = QColor(255, 255, 255)
self.colText = QColor(0, 0, 0)
self.colLink = QColor(0, 0, 0)
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.colDialA = QColor(0, 0, 0)
self.colHidden = QColor(0, 0, 0)
self.colNote = QColor(0, 0, 0)
self.colCode = QColor(0, 0, 0)
self.colKey = QColor(0, 0, 0)
self.colTag = QColor(0, 0, 0)
self.colVal = QColor(0, 0, 0)
self.colOpt = 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.colMark = QColor(255, 255, 255, 128)
# Class Setup
# ===========
# Load Themes # Load Themes
self._guiPalette = QPalette() self._guiPalette = QPalette()
@@ -384,31 +401,33 @@ class GuiTheme:
meta.license = parser.rdStr(sec, "license", "N/A") meta.license = parser.rdStr(sec, "license", "N/A")
meta.licenseUrl = parser.rdStr(sec, "licenseurl", "") meta.licenseUrl = parser.rdStr(sec, "licenseurl", "")
self.syntaxMeta = meta
# Syntax # Syntax
sec = "Syntax" sec = "Syntax"
syntax = SyntaxColors()
if parser.has_section(sec): if parser.has_section(sec):
self.colBack = self._parseColour(parser, sec, "background") syntax.back = self._parseColour(parser, sec, "background")
self.colText = self._parseColour(parser, sec, "text") syntax.text = self._parseColour(parser, sec, "text")
self.colLink = self._parseColour(parser, sec, "link") syntax.link = self._parseColour(parser, sec, "link")
self.colHead = self._parseColour(parser, sec, "headertext") syntax.head = self._parseColour(parser, sec, "headertext")
self.colHeadH = self._parseColour(parser, sec, "headertag") syntax.headH = self._parseColour(parser, sec, "headertag")
self.colEmph = self._parseColour(parser, sec, "emphasis") syntax.emph = self._parseColour(parser, sec, "emphasis")
self.colDialN = self._parseColour(parser, sec, "dialog") syntax.dialN = self._parseColour(parser, sec, "dialog")
self.colDialA = self._parseColour(parser, sec, "altdialog") syntax.dialA = self._parseColour(parser, sec, "altdialog")
self.colHidden = self._parseColour(parser, sec, "hidden") syntax.hidden = self._parseColour(parser, sec, "hidden")
self.colNote = self._parseColour(parser, sec, "note") syntax.note = self._parseColour(parser, sec, "note")
self.colCode = self._parseColour(parser, sec, "shortcode") syntax.code = self._parseColour(parser, sec, "shortcode")
self.colKey = self._parseColour(parser, sec, "keyword") syntax.key = self._parseColour(parser, sec, "keyword")
self.colTag = self._parseColour(parser, sec, "tag") syntax.tag = self._parseColour(parser, sec, "tag")
self.colVal = self._parseColour(parser, sec, "value") syntax.val = self._parseColour(parser, sec, "value")
self.colOpt = self._parseColour(parser, sec, "optional") syntax.opt = self._parseColour(parser, sec, "optional")
self.colSpell = self._parseColour(parser, sec, "spellcheckline") syntax.spell = self._parseColour(parser, sec, "spellcheckline")
self.colError = self._parseColour(parser, sec, "errorline") syntax.error = self._parseColour(parser, sec, "errorline")
self.colRepTag = self._parseColour(parser, sec, "replacetag") syntax.repTag = self._parseColour(parser, sec, "replacetag")
self.colMod = self._parseColour(parser, sec, "modifier") syntax.mod = self._parseColour(parser, sec, "modifier")
self.colMark = self._parseColour(parser, sec, "texthighlight") syntax.mark = self._parseColour(parser, sec, "texthighlight")
self.syntaxMeta = meta
self.syntaxTheme = syntax
return True return True
@@ -568,6 +587,11 @@ class GuiIcons:
returned instead. returned instead.
""" """
__slots__ = (
"mainTheme", "themeMeta", "_svgData", "_svgColours", "_qIcons",
"_headerDec", "_headerDecNarrow", "_themeList", "_iconPath", "_noIcon",
)
TOGGLE_ICON_KEYS: dict[str, tuple[str, str]] = { TOGGLE_ICON_KEYS: dict[str, tuple[str, str]] = {
"bullet": ("bullet-on", "bullet-off"), "bullet": ("bullet-on", "bullet-off"),
"unfold": ("unfold-show", "unfold-hide"), "unfold": ("unfold-show", "unfold-hide"),
@@ -580,6 +604,7 @@ class GuiIcons:
def __init__(self, mainTheme: GuiTheme) -> None: def __init__(self, mainTheme: GuiTheme) -> None:
self.mainTheme = mainTheme self.mainTheme = mainTheme
self.themeMeta = ThemeMeta()
# Storage # Storage
self._svgData: dict[str, bytes] = {} self._svgData: dict[str, bytes] = {}
@@ -595,9 +620,6 @@ class GuiIcons:
# None Icon # None Icon
self._noIcon = QIcon(str(self._iconPath / "none.svg")) self._noIcon = QIcon(str(self._iconPath / "none.svg"))
# Icon Theme Meta
self.themeMeta = ThemeMeta()
return return
def clear(self) -> None: def clear(self) -> None:
+3 -2
View File
@@ -906,10 +906,11 @@ class _HeadingSyntaxHighlighter(QSyntaxHighlighter):
def __init__(self, document: QTextDocument) -> None: def __init__(self, document: QTextDocument) -> None:
super().__init__(document) super().__init__(document)
syntax = SHARED.theme.syntaxTheme
self._fmtSymbol = QTextCharFormat() self._fmtSymbol = QTextCharFormat()
self._fmtSymbol.setForeground(SHARED.theme.colHead) self._fmtSymbol.setForeground(syntax.head)
self._fmtFormat = QTextCharFormat() self._fmtFormat = QTextCharFormat()
self._fmtFormat.setForeground(SHARED.theme.colEmph) self._fmtFormat.setForeground(syntax.emph)
return return
def highlightBlock(self, text: str) -> None: def highlightBlock(self, text: str) -> None:
+5 -5
View File
@@ -186,12 +186,12 @@ def testGuiMain_UpdateTheme(qtbot, nwGUI):
mainTheme.loadSyntax() mainTheme.loadSyntax()
nwGUI._processConfigChanges(True, True, True, True) nwGUI._processConfigChanges(True, True, True, True)
syntaxBack = SHARED.theme.colBack syntax = SHARED.theme.syntaxTheme
assert nwGUI.docEditor.palette().color(QPalette.ColorRole.Window) == syntaxBack assert nwGUI.docEditor.palette().color(QPalette.ColorRole.Window) == syntax.back
assert nwGUI.docEditor.docHeader.palette().color(QPalette.ColorRole.Window) == syntaxBack assert nwGUI.docEditor.docHeader.palette().color(QPalette.ColorRole.Window) == syntax.back
assert nwGUI.docViewer.palette().color(QPalette.ColorRole.Window) == syntaxBack assert nwGUI.docViewer.palette().color(QPalette.ColorRole.Window) == syntax.back
assert nwGUI.docViewer.docHeader.palette().color(QPalette.ColorRole.Window) == syntaxBack assert nwGUI.docViewer.docHeader.palette().color(QPalette.ColorRole.Window) == syntax.back
# qtbot.stop() # qtbot.stop()
+6 -6
View File
@@ -252,9 +252,9 @@ def testGuiTheme_Syntax(qtbot, monkeypatch, nwGUI):
# Check some values # Check some values
assert mainTheme.syntaxMeta.name == "Default Light" assert mainTheme.syntaxMeta.name == "Default Light"
assert mainTheme.colBack == QColor(255, 255, 255) assert mainTheme.syntaxTheme.back == QColor(255, 255, 255)
assert mainTheme.colText == QColor(0, 0, 0) assert mainTheme.syntaxTheme.text == QColor(0, 0, 0)
assert mainTheme.colLink == QColor(0, 0, 200) assert mainTheme.syntaxTheme.link == QColor(0, 0, 200)
# Load Default Dark Theme # Load Default Dark Theme
# ======================= # =======================
@@ -265,9 +265,9 @@ def testGuiTheme_Syntax(qtbot, monkeypatch, nwGUI):
# Check some values # Check some values
assert mainTheme.syntaxMeta.name == "Default Dark" assert mainTheme.syntaxMeta.name == "Default Dark"
assert mainTheme.colBack == QColor(42, 42, 42) assert mainTheme.syntaxTheme.back == QColor(42, 42, 42)
assert mainTheme.colText == QColor(204, 204, 204) assert mainTheme.syntaxTheme.text == QColor(204, 204, 204)
assert mainTheme.colLink == QColor(102, 153, 204) assert mainTheme.syntaxTheme.link == QColor(102, 153, 204)
# qtbot.stop() # qtbot.stop()