Add theme update handling to manuscript build settings

This commit is contained in:
Veronica Berglyd Olsen
2025-10-26 02:04:03 +01:00
parent e492c6575d
commit 8b02c95f51
6 changed files with 114 additions and 42 deletions
+4
View File
@@ -286,6 +286,10 @@ class GuiManuscript(NToolDialog):
self.buildOutline.updateTheme()
self.docPreview.updateTheme()
for obj in SHARED.mainGui.children():
if isinstance(obj, GuiBuildSettings):
obj.updateTheme()
##
# Events
##
+89 -30
View File
@@ -154,6 +154,7 @@ class GuiBuildSettings(NToolDialog):
self.outerBox.setSpacing(12)
self.setLayout(self.outerBox)
self.updateTheme(init=True)
# Set Default Tab
self.sidebar.setSelected(self.OPT_FILTERS)
@@ -170,6 +171,20 @@ class GuiBuildSettings(NToolDialog):
self.optTabHeadings.loadContent()
self.optTabFormatting.loadContent()
def updateTheme(self, *, init: bool = False) -> None:
"""Update theme elements."""
if not init:
self.btnApply.updateIcon()
self.btnSave.updateIcon()
self.btnClose.updateIcon()
self.optTabSelect.updateTheme()
self.optTabHeadings.updateTheme()
self.optTabFormatting.updateTheme()
self.titleLabel.setTextColors(color=SHARED.theme.helpText)
self.sidebar.setLabelColor(SHARED.theme.helpText)
##
# Properties
##
@@ -326,15 +341,13 @@ class _FilterTab(NFixedPage):
self.includedButton = NIconToolButton(self, iSz)
self.includedButton.setToolTip(self.tr("Always included"))
self.includedButton.setIcon(self._statusFlags[self.F_INCLUDED])
self.includedButton.clicked.connect(qtLambda(self._setSelectedMode, self.F_INCLUDED))
self.excludedButton = NIconToolButton(self, iSz)
self.excludedButton.setToolTip(self.tr("Always excluded"))
self.excludedButton.setIcon(self._statusFlags[self.F_EXCLUDED])
self.excludedButton.clicked.connect(qtLambda(self._setSelectedMode, self.F_EXCLUDED))
self.resetButton = NIconToolButton(self, iSz, "revert", "green")
self.resetButton = NIconToolButton(self, iSz)
self.resetButton.setToolTip(self.tr("Reset to default"))
self.resetButton.clicked.connect(qtLambda(self._setSelectedMode, self.F_FILTERED))
@@ -376,6 +389,7 @@ class _FilterTab(NFixedPage):
pOptions.getInt("GuiBuildSettings", "filterWidth", 300),
])
self.updateTheme(init=True)
self.setCentralWidget(self.mainSplit)
def loadContent(self) -> None:
@@ -389,6 +403,18 @@ class _FilterTab(NFixedPage):
m, n = (sizes[0], sizes[1]) if len(sizes) >= 2 else (0, 0)
return m, n
def updateTheme(self, *, init: bool = False) -> None:
"""Update theme elements."""
if not init:
self._statusFlags[self.F_FILTERED] = SHARED.theme.getIcon("filter", "orange")
self._statusFlags[self.F_INCLUDED] = SHARED.theme.getIcon("pin", "blue")
self._statusFlags[self.F_EXCLUDED] = SHARED.theme.getIcon("exclude", "red")
self.loadContent()
self.includedButton.setIcon(self._statusFlags[self.F_INCLUDED])
self.excludedButton.setIcon(self._statusFlags[self.F_EXCLUDED])
self.resetButton.setThemeIcon("revert", "green")
##
# Slots
##
@@ -555,7 +581,7 @@ class _HeadingsTab(NScrollablePage):
self.lblPart = QLabel(self._build.getLabel("headings.fmtPart"), self)
self.fmtPart = QLineEdit("", self)
self.fmtPart.setReadOnly(True)
self.btnPart = NIconToolButton(self, iSz, "edit", "green")
self.btnPart = NIconToolButton(self, iSz)
self.btnPart.clicked.connect(qtLambda(self._editHeading, self.EDIT_TITLE))
self.swtPart = NSwitch(self, height=iPx)
self.hdePart = QLabel(trHide, self)
@@ -572,7 +598,7 @@ class _HeadingsTab(NScrollablePage):
self.lblChapter = QLabel(self._build.getLabel("headings.fmtChapter"), self)
self.fmtChapter = QLineEdit("", self)
self.fmtChapter.setReadOnly(True)
self.btnChapter = NIconToolButton(self, iSz, "edit", "green")
self.btnChapter = NIconToolButton(self, iSz)
self.btnChapter.clicked.connect(qtLambda(self._editHeading, self.EDIT_CHAPTER))
self.swtChapter = NSwitch(self, height=iPx)
self.hdeChapter = QLabel(trHide, self)
@@ -589,7 +615,7 @@ class _HeadingsTab(NScrollablePage):
self.lblUnnumbered = QLabel(self._build.getLabel("headings.fmtUnnumbered"), self)
self.fmtUnnumbered = QLineEdit("", self)
self.fmtUnnumbered.setReadOnly(True)
self.btnUnnumbered = NIconToolButton(self, iSz, "edit", "green")
self.btnUnnumbered = NIconToolButton(self, iSz)
self.btnUnnumbered.clicked.connect(qtLambda(self._editHeading, self.EDIT_UNNUM))
self.swtUnnumbered = NSwitch(self, height=iPx)
self.hdeUnnumbered = QLabel(trHide, self)
@@ -606,7 +632,7 @@ class _HeadingsTab(NScrollablePage):
self.lblScene = QLabel(self._build.getLabel("headings.fmtScene"), self)
self.fmtScene = QLineEdit("", self)
self.fmtScene.setReadOnly(True)
self.btnScene = NIconToolButton(self, iSz, "edit", "green")
self.btnScene = NIconToolButton(self, iSz)
self.btnScene.clicked.connect(qtLambda(self._editHeading, self.EDIT_SCENE))
self.swtScene = NSwitch(self, height=iPx)
self.hdeScene = QLabel(trHide, self)
@@ -623,7 +649,7 @@ class _HeadingsTab(NScrollablePage):
self.lblAScene = QLabel(self._build.getLabel("headings.fmtAltScene"), self)
self.fmtAScene = QLineEdit("", self)
self.fmtAScene.setReadOnly(True)
self.btnAScene = NIconToolButton(self, iSz, "edit", "green")
self.btnAScene = NIconToolButton(self, iSz)
self.btnAScene.clicked.connect(qtLambda(self._editHeading, self.EDIT_HSCENE))
self.swtAScene = NSwitch(self, height=iPx)
self.hdeAScene = QLabel(trHide, self)
@@ -640,7 +666,7 @@ class _HeadingsTab(NScrollablePage):
self.lblSection = QLabel(self._build.getLabel("headings.fmtSection"), self)
self.fmtSection = QLineEdit("", self)
self.fmtSection.setReadOnly(True)
self.btnSection = NIconToolButton(self, iSz, "edit", "green")
self.btnSection = NIconToolButton(self, iSz)
self.btnSection.clicked.connect(qtLambda(self._editHeading, self.EDIT_SECTION))
self.swtSection = NSwitch(self, height=iPx)
self.hdeSection = QLabel(trHide, self)
@@ -774,8 +800,21 @@ class _HeadingsTab(NScrollablePage):
self.outerBox.addLayout(self.layoutMatrix)
self.outerBox.addStretch(1)
self.updateTheme()
self.setCentralLayout(self.outerBox)
def updateTheme(self) -> None:
"""Update theme elements."""
self.btnPart.setThemeIcon("edit", "green")
self.btnChapter.setThemeIcon("edit", "green")
self.btnUnnumbered.setThemeIcon("edit", "green")
self.btnScene.setThemeIcon("edit", "green")
self.btnAScene.setThemeIcon("edit", "green")
self.btnSection.setThemeIcon("edit", "green")
self.formSyntax.initHighlighter()
self.formSyntax.rehighlight()
def loadContent(self) -> None:
"""Populate the widgets."""
def fmtBreak(text: str) -> str:
@@ -907,10 +946,14 @@ class _HeadingSyntaxHighlighter(QSyntaxHighlighter):
def __init__(self, document: QTextDocument | None) -> None:
super().__init__(document)
syntax = SHARED.theme.syntaxTheme
self._fmtSymbol = QTextCharFormat()
self._fmtSymbol.setForeground(syntax.head)
self._fmtFormat = QTextCharFormat()
self.initHighlighter()
def initHighlighter(self) -> None:
"""Update theme elements."""
syntax = SHARED.theme.syntaxTheme
self._fmtSymbol.setForeground(syntax.head)
self._fmtFormat.setForeground(syntax.emph)
def highlightBlock(self, text: str) -> None:
@@ -936,6 +979,7 @@ class _FormattingTab(NScrollableForm):
self.setHelpTextStyle(SHARED.theme.helpText)
self.buildForm()
self.updateTheme()
def buildForm(self) -> None:
"""Build the formatting form."""
@@ -979,7 +1023,7 @@ class _FormattingTab(NScrollableForm):
lambda keyword=keyword: self._updateIgnoredKeywords(keyword)
)
self.ignoredKeywordsButton = NIconToolButton(self, iSz, "add", "green")
self.ignoredKeywordsButton = NIconToolButton(self, iSz)
self.ignoredKeywordsButton.setMenu(self.mnKeywords)
self.addRow(
self._build.getLabel("text.ignoredKeywords"), self.ignoredKeywords,
@@ -1001,7 +1045,7 @@ class _FormattingTab(NScrollableForm):
# Text Font
self.textFont = QLineEdit(self)
self.textFont.setReadOnly(True)
self.btnTextFont = NIconToolButton(self, iSz, "font")
self.btnTextFont = NIconToolButton(self, iSz)
self.btnTextFont.clicked.connect(self._selectFont)
self.addRow(
self._build.getLabel("format.textFont"), self.textFont,
@@ -1060,12 +1104,12 @@ class _FormattingTab(NScrollableForm):
self._sidebar.addButton(title, section)
self.addGroupLabel(title, section)
pixT = SHARED.theme.getPixmap("margin_top", (iPx, iPx))
pixB = SHARED.theme.getPixmap("margin_bottom", (iPx, iPx))
pixL = SHARED.theme.getPixmap("margin_left", (iPx, iPx))
pixR = SHARED.theme.getPixmap("margin_right", (iPx, iPx))
pixH = SHARED.theme.getPixmap("fit_height", (iPx, iPx))
pixW = SHARED.theme.getPixmap("fit_width", (iPx, iPx))
self.pixT = QLabel(self)
self.pixB = QLabel(self)
self.pixL = QLabel(self)
self.pixR = QLabel(self)
self.pixH = QLabel(self)
self.pixW = QLabel(self)
# Title
self.titleMarginT = NDoubleSpinBox(self)
@@ -1076,7 +1120,7 @@ class _FormattingTab(NScrollableForm):
self.addRow(
self._build.getLabel("format.titleMargin"),
[pixT, self.titleMarginT, 6, pixB, self.titleMarginB],
[self.pixT, self.titleMarginT, 6, self.pixB, self.titleMarginB],
unit="em",
)
@@ -1089,7 +1133,7 @@ class _FormattingTab(NScrollableForm):
self.addRow(
self._build.getLabel("format.h1Margin"),
[pixT, self.h1MarginT, 6, pixB, self.h1MarginB],
[self.pixT, self.h1MarginT, 6, self.pixB, self.h1MarginB],
unit="em",
)
@@ -1102,7 +1146,7 @@ class _FormattingTab(NScrollableForm):
self.addRow(
self._build.getLabel("format.h2Margin"),
[pixT, self.h2MarginT, 6, pixB, self.h2MarginB],
[self.pixT, self.h2MarginT, 6, self.pixB, self.h2MarginB],
unit="em",
)
@@ -1115,7 +1159,7 @@ class _FormattingTab(NScrollableForm):
self.addRow(
self._build.getLabel("format.h3Margin"),
[pixT, self.h3MarginT, 6, pixB, self.h3MarginB],
[self.pixT, self.h3MarginT, 6, self.pixB, self.h3MarginB],
unit="em",
)
@@ -1128,7 +1172,7 @@ class _FormattingTab(NScrollableForm):
self.addRow(
self._build.getLabel("format.h4Margin"),
[pixT, self.h4MarginT, 6, pixB, self.h4MarginB],
[self.pixT, self.h4MarginT, 6, self.pixB, self.h4MarginB],
unit="em",
)
@@ -1141,7 +1185,7 @@ class _FormattingTab(NScrollableForm):
self.addRow(
self._build.getLabel("format.textMargin"),
[pixT, self.textMarginT, 6, pixB, self.textMarginB],
[self.pixT, self.textMarginT, 6, self.pixB, self.textMarginB],
unit="em",
)
@@ -1154,7 +1198,7 @@ class _FormattingTab(NScrollableForm):
self.addRow(
self._build.getLabel("format.sepMargin"),
[pixT, self.sepMarginT, 6, pixB, self.sepMarginB],
[self.pixT, self.sepMarginT, 6, self.pixB, self.sepMarginB],
unit="em",
)
@@ -1188,7 +1232,7 @@ class _FormattingTab(NScrollableForm):
self.addRow(
self._build.getLabel("format.pageSize"),
[self.pageSize, 6, pixW, self.pageWidth, 6, pixH, self.pageHeight],
[self.pageSize, 6, self.pixW, self.pageWidth, 6, self.pixH, self.pageHeight],
)
# Page Margins
@@ -1206,11 +1250,11 @@ class _FormattingTab(NScrollableForm):
self.addRow(
self._build.getLabel("format.pageMargins"),
[pixT, self.topMargin, 6, pixB, self.bottomMargin],
[self.pixT, self.topMargin, 6, self.pixB, self.bottomMargin],
)
self.addRow(
"",
[pixL, self.leftMargin, 6, pixR, self.rightMargin],
[self.pixL, self.leftMargin, 6, self.pixR, self.rightMargin],
)
# Open Document
@@ -1224,7 +1268,7 @@ class _FormattingTab(NScrollableForm):
# Header
self.odtPageHeader = QLineEdit(self)
self.odtPageHeader.setMinimumWidth(200)
self.btnPageHeader = NIconToolButton(self, iSz, "revert", "green")
self.btnPageHeader = NIconToolButton(self, iSz)
self.btnPageHeader.clicked.connect(self._resetPageHeader)
self.addRow(
self._build.getLabel("doc.pageHeader"), self.odtPageHeader,
@@ -1264,6 +1308,21 @@ class _FormattingTab(NScrollableForm):
# Finalise
self.finalise()
def updateTheme(self) -> None:
"""Update theme elements."""
iPx = SHARED.theme.baseIconHeight
self.ignoredKeywordsButton.setThemeIcon("add", "green")
self.btnTextFont.setThemeIcon("font")
self.btnPageHeader.setThemeIcon("revert", "green")
self.pixT.setPixmap(SHARED.theme.getPixmap("margin_top", (iPx, iPx)))
self.pixB.setPixmap(SHARED.theme.getPixmap("margin_bottom", (iPx, iPx)))
self.pixL.setPixmap(SHARED.theme.getPixmap("margin_left", (iPx, iPx)))
self.pixR.setPixmap(SHARED.theme.getPixmap("margin_right", (iPx, iPx)))
self.pixH.setPixmap(SHARED.theme.getPixmap("fit_height", (iPx, iPx)))
self.pixW.setPixmap(SHARED.theme.getPixmap("fit_width", (iPx, iPx)))
def loadContent(self) -> None:
"""Populate the widgets."""
# Text Content