feat: add system theme detection for sv-ttk
This commit is contained in:
@@ -57,3 +57,51 @@ class TestNoOpTray:
|
|||||||
from whisper_local.tray._tray import AppState, NoOpTray
|
from whisper_local.tray._tray import AppState, NoOpTray
|
||||||
tray = NoOpTray()
|
tray = NoOpTray()
|
||||||
tray.set_state(AppState.RECORDING) # kein Fehler
|
tray.set_state(AppState.RECORDING) # kein Fehler
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skipif(sys.platform != "win32", reason="Theme nur auf Windows")
|
||||||
|
class TestApplySystemTheme:
|
||||||
|
def test_applies_light_theme(self):
|
||||||
|
import tkinter as tk
|
||||||
|
from unittest.mock import patch, MagicMock
|
||||||
|
from whisper_local.tray._theme import apply_system_theme
|
||||||
|
|
||||||
|
root = tk.Tk()
|
||||||
|
root.withdraw()
|
||||||
|
try:
|
||||||
|
with patch("darkdetect.theme", return_value="Light"), \
|
||||||
|
patch("sv_ttk.set_theme") as mock_set:
|
||||||
|
apply_system_theme(root)
|
||||||
|
mock_set.assert_called_once_with("light")
|
||||||
|
finally:
|
||||||
|
root.destroy()
|
||||||
|
|
||||||
|
def test_applies_dark_theme(self):
|
||||||
|
import tkinter as tk
|
||||||
|
from unittest.mock import patch
|
||||||
|
from whisper_local.tray._theme import apply_system_theme
|
||||||
|
|
||||||
|
root = tk.Tk()
|
||||||
|
root.withdraw()
|
||||||
|
try:
|
||||||
|
with patch("darkdetect.theme", return_value="Dark"), \
|
||||||
|
patch("sv_ttk.set_theme") as mock_set:
|
||||||
|
apply_system_theme(root)
|
||||||
|
mock_set.assert_called_once_with("dark")
|
||||||
|
finally:
|
||||||
|
root.destroy()
|
||||||
|
|
||||||
|
def test_falls_back_to_light_when_none(self):
|
||||||
|
import tkinter as tk
|
||||||
|
from unittest.mock import patch
|
||||||
|
from whisper_local.tray._theme import apply_system_theme
|
||||||
|
|
||||||
|
root = tk.Tk()
|
||||||
|
root.withdraw()
|
||||||
|
try:
|
||||||
|
with patch("darkdetect.theme", return_value=None), \
|
||||||
|
patch("sv_ttk.set_theme") as mock_set:
|
||||||
|
apply_system_theme(root)
|
||||||
|
mock_set.assert_called_once_with("light")
|
||||||
|
finally:
|
||||||
|
root.destroy()
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
"""System-Theme-Erkennung und sv-ttk-Anwendung."""
|
||||||
|
|
||||||
|
import tkinter as tk
|
||||||
|
|
||||||
|
|
||||||
|
def apply_system_theme(root: tk.Tk) -> None:
|
||||||
|
"""Setzt sv-ttk-Theme passend zum Windows-System-Theme (Light/Dark)."""
|
||||||
|
import darkdetect
|
||||||
|
import sv_ttk
|
||||||
|
|
||||||
|
detected = darkdetect.theme() or "Light"
|
||||||
|
sv_ttk.set_theme(detected.lower())
|
||||||
Reference in New Issue
Block a user