From 551a7609f865b7ea055972ab20c829a4e78a2a1b Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Tue, 8 Jul 2025 15:19:33 +0200 Subject: [PATCH] Preserve status icon custom colour when switching theme (#2452) --- novelwriter/core/status.py | 3 ++- tests/test_core/test_core_status.py | 42 +++++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/novelwriter/core/status.py b/novelwriter/core/status.py index c3e58b76..3576e4a3 100644 --- a/novelwriter/core/status.py +++ b/novelwriter/core/status.py @@ -192,7 +192,8 @@ class NWStatus: def refreshIcons(self) -> None: """Refresh all icons.""" for entry in self._store.values(): - entry.color = SHARED.theme.parseColor(entry.theme) + if entry.theme != CUSTOM_COL: + entry.color = SHARED.theme.parseColor(entry.theme) entry.icon = NWStatus.createIcon(self._height, entry.color, entry.shape) return diff --git a/tests/test_core/test_core_status.py b/tests/test_core/test_core_status.py index 1ea0c09e..7927678e 100644 --- a/tests/test_core/test_core_status.py +++ b/tests/test_core/test_core_status.py @@ -324,23 +324,55 @@ def testCoreStatus_Entries(mockGUI, mockRnd): @pytest.mark.core -def testCoreStatus_RefreshIcons(mockGUIwithTheme, mockRnd): - """Test refreshing the icons of the NWStatus class.""" +def testCoreStatus_RefreshIcons_Theme(mockGUIwithTheme, mockRnd): + """Test refreshing the icons with theme colours.""" nStatus = NWStatus(NWStatus.STATUS) nStatus.add(None, "New", "default", "SQUARE", 0) nStatus.add(None, "Note", "red", "CIRCLE", 0) nStatus.add(None, "Draft", "yellow", "SQUARE", 0) nStatus.add(None, "Finished", "green", "SQUARE", 0) - beforeIcons = [nStatus[statusKeys[i]].icon for i in range(4)] + iconsA = [nStatus[statusKeys[i]].icon for i in range(4)] + themeA = [nStatus[statusKeys[i]].theme for i in range(4)] # Refreshing the icons should generate new ones nStatus.refreshIcons() - afterIcons = [nStatus[statusKeys[i]].icon for i in range(4)] + iconsB = [nStatus[statusKeys[i]].icon for i in range(4)] + themeB = [nStatus[statusKeys[i]].theme for i in range(4)] - for before, after in zip(beforeIcons, afterIcons, strict=False): + for before, after in zip(iconsA, iconsB, strict=False): assert before is not after + assert themeA == themeB + + +@pytest.mark.core +def testCoreStatus_RefreshIcons_Custom(mockGUIwithTheme, mockRnd): + """Test refreshing the icons with custom colours.""" + nStatus = NWStatus(NWStatus.STATUS) + nStatus.add(None, "New", "#707070", "SQUARE", 0) + nStatus.add(None, "Note", "#ff0000", "CIRCLE", 0) + nStatus.add(None, "Draft", "#ffff00", "SQUARE", 0) + nStatus.add(None, "Finished", "#00ff00", "SQUARE", 0) + + iconsA = [nStatus[statusKeys[i]].icon for i in range(4)] + themeA = [nStatus[statusKeys[i]].theme for i in range(4)] + colorA = [nStatus[statusKeys[i]].color.getRgb() for i in range(4)] + + # Refreshing the icons should generate new ones + nStatus.refreshIcons() + iconsB = [nStatus[statusKeys[i]].icon for i in range(4)] + themeB = [nStatus[statusKeys[i]].theme for i in range(4)] + colorB = [nStatus[statusKeys[i]].color.getRgb() for i in range(4)] + + for before, after in zip(iconsA, iconsB, strict=False): + assert before is not after + + # But they should have the same colour value (#2452) + assert themeA == [CUSTOM_COL, CUSTOM_COL, CUSTOM_COL, CUSTOM_COL] + assert themeB == [CUSTOM_COL, CUSTOM_COL, CUSTOM_COL, CUSTOM_COL] + assert colorA == colorB + @pytest.mark.core def testCoreStatus_Pack(mockGUIwithTheme, mockRnd):