-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from qfluentwidgets import setTheme, Theme, qconfig | ||
from PyQt5.QtCore import QThread, pyqtSignal | ||
import darkdetect | ||
|
||
|
||
class SystemThemeListener(QThread): | ||
""" System theme listener """ | ||
systemThemeChanged = pyqtSignal() | ||
|
||
def __init__(self, parent=None): | ||
super().__init__(parent=parent) | ||
|
||
def run(self): | ||
darkdetect.listener(self._onThemeChanged) | ||
|
||
def _onThemeChanged(self, theme: str): | ||
theme = Theme.DARK if theme.lower() == "dark" else Theme.LIGHT | ||
if qconfig.themeMode.value != Theme.AUTO or theme == qconfig.theme: | ||
return | ||
qconfig.theme = Theme.AUTO | ||
qconfig._cfg.themeChanged.emit(Theme.AUTO) | ||
self.systemThemeChanged.emit() | ||
|
||
|
||
def checkThemeChange(self): | ||
def handle_theme_change(): | ||
setTheme(Theme.AUTO, lazy=True) | ||
|
||
self.themeListener = SystemThemeListener(self) | ||
self.themeListener.systemThemeChanged.connect(handle_theme_change) | ||
self.themeListener.start() | ||
return self.themeListener |