-
-
Notifications
You must be signed in to change notification settings - Fork 602
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
添加系统主题监听器 SystemThemeListener (#954)
- Loading branch information
Showing
4 changed files
with
50 additions
and
4 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
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,27 @@ | ||
# coding:utf-8 | ||
from PyQt5.QtCore import QThread, pyqtSignal | ||
|
||
from .config import Theme, qconfig | ||
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() |