1
1
mirror of https://github.com/KenanZhu/AutoLibrary.git synced 2026-06-17 23:13:03 +08:00

refactor(gui): 重命名 _applyThemeByName → _applyCustomTheme,_clearQss → _clearCustomTheme

- _clearCustomTheme(theme) 清除 QSS 后切换到指定默认主题
- _applyCustomTheme(name, fallback_theme) 应用自定义主题,失败时回退到 fallback_theme
- saveAndApply 调用处传入当前 radio 主题作为 fallback
This commit is contained in:
2026-05-30 21:37:15 +08:00
parent a2bc1881bc
commit 732f104c5c
+9 -6
View File
@@ -50,24 +50,27 @@ def _setActiveStyleName(
global _active_style_name
_active_style_name = name
def _clearQss(
def _clearCustomTheme(
theme: str
):
app : QApplication | None = QApplication.instance()
if app:
app.setStyleSheet("")
_applyTheme(theme)
def _applyThemeByName(
name: str
def _applyCustomTheme(
name: str,
fallback_theme: str = "system"
):
if not name:
_clearQss()
_clearCustomTheme(fallback_theme)
return
try:
themeInstance().applyTheme(name)
except Exception:
_clearQss()
_clearCustomTheme(fallback_theme)
def _applyTheme(
theme: str
@@ -274,7 +277,7 @@ class ALSettingsWidget(QWidget, Ui_ALSettingsWidget):
self.__cfg_mgr.set(CfgKey.GLOBAL.APPEARANCE.THEME, theme)
self.__cfg_mgr.set(CfgKey.GLOBAL.APPEARANCE.STYLE, style)
self.__cfg_mgr.set(CfgKey.GLOBAL.APPEARANCE.CUSTOM_THEME, custom_theme)
_applyThemeByName(custom_theme)
_applyCustomTheme(custom_theme, theme)
self._syncRadioFromNeedTheme(custom_theme)
theme, _, _ = self.collectSettings()
_applyTheme(theme)