Add error text colour setting to theme (#1880)

This commit is contained in:
Veronica Berglyd Olsen
2024-05-20 13:36:37 +02:00
committed by GitHub
9 changed files with 28 additions and 10 deletions
+10 -4
View File
@@ -131,9 +131,11 @@ A GUI theme ``.conf`` file consists of the following settings:
linkvisited = 100, 100, 100 linkvisited = 100, 100, 100
[GUI] [GUI]
statusnone = 100, 100, 100 helptext = 0, 0, 0
statussaved = 100, 100, 100 errortext = 255, 0, 0
statusunsaved = 100, 100, 100 statusnone = 120, 120, 120
statussaved = 2, 133, 37
statusunsaved = 200, 15, 39
In the Main section you must at least define the ``name`` and ``icontheme`` settings. The In the Main section you must at least define the ``name`` and ``icontheme`` settings. The
``icontheme`` settings should correspond to one of the internal icon themes, either ``icontheme`` settings should correspond to one of the internal icon themes, either
@@ -143,7 +145,11 @@ setting must match the icon theme's folder name.
The Palette values correspond to the Qt enum values for ``QPalette::ColorRole``, see the The Palette values correspond to the Qt enum values for ``QPalette::ColorRole``, see the
`Qt documentation <https://doc.qt.io/qt-5.15/qpalette.html#ColorRole-enum>`_ for more details. The `Qt documentation <https://doc.qt.io/qt-5.15/qpalette.html#ColorRole-enum>`_ for more details. The
colour values are RGB numbers on the format ``r, g, b`` where each is an integer from ``0`` to colour values are RGB numbers on the format ``r, g, b`` where each is an integer from ``0`` to
``255``. Omitted values are not loaded and will use default values. ``255``. Omitted values are not loaded and will use default values. If the ``helptext`` colour is
not defined, it is computed as a colour between the ``window`` and ``windowtext`` colour.
.. versionadded:: 2.5
The ``errortext`` theme colour entry was added.
Custom Syntax Theme Custom Syntax Theme
@@ -24,6 +24,8 @@ link = 77, 77, 255
linkvisited = 50, 0, 80 linkvisited = 50, 0, 80
[GUI] [GUI]
helptext = 97, 97, 97
errortext = 255, 77, 77
statusnone = 50, 50, 50 statusnone = 50, 50, 50
statussaved = 77, 255, 77 statussaved = 77, 255, 77
statusunsaved = 255, 77, 77 statusunsaved = 255, 77, 77
@@ -26,6 +26,7 @@ linkvisited = 102, 153, 204
[GUI] [GUI]
helptext = 164, 164, 164 helptext = 164, 164, 164
errortext = 255, 164, 164
statusnone = 150, 152, 150 statusnone = 150, 152, 150
statussaved = 39, 135, 78 statussaved = 39, 135, 78
statusunsaved = 138, 32, 32 statusunsaved = 138, 32, 32
@@ -26,6 +26,7 @@ linkvisited = 66, 113, 174
[GUI] [GUI]
helptext = 92, 92, 92 helptext = 92, 92, 92
errortext = 255, 92, 92
statusnone = 120, 120, 120 statusnone = 120, 120, 120
statussaved = 200, 15, 39 statussaved = 200, 15, 39
statusunsaved = 2, 133, 37 statusunsaved = 2, 133, 37
+1
View File
@@ -41,6 +41,7 @@ linkvisited = 139, 233, 253
[GUI] [GUI]
helptext = 204, 172, 249 helptext = 204, 172, 249
errortext = 255, 85, 85
statusnone = 98, 114, 164 statusnone = 98, 114, 164
statussaved = 80, 250, 123 statussaved = 80, 250, 123
statusunsaved = 255, 85, 85 statusunsaved = 255, 85, 85
@@ -25,6 +25,7 @@ linkvisited = 38, 139, 210
[GUI] [GUI]
helptext = 166, 161, 149 helptext = 166, 161, 149
errortext = 255, 161, 149
statusnone = 88, 110, 117 statusnone = 88, 110, 117
statussaved = 42, 161, 152 statussaved = 42, 161, 152
statusunsaved = 203, 75, 22 statusunsaved = 203, 75, 22
@@ -25,6 +25,7 @@ linkvisited = 38, 139, 210
[GUI] [GUI]
helptext = 78, 91, 95 helptext = 78, 91, 95
errortext = 255, 91, 95
statusnone = 88, 110, 117 statusnone = 88, 110, 117
statussaved = 42, 161, 152 statussaved = 42, 161, 152
statusunsaved = 203, 75, 22 statusunsaved = 203, 75, 22
+7
View File
@@ -75,6 +75,7 @@ class GuiTheme:
self.statUnsaved = QColor(0, 0, 0) self.statUnsaved = QColor(0, 0, 0)
self.statSaved = QColor(0, 0, 0) self.statSaved = QColor(0, 0, 0)
self.helpText = QColor(0, 0, 0) self.helpText = QColor(0, 0, 0)
self.errorText = QColor(255, 0, 0)
# Loaded Syntax Settings # Loaded Syntax Settings
# ====================== # ======================
@@ -265,6 +266,7 @@ class GuiTheme:
sec = "GUI" sec = "GUI"
if parser.has_section(sec): if parser.has_section(sec):
self.helpText = self._parseColour(parser, sec, "helptext") self.helpText = self._parseColour(parser, sec, "helptext")
self.errorText = self._parseColour(parser, sec, "errortext")
self.statNone = self._parseColour(parser, sec, "statusnone") self.statNone = self._parseColour(parser, sec, "statusnone")
self.statUnsaved = self._parseColour(parser, sec, "statusunsaved") self.statUnsaved = self._parseColour(parser, sec, "statusunsaved")
self.statSaved = self._parseColour(parser, sec, "statussaved") self.statSaved = self._parseColour(parser, sec, "statussaved")
@@ -282,6 +284,10 @@ class GuiTheme:
else: else:
helpLCol = backLNess + 0.65*(textLNess - backLNess) helpLCol = backLNess + 0.65*(textLNess - backLNess)
self.helpText = QColor.fromHsl(0, 0, int(255*helpLCol)) self.helpText = QColor.fromHsl(0, 0, int(255*helpLCol))
logger.debug(
"Computed help text colour: rgb(%d, %d, %d)",
self.helpText.red(), self.helpText.green(), self.helpText.blue()
)
# Icons # Icons
defaultIcons = "typicons_light" if backLNess >= 0.5 else "typicons_dark" defaultIcons = "typicons_light" if backLNess >= 0.5 else "typicons_dark"
@@ -402,6 +408,7 @@ class GuiTheme:
self.statUnsaved = QColor(200, 15, 39) self.statUnsaved = QColor(200, 15, 39)
self.statSaved = QColor(2, 133, 37) self.statSaved = QColor(2, 133, 37)
self.helpText = QColor(0, 0, 0) self.helpText = QColor(0, 0, 0)
self.errorText = QColor(255, 0, 0)
return return
def _setGuiFont(self) -> None: def _setGuiFont(self) -> None:
+4 -6
View File
@@ -36,7 +36,7 @@ from PyQt5.QtWidgets import (
) )
from novelwriter import CONFIG, SHARED from novelwriter import CONFIG, SHARED
from novelwriter.common import formatFileFilter, formatInt, getFileSize, openExternalPath from novelwriter.common import cssCol, formatFileFilter, formatInt, getFileSize, openExternalPath
from novelwriter.error import formatException from novelwriter.error import formatException
from novelwriter.extensions.modified import NIconToolButton, NNonBlockingDialog from novelwriter.extensions.modified import NIconToolButton, NNonBlockingDialog
from novelwriter.types import QtDialogClose from novelwriter.types import QtDialogClose
@@ -186,7 +186,7 @@ class GuiDictionaries(NNonBlockingDialog):
(self.tr("Free or Libre Office extension"), "*.sox *.oxt"), "*" (self.tr("Free or Libre Office extension"), "*.sox *.oxt"), "*"
]) ])
soxFile, _ = QFileDialog.getOpenFileName( soxFile, _ = QFileDialog.getOpenFileName(
self, self.tr("Browse Files"), "", filter=ffilter self, self.tr("Browse Files"), str(CONFIG.homePath()), filter=ffilter
) )
if soxFile: if soxFile:
path = Path(soxFile).absolute() path = Path(soxFile).absolute()
@@ -257,10 +257,8 @@ class GuiDictionaries(NNonBlockingDialog):
cursor.movePosition(QTextCursor.MoveOperation.End) cursor.movePosition(QTextCursor.MoveOperation.End)
if cursor.position() > 0: if cursor.position() > 0:
cursor.insertText("\n") cursor.insertText("\n")
if err: textCol = cssCol(SHARED.theme.errorText if err else self.palette().text().color())
cursor.insertHtml(f"<font color='red'>{text}</font>") cursor.insertHtml(f"<font style='color: {textCol}'>{text}</font>")
else:
cursor.insertText(text)
cursor.movePosition(QTextCursor.MoveOperation.End) cursor.movePosition(QTextCursor.MoveOperation.End)
cursor.deleteChar() cursor.deleteChar()
self.infoBox.setTextCursor(cursor) self.infoBox.setTextCursor(cursor)