Change the name and alpha format of colour themes

This commit is contained in:
Veronica Berglyd Olsen
2025-06-03 12:02:38 +02:00
parent b0ea1781e7
commit 82188d156b
14 changed files with 84 additions and 86 deletions
+2 -2
View File
@@ -54,7 +54,7 @@ background = #363636
text = default text = default
link = blue link = blue
headertext = green headertext = green
headertag = green, 160 headertag = green:160
emphasis = orange emphasis = orange
dialog = blue dialog = blue
altdialog = blue altdialog = blue
@@ -69,4 +69,4 @@ spellcheckline = red
errorline = green errorline = green
replacetag = green replacetag = green
modifier = green modifier = green
texthighlight = yellow, 72 texthighlight = yellow:72
+1 -1
View File
@@ -54,7 +54,7 @@ background = #ffffff
text = #000000 text = #000000
link = blue link = blue
headertext = green headertext = green
headertag = green, 160 headertag = green:160
emphasis = orange emphasis = orange
dialog = blue dialog = blue
altdialog = blue altdialog = blue
+2 -2
View File
@@ -73,7 +73,7 @@ background = #fbfbfb
text = default text = default
link = blue link = blue
headertext = blue headertext = blue
headertag = blue, 160 headertag = blue:160
emphasis = orange emphasis = orange
dialog = green dialog = green
altdialog = yellow altdialog = yellow
@@ -88,4 +88,4 @@ spellcheckline = red
errorline = green errorline = green
replacetag = aqua replacetag = aqua
modifier = green modifier = green
texthighlight = yellow, 96 texthighlight = yellow:96
+2 -2
View File
@@ -73,7 +73,7 @@ background = #011627
text = default text = default
link = blue link = blue
headertext = blue headertext = blue
headertag = blue, 160 headertag = blue:160
emphasis = orange emphasis = orange
dialog = green dialog = green
altdialog = yellow altdialog = yellow
@@ -88,4 +88,4 @@ spellcheckline = red
errorline = green errorline = green
replacetag = aqua replacetag = aqua
modifier = green modifier = green
texthighlight = yellow, 96 texthighlight = yellow:96
+3 -3
View File
@@ -63,7 +63,7 @@ background = #2e3436
text = default text = default
link = blue link = blue
headertext = blue headertext = blue
headertag = blue, 160 headertag = blue:160
emphasis = orange emphasis = orange
dialog = green dialog = green
altdialog = yellow altdialog = yellow
@@ -76,6 +76,6 @@ value = red
optional = blue optional = blue
spellcheckline = red spellcheckline = red
errorline = green errorline = green
replacetag = cyan replacetag = aqua
modifier = blue modifier = blue
texthighlight = yellow, 96 texthighlight = yellow:96
+5 -5
View File
@@ -1,6 +1,6 @@
[Main] [Main]
name = Tango Light name = Tango Light
mode = light mode = light
author = Veronica Berglyd Olsen (adaptation) author = Veronica Berglyd Olsen (adaptation)
## ##
@@ -63,7 +63,7 @@ background = #eeeeec
text = default text = default
link = blue link = blue
headertext = blue headertext = blue
headertag = blue, 160 headertag = blue:160
emphasis = orange emphasis = orange
dialog = green dialog = green
altdialog = yellow altdialog = yellow
@@ -76,6 +76,6 @@ value = red
optional = blue optional = blue
spellcheckline = red spellcheckline = red
errorline = green errorline = green
replacetag = cyan replacetag = aqua
modifier = blue modifier = blue
texthighlight = yellow, 96 texthighlight = yellow:96
+2 -2
View File
@@ -73,7 +73,7 @@ background = #ffffff
text = #4d4d4c text = #4d4d4c
link = blue link = blue
headertext = blue headertext = blue
headertag = blue, 160 headertag = blue:160
emphasis = orange emphasis = orange
dialog = green dialog = green
altdialog = yellow altdialog = yellow
@@ -88,4 +88,4 @@ spellcheckline = red
errorline = green errorline = green
replacetag = aqua replacetag = aqua
modifier = orange modifier = orange
texthighlight = yellow, 96 texthighlight = yellow:96
@@ -73,7 +73,7 @@ background = #1d1f21
text = default text = default
link = blue link = blue
headertext = blue headertext = blue
headertag = blue, 160 headertag = blue:160
emphasis = orange emphasis = orange
dialog = green dialog = green
altdialog = yellow altdialog = yellow
@@ -88,4 +88,4 @@ spellcheckline = red
errorline = green errorline = green
replacetag = aqua replacetag = aqua
modifier = orange modifier = orange
texthighlight = yellow, 96 texthighlight = yellow:96
@@ -73,7 +73,7 @@ background = #002451
text = default text = default
link = blue link = blue
headertext = blue headertext = blue
headertag = blue, 160 headertag = blue:160
emphasis = orange emphasis = orange
dialog = green dialog = green
altdialog = yellow altdialog = yellow
@@ -88,4 +88,4 @@ spellcheckline = red
errorline = green errorline = green
replacetag = aqua replacetag = aqua
modifier = orange modifier = orange
texthighlight = yellow, 96 texthighlight = yellow:96
@@ -73,7 +73,7 @@ background = #000000
text = default text = default
link = blue link = blue
headertext = blue headertext = blue
headertag = blue, 160 headertag = blue:160
emphasis = orange emphasis = orange
dialog = green dialog = green
altdialog = yellow altdialog = yellow
@@ -88,4 +88,4 @@ spellcheckline = red
errorline = green errorline = green
replacetag = aqua replacetag = aqua
modifier = orange modifier = orange
texthighlight = yellow, 96 texthighlight = yellow:96
@@ -73,7 +73,7 @@ background = #2d2d2d
text = default text = default
link = blue link = blue
headertext = blue headertext = blue
headertag = blue, 160 headertag = blue:160
emphasis = orange emphasis = orange
dialog = green dialog = green
altdialog = yellow altdialog = yellow
@@ -88,4 +88,4 @@ spellcheckline = red
errorline = green errorline = green
replacetag = aqua replacetag = aqua
modifier = orange modifier = orange
texthighlight = yellow, 96 texthighlight = yellow:96
+6 -6
View File
@@ -82,10 +82,6 @@ class GuiSideBar(QWidget):
self.tbTheme.setToolTip(self.tr("Switch Colour Theme")) self.tbTheme.setToolTip(self.tr("Switch Colour Theme"))
self.tbTheme.clicked.connect(self._cycleColurTheme) self.tbTheme.clicked.connect(self._cycleColurTheme)
self.tbBuild = NIconToolButton(self, iSz)
self.tbBuild.setToolTip("{0} [F5]".format(self.tr("Build Manuscript")))
self.tbBuild.clicked.connect(self.mainGui.showBuildManuscriptDialog)
self.tbDetails = NIconToolButton(self, iSz) self.tbDetails = NIconToolButton(self, iSz)
self.tbDetails.setToolTip("{0} [Shift+F6]".format(self.tr("Novel Details"))) self.tbDetails.setToolTip("{0} [Shift+F6]".format(self.tr("Novel Details")))
self.tbDetails.clicked.connect(self.mainGui.showNovelDetailsDialog) self.tbDetails.clicked.connect(self.mainGui.showNovelDetailsDialog)
@@ -94,6 +90,10 @@ class GuiSideBar(QWidget):
self.tbStats.setToolTip("{0} [F6]".format(self.tr("Writing Statistics"))) self.tbStats.setToolTip("{0} [F6]".format(self.tr("Writing Statistics")))
self.tbStats.clicked.connect(self.mainGui.showWritingStatsDialog) self.tbStats.clicked.connect(self.mainGui.showWritingStatsDialog)
self.tbBuild = NIconToolButton(self, iSz)
self.tbBuild.setToolTip("{0} [F5]".format(self.tr("Build Manuscript")))
self.tbBuild.clicked.connect(self.mainGui.showBuildManuscriptDialog)
# Settings Menu # Settings Menu
self.tbSettings = NIconToolButton(self, iSz) self.tbSettings = NIconToolButton(self, iSz)
self.tbSettings.setToolTip(self.tr("Settings")) self.tbSettings.setToolTip(self.tr("Settings"))
@@ -114,9 +114,9 @@ class GuiSideBar(QWidget):
self.outerBox.addWidget(self.tbOutline) self.outerBox.addWidget(self.tbOutline)
self.outerBox.addWidget(self.tbBuild) self.outerBox.addWidget(self.tbBuild)
self.outerBox.addStretch(1) self.outerBox.addStretch(1)
self.outerBox.addWidget(self.tbTheme)
self.outerBox.addWidget(self.tbDetails) self.outerBox.addWidget(self.tbDetails)
self.outerBox.addWidget(self.tbStats) self.outerBox.addWidget(self.tbStats)
self.outerBox.addWidget(self.tbTheme)
self.outerBox.addWidget(self.tbSettings) self.outerBox.addWidget(self.tbSettings)
self.outerBox.setContentsMargins(0, 0, 0, 0) self.outerBox.setContentsMargins(0, 0, 0, 0)
self.outerBox.setSpacing(6) self.outerBox.setSpacing(6)
@@ -137,9 +137,9 @@ class GuiSideBar(QWidget):
self.tbSearch.setStyleSheet(buttonStyle) self.tbSearch.setStyleSheet(buttonStyle)
self.tbOutline.setStyleSheet(buttonStyle) self.tbOutline.setStyleSheet(buttonStyle)
self.tbBuild.setStyleSheet(buttonStyle) self.tbBuild.setStyleSheet(buttonStyle)
self.tbTheme.setStyleSheet(buttonStyle)
self.tbDetails.setStyleSheet(buttonStyle) self.tbDetails.setStyleSheet(buttonStyle)
self.tbStats.setStyleSheet(buttonStyle) self.tbStats.setStyleSheet(buttonStyle)
self.tbTheme.setStyleSheet(buttonStyle)
self.tbSettings.setStyleSheet(buttonStyle) self.tbSettings.setStyleSheet(buttonStyle)
self.tbProject.setThemeIcon("sb_project") self.tbProject.setThemeIcon("sb_project")
+17 -19
View File
@@ -229,27 +229,25 @@ class GuiTheme:
if value in self._qColors: if value in self._qColors:
# Named colour # Named colour
return self._qColors[value] return self._qColors[value]
elif value.startswith("#"): elif value.startswith("#") and len(value) == 7:
if len(value) >= 9: # Assume #RRGGBB
# Convert from #RRGGBBAA to #AARRGGBB return QColor.fromString(value)
return QColor.fromString(f"#{value[7:9]}{value[1:7]}") elif value.startswith("#") and len(value) == 9:
else: # Assume #RRGGBBAA and convert to #AARRGGBB
# Assume #RRGGBB return QColor.fromString(f"#{value[7:9]}{value[1:7]}")
return QColor.fromString(value[:7]) elif ":" in value:
# Colour name and alpha
name, _, alpha = value.partition(":")
color = QColor(self._qColors.get(name.strip(), default))
color.setAlpha(checkInt(alpha, 255))
return color
elif "," in value: elif "," in value:
# Integer red, green, blue, alpha
data = value.split(",") data = value.split(",")
entries = len(data) result = [0, 0, 0, 255]
if entries == 2: for i in range(min(len(data), 4)):
# Assume name, alpha result[i] = checkInt(data[i].strip(), result[i])
color = QColor(self._qColors.get(data[0].strip(), default)) return QColor(*result)
color.setAlpha(checkInt(data[1], 255))
return color
else:
# Assume red, green, blue, alpha
result = [0, 0, 0, 255]
for i in range(min(entries, 4)):
result[i] = checkInt(data[i].strip(), result[i])
return QColor(*result)
return default return default
def loadTheme(self, force: bool = False) -> bool: def loadTheme(self, force: bool = False) -> bool:
+36 -36
View File
@@ -39,40 +39,6 @@ from tests.mocked import causeOSError
from tests.tools import writeFile from tests.tools import writeFile
@pytest.mark.gui
def testGuiTheme_ParseColor(qtbot, nwGUI):
"""Test the colour parsing."""
theme = SHARED.theme
# Pre-Populate
theme._qColors["red"] = QColor(255, 0, 0)
theme._qColors["green"] = QColor(0, 255, 0)
theme._qColors["blue"] = QColor(0, 0, 255)
# By Name
assert theme.parseColor("red").getRgb() == (255, 0, 0, 255)
assert theme.parseColor("green").getRgb() == (0, 255, 0, 255)
assert theme.parseColor("blue").getRgb() == (0, 0, 255, 255)
assert theme.parseColor("bob").getRgb() == (0, 0, 0, 255)
# CSS Format
assert theme.parseColor("#ff0000").getRgb() == (255, 0, 0, 255)
assert theme.parseColor("#ff00007f").getRgb() == (255, 0, 0, 127)
assert theme.parseColor("#ff00").getRgb() == (0, 0, 0, 255) # Too short -> ignored
assert theme.parseColor("#ff00007f15").getRgb() == (255, 0, 0, 127) # Too long -> truncated
# Name + Alpha
assert theme.parseColor("red, 255").getRgb() == (255, 0, 0, 255)
assert theme.parseColor("red, 127").getRgb() == (255, 0, 0, 127)
assert theme.parseColor("red, 512").getRgb() == (255, 0, 0, 255) # Value truncated
# Values
assert theme.parseColor("255, 0, 0").getRgb() == (255, 0, 0, 255)
assert theme.parseColor("255, 0, 0, 255").getRgb() == (255, 0, 0, 255)
assert theme.parseColor("255, 0, 0, 127").getRgb() == (255, 0, 0, 127)
assert theme.parseColor("255, 0, 0, 127, 42").getRgb() == (255, 0, 0, 127) # Truncated
@pytest.mark.gui @pytest.mark.gui
def testGuiTheme_Main(qtbot, nwGUI, tstPaths): def testGuiTheme_Main(qtbot, nwGUI, tstPaths):
"""Test the theme class init.""" """Test the theme class init."""
@@ -118,7 +84,7 @@ def testGuiTheme_Main(qtbot, nwGUI, tstPaths):
assert theme._readColor(parser, "Palette", "colour1").getRgb() == (100, 150, 200, 255) assert theme._readColor(parser, "Palette", "colour1").getRgb() == (100, 150, 200, 255)
assert theme._readColor(parser, "Palette", "colour2").getRgb() == (100, 150, 200, 250) assert theme._readColor(parser, "Palette", "colour2").getRgb() == (100, 150, 200, 250)
assert theme._readColor(parser, "Palette", "colour3").getRgb() == (100, 150, 200, 250) assert theme._readColor(parser, "Palette", "colour3").getRgb() == (100, 150, 200, 250)
assert theme._readColor(parser, "Palette", "colour4").getRgb() == (0, 0, 0, 250) assert theme._readColor(parser, "Palette", "colour4").getRgb() == (250, 250, 0, 255)
assert theme._readColor(parser, "Palette", "colour5").getRgb() == (0, 0, 0, 0) assert theme._readColor(parser, "Palette", "colour5").getRgb() == (0, 0, 0, 0)
assert theme._readColor(parser, "Palette", "colour6").getRgb() == (0, 127, 255, 255) assert theme._readColor(parser, "Palette", "colour6").getRgb() == (0, 127, 255, 255)
@@ -130,7 +96,7 @@ def testGuiTheme_Main(qtbot, nwGUI, tstPaths):
theme._setPalette(parser, "Palette", "colour3", QPalette.ColorRole.Window) theme._setPalette(parser, "Palette", "colour3", QPalette.ColorRole.Window)
assert theme._guiPalette.color(QPalette.ColorRole.Window).getRgb() == (100, 150, 200, 250) assert theme._guiPalette.color(QPalette.ColorRole.Window).getRgb() == (100, 150, 200, 250)
theme._setPalette(parser, "Palette", "colour4", QPalette.ColorRole.Window) theme._setPalette(parser, "Palette", "colour4", QPalette.ColorRole.Window)
assert theme._guiPalette.color(QPalette.ColorRole.Window).getRgb() == (0, 0, 0, 250) assert theme._guiPalette.color(QPalette.ColorRole.Window).getRgb() == (250, 250, 0, 255)
theme._setPalette(parser, "Palette", "colour5", QPalette.ColorRole.Window) theme._setPalette(parser, "Palette", "colour5", QPalette.ColorRole.Window)
assert theme._guiPalette.color(QPalette.ColorRole.Window).getRgb() == (0, 0, 0, 0) assert theme._guiPalette.color(QPalette.ColorRole.Window).getRgb() == (0, 0, 0, 0)
theme._setPalette(parser, "Palette", "colour6", QPalette.ColorRole.Window) theme._setPalette(parser, "Palette", "colour6", QPalette.ColorRole.Window)
@@ -144,6 +110,40 @@ def testGuiTheme_Main(qtbot, nwGUI, tstPaths):
# qtbot.stop() # qtbot.stop()
@pytest.mark.gui
def testGuiTheme_ParseColor(qtbot, nwGUI):
"""Test the colour parsing."""
theme = SHARED.theme
# Pre-Populate
theme._qColors["red"] = QColor(255, 0, 0)
theme._qColors["green"] = QColor(0, 255, 0)
theme._qColors["blue"] = QColor(0, 0, 255)
# By Name
assert theme.parseColor("red").getRgb() == (255, 0, 0, 255)
assert theme.parseColor("green").getRgb() == (0, 255, 0, 255)
assert theme.parseColor("blue").getRgb() == (0, 0, 255, 255)
assert theme.parseColor("bob").getRgb() == (0, 0, 0, 255)
# CSS Format
assert theme.parseColor("#ff0000").getRgb() == (255, 0, 0, 255)
assert theme.parseColor("#ff00007f").getRgb() == (255, 0, 0, 127)
assert theme.parseColor("#ff00").getRgb() == (0, 0, 0, 255) # Too short -> ignored
assert theme.parseColor("#ff00007f15").getRgb() == (0, 0, 0, 255) # Too long -> ignored
# Name + Alpha
assert theme.parseColor("red:255").getRgb() == (255, 0, 0, 255)
assert theme.parseColor("red:127").getRgb() == (255, 0, 0, 127)
assert theme.parseColor("red:512").getRgb() == (255, 0, 0, 255) # Value truncated
# Values
assert theme.parseColor("255, 0, 0").getRgb() == (255, 0, 0, 255)
assert theme.parseColor("255, 0, 0, 255").getRgb() == (255, 0, 0, 255)
assert theme.parseColor("255, 0, 0, 127").getRgb() == (255, 0, 0, 127)
assert theme.parseColor("255, 0, 0, 127, 42").getRgb() == (255, 0, 0, 127) # Truncated
@pytest.mark.gui @pytest.mark.gui
@pytest.mark.skip @pytest.mark.skip
def testGuiTheme_Theme(qtbot, monkeypatch, nwGUI, tstPaths): def testGuiTheme_Theme(qtbot, monkeypatch, nwGUI, tstPaths):