-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy paththeme_manager.py
More file actions
32 lines (26 loc) · 926 Bytes
/
Copy paththeme_manager.py
File metadata and controls
32 lines (26 loc) · 926 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""主题管理器 — 集中管理所有需手动更新的主题回调。
Fluent 控件自动响应 qconfig.themeChanged。
这里仅注册原生 Qt 等需要手动更新的 widget。
"""
from __future__ import annotations
from collections.abc import Callable
class ThemeManager:
"""单例式主题回调管理器。"""
_callbacks: list[Callable[[bool], None]] = []
@classmethod
def register(cls, fn: Callable[[bool], None]) -> Callable[[bool], None]:
cls._callbacks.append(fn)
return fn
@classmethod
def unregister(cls, fn: Callable[[bool], None]) -> None:
if fn in cls._callbacks:
cls._callbacks.remove(fn)
@classmethod
def refresh(cls) -> None:
from qfluentwidgets import isDarkTheme
dark = isDarkTheme()
for fn in cls._callbacks:
try:
fn(dark)
except Exception:
pass