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