From 60318db02e19ab47bec1c147a5da3e1e53838dd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <101191390+HIllya51@users.noreply.github.com> Date: Mon, 1 Apr 2024 14:52:51 +0800 Subject: [PATCH] Update settin.py --- LunaTranslator/LunaTranslator/gui/settin.py | 29 ++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/LunaTranslator/LunaTranslator/gui/settin.py b/LunaTranslator/LunaTranslator/gui/settin.py index e4cbd869..847875fd 100644 --- a/LunaTranslator/LunaTranslator/gui/settin.py +++ b/LunaTranslator/LunaTranslator/gui/settin.py @@ -1,9 +1,9 @@ -from PyQt5.QtCore import pyqtSignal ,Qt,QSize -from PyQt5.QtWidgets import QLabel,QScrollArea,QWidget,QGridLayout,QVBoxLayout,QListWidget,QHBoxLayout,QListWidgetItem +from PyQt5.QtCore import pyqtSignal ,Qt,QSize,QObject,QEvent +from PyQt5.QtWidgets import QLabel,QScrollArea,QWidget,QGridLayout,QVBoxLayout,QListWidget,QHBoxLayout,QListWidgetItem,QApplication from PyQt5.QtGui import QResizeEvent from PyQt5.QtWidgets import QTabWidget -import qtawesome,darkdetect +import qtawesome,darkdetect,ctypes import functools from traceback import print_exc from myutils.config import globalconfig ,_TR @@ -185,6 +185,29 @@ class Settin(closeashidewindow) : dark=darkdetect.isDark() darklight=['light','dark'][dark] + top_level_widgets = QApplication.topLevelWidgets() + def ChangeDWMAttrib(hWnd: int, attrib: int, color) -> None: + try: + ctypes.windll.dwmapi.DwmSetWindowAttribute(hWnd, attrib, ctypes.byref(color), ctypes.sizeof(ctypes.c_int)) + except: + pass + def darkchange(hwnd): + if dark: + ChangeDWMAttrib(hwnd, 19, ctypes.c_int(1)) + ChangeDWMAttrib(hwnd, 20, ctypes.c_int(1)) + else: + ChangeDWMAttrib(hwnd, 19, ctypes.c_int(0)) + ChangeDWMAttrib(hwnd, 20, ctypes.c_int(0)) + class WindowEventFilter(QObject): + def eventFilter(self, obj, event): + if event.type() == QEvent.Type.WindowTitleChange: + darkchange(int(obj.winId())) + return False + self.__filter=WindowEventFilter() + QApplication.instance().installEventFilter(self.__filter) + for widget in top_level_widgets: + darkchange(int(widget.winId())) + try: idx=globalconfig[darklight+'theme']-int(not dark) if idx==-1:raise Exception()