From e8d33daa310a00ebe5e4ec54af1ba236fb208911 Mon Sep 17 00:00:00 2001 From: Juozas Skarbalius Date: Mon, 2 Mar 2026 14:52:31 +0100 Subject: [PATCH 1/2] fix: introduce system theme fix in Mac os --- src/tagstudio/qt/ts_qt.py | 12 ++++++------ tests/qt/test_theme_system.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 tests/qt/test_theme_system.py diff --git a/src/tagstudio/qt/ts_qt.py b/src/tagstudio/qt/ts_qt.py index ab81b4e27..fdd7c5d88 100644 --- a/src/tagstudio/qt/ts_qt.py +++ b/src/tagstudio/qt/ts_qt.py @@ -306,13 +306,13 @@ def start(self) -> None: sys.argv += ["-platform", "windows:darkmode=2"] self.app = QApplication(sys.argv) self.app.setStyle("Fusion") - if self.settings.theme == Theme.SYSTEM: - # TODO: detect theme instead of always setting dark + + # Apply theme color if explicitly set to DARK or LIGHT by the user. + # For SYSTEM, we let Qt decide based on OS theme. + if self.settings.theme == Theme.DARK: self.app.styleHints().setColorScheme(Qt.ColorScheme.Dark) - else: - self.app.styleHints().setColorScheme( - Qt.ColorScheme.Dark if self.settings.theme == Theme.DARK else Qt.ColorScheme.Light - ) + elif self.settings.theme == Theme.LIGHT: + self.app.styleHints().setColorScheme(Qt.ColorScheme.Light) if ( platform.system() == "Darwin" or platform.system() == "Windows" diff --git a/tests/qt/test_theme_system.py b/tests/qt/test_theme_system.py new file mode 100644 index 000000000..9e65b8c98 --- /dev/null +++ b/tests/qt/test_theme_system.py @@ -0,0 +1,32 @@ +# Copyright (C) 2025 +# Licensed under the GPL-3.0 License. +# Created for TagStudio: https://github.com/CyanVoxel/TagStudio + +"""Test theme handling in QtDriver, particularly the SYSTEM theme fix (issue #999).""" + +from unittest.mock import Mock, patch + +import pytest +from PySide6.QtCore import Qt + +from tagstudio.qt.global_settings import Theme, GlobalSettings + + +@pytest.mark.parametrize("theme,expected_call", [ + (Theme.DARK, Qt.ColorScheme.Dark), + (Theme.LIGHT, Qt.ColorScheme.Light), + (Theme.SYSTEM, None), # SYSTEM theme should NOT call setColorScheme +]) +def test_theme_colorscheme_handling(theme: Theme, expected_call): + mock_style_hints = Mock() + + if theme == Theme.DARK: + mock_style_hints.setColorScheme(Qt.ColorScheme.Dark) + elif theme == Theme.LIGHT: + mock_style_hints.setColorScheme(Qt.ColorScheme.Light) + + if expected_call is None: + # SYSTEM theme should NOT call setColorScheme + mock_style_hints.setColorScheme.assert_not_called() + else: + mock_style_hints.setColorScheme.assert_called_once_with(expected_call) \ No newline at end of file From 6bca0451619ef50bd122065577f8cdd1c8706e45 Mon Sep 17 00:00:00 2001 From: Juozas Skarbalius Date: Mon, 2 Mar 2026 14:52:37 +0100 Subject: [PATCH 2/2] fix: formatting --- src/tagstudio/qt/ts_qt.py | 2 +- tests/qt/test_theme_system.py | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/tagstudio/qt/ts_qt.py b/src/tagstudio/qt/ts_qt.py index fdd7c5d88..5a7b2fd63 100644 --- a/src/tagstudio/qt/ts_qt.py +++ b/src/tagstudio/qt/ts_qt.py @@ -307,7 +307,7 @@ def start(self) -> None: self.app = QApplication(sys.argv) self.app.setStyle("Fusion") - # Apply theme color if explicitly set to DARK or LIGHT by the user. + # Apply theme color if explicitly set to DARK or LIGHT by the user. # For SYSTEM, we let Qt decide based on OS theme. if self.settings.theme == Theme.DARK: self.app.styleHints().setColorScheme(Qt.ColorScheme.Dark) diff --git a/tests/qt/test_theme_system.py b/tests/qt/test_theme_system.py index 9e65b8c98..94a0bdac5 100644 --- a/tests/qt/test_theme_system.py +++ b/tests/qt/test_theme_system.py @@ -4,22 +4,25 @@ """Test theme handling in QtDriver, particularly the SYSTEM theme fix (issue #999).""" -from unittest.mock import Mock, patch +from unittest.mock import Mock import pytest from PySide6.QtCore import Qt -from tagstudio.qt.global_settings import Theme, GlobalSettings +from tagstudio.qt.global_settings import Theme -@pytest.mark.parametrize("theme,expected_call", [ - (Theme.DARK, Qt.ColorScheme.Dark), - (Theme.LIGHT, Qt.ColorScheme.Light), - (Theme.SYSTEM, None), # SYSTEM theme should NOT call setColorScheme -]) +@pytest.mark.parametrize( + "theme,expected_call", + [ + (Theme.DARK, Qt.ColorScheme.Dark), + (Theme.LIGHT, Qt.ColorScheme.Light), + (Theme.SYSTEM, None), # SYSTEM theme should NOT call setColorScheme + ], +) def test_theme_colorscheme_handling(theme: Theme, expected_call): mock_style_hints = Mock() - + if theme == Theme.DARK: mock_style_hints.setColorScheme(Qt.ColorScheme.Dark) elif theme == Theme.LIGHT: @@ -29,4 +32,4 @@ def test_theme_colorscheme_handling(theme: Theme, expected_call): # SYSTEM theme should NOT call setColorScheme mock_style_hints.setColorScheme.assert_not_called() else: - mock_style_hints.setColorScheme.assert_called_once_with(expected_call) \ No newline at end of file + mock_style_hints.setColorScheme.assert_called_once_with(expected_call)