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

feat(gui): 新增主题信息标签,移除 custom_qss 兼容,优化重置按钮

- .ui 新增 ThemeInfoLabel 用于展示主题作者和简介
- ALSettingsWidget 新增 _updateThemeInfo 方法,ComboBox 切换时更新信息
- 移除 _loadQss/_applyQss 模块函数及所有 CUSTOM_QSS 引用
- AppInitializer 移除 _applyQss 导入和回退逻辑
- ConfigProvider/ConfigManager 移除 custom_qss 键
- 纯 QSS 导入通过 ThemeManager 打包为 .altheme 统一管理
This commit is contained in:
2026-05-30 21:33:59 +08:00
parent c1004ed2bc
commit a2bc1881bc
5 changed files with 55 additions and 43 deletions
+1 -5
View File
@@ -15,7 +15,6 @@ from PySide6.QtWidgets import QApplication
from gui.ALSettingsWidget import ( from gui.ALSettingsWidget import (
_setActiveStyleName, _setActiveStyleName,
_applyTheme, _applyTheme,
_applyQss,
) )
from interfaces.ConfigProvider import CfgKey from interfaces.ConfigProvider import CfgKey
from managers.config.ConfigManager import instance as configInstance from managers.config.ConfigManager import instance as configInstance
@@ -80,7 +79,6 @@ def _initializeAppearance(
cfg = configInstance() cfg = configInstance()
saved_style = cfg.get(CfgKey.GLOBAL.APPEARANCE.STYLE, "Fusion") saved_style = cfg.get(CfgKey.GLOBAL.APPEARANCE.STYLE, "Fusion")
saved_theme = cfg.get(CfgKey.GLOBAL.APPEARANCE.THEME, "system") saved_theme = cfg.get(CfgKey.GLOBAL.APPEARANCE.THEME, "system")
saved_qss = cfg.get(CfgKey.GLOBAL.APPEARANCE.CUSTOM_QSS, "")
saved_custom_theme = cfg.get(CfgKey.GLOBAL.APPEARANCE.CUSTOM_THEME, "") saved_custom_theme = cfg.get(CfgKey.GLOBAL.APPEARANCE.CUSTOM_THEME, "")
app.setStyle(saved_style) app.setStyle(saved_style)
_setActiveStyleName(saved_style) _setActiveStyleName(saved_style)
@@ -89,9 +87,7 @@ def _initializeAppearance(
from managers.theme.ThemeManager import instance as themeInstance from managers.theme.ThemeManager import instance as themeInstance
themeInstance().applyTheme(saved_custom_theme) themeInstance().applyTheme(saved_custom_theme)
except Exception: except Exception:
_applyQss(saved_qss) pass
else:
_applyQss(saved_qss)
_applyTheme(saved_theme) _applyTheme(saved_theme)
def initializeApp( def initializeApp(
+29 -27
View File
@@ -69,31 +69,6 @@ def _applyThemeByName(
except Exception: except Exception:
_clearQss() _clearQss()
def _loadQss(
file_path: str
) -> str:
if not file_path or not os.path.isfile(file_path):
return ""
try:
with open(file_path, "r", encoding="utf-8") as fh:
return fh.read()
except Exception:
return ""
def _applyQss(
file_path: str
):
app : QApplication | None = QApplication.instance()
if not app:
return
qss = _loadQss(file_path)
if qss:
app.setStyleSheet(qss)
else:
_clearQss()
def _applyTheme( def _applyTheme(
theme: str theme: str
): ):
@@ -173,6 +148,7 @@ class ALSettingsWidget(QWidget, Ui_ALSettingsWidget):
): ):
self.BrowseQssButton.clicked.connect(self.onImportThemeButtonClicked) self.BrowseQssButton.clicked.connect(self.onImportThemeButtonClicked)
self.ThemeComboBox.currentTextChanged.connect(self.onThemeComboBoxChanged)
self.ResetQssButton.clicked.connect(self.onResetQssButtonClicked) self.ResetQssButton.clicked.connect(self.onResetQssButtonClicked)
self.CancelButton.clicked.connect(self.onCancelButtonClicked) self.CancelButton.clicked.connect(self.onCancelButtonClicked)
self.ApplyButton.clicked.connect(self.onApplyButtonClicked) self.ApplyButton.clicked.connect(self.onApplyButtonClicked)
@@ -233,6 +209,7 @@ class ALSettingsWidget(QWidget, Ui_ALSettingsWidget):
if idx >= 0: if idx >= 0:
self.ThemeComboBox.setCurrentIndex(idx) self.ThemeComboBox.setCurrentIndex(idx)
self.updateThemeStatus() self.updateThemeStatus()
self._updateThemeInfo()
def updateThemeStatus( def updateThemeStatus(
self self
@@ -240,9 +217,25 @@ class ALSettingsWidget(QWidget, Ui_ALSettingsWidget):
name = self.ThemeComboBox.currentText() name = self.ThemeComboBox.currentText()
if name and name != "默认": if name and name != "默认":
self.QssStatusLabel.setText(f"已加载主题:{name}") self.QssStatusLabel.setText(f"当前使用 {name} 主题。")
else: else:
self.QssStatusLabel.setText("当前使用程序默认外观") self.QssStatusLabel.setText("当前使用 默认 主题")
def _updateThemeInfo(
self
):
name = self.ThemeComboBox.currentText()
if not name or name == "默认":
self.ThemeInfoLabel.setText("")
return
t = self.__theme_cache.get(name)
if t:
author = t.get("author", "未知")
brief = t.get("brief", "没有相关简介")
self.ThemeInfoLabel.setText(f"作者:{author}\n简介:{brief}")
else:
self.ThemeInfoLabel.setText("")
def _syncRadioFromNeedTheme( def _syncRadioFromNeedTheme(
self, self,
@@ -287,6 +280,7 @@ class ALSettingsWidget(QWidget, Ui_ALSettingsWidget):
_applyTheme(theme) _applyTheme(theme)
self.setNavigationIcons() self.setNavigationIcons()
self.updateThemeStatus() self.updateThemeStatus()
self._updateThemeInfo()
self.__original_style = self.currentStyleKey() self.__original_style = self.currentStyleKey()
def maybeRestart( def maybeRestart(
@@ -341,6 +335,7 @@ class ALSettingsWidget(QWidget, Ui_ALSettingsWidget):
if idx >= 0: if idx >= 0:
self.ThemeComboBox.setCurrentIndex(idx) self.ThemeComboBox.setCurrentIndex(idx)
self.updateThemeStatus() self.updateThemeStatus()
self._updateThemeInfo()
except Exception as e: except Exception as e:
QMessageBox.warning( QMessageBox.warning(
self, self,
@@ -348,6 +343,13 @@ class ALSettingsWidget(QWidget, Ui_ALSettingsWidget):
f"无法导入主题文件:{e}" f"无法导入主题文件:{e}"
) )
@Slot()
def onThemeComboBoxChanged(
self
):
self._updateThemeInfo()
@Slot() @Slot()
def onResetQssButtonClicked( def onResetQssButtonClicked(
self self
+25 -9
View File
@@ -283,15 +283,15 @@
</item> </item>
<item> <item>
<widget class="QLineEdit" name="QssPathEdit"> <widget class="QLineEdit" name="QssPathEdit">
<property name="visible">
<bool>false</bool>
</property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>0</width> <width>0</width>
<height>25</height> <height>25</height>
</size> </size>
</property> </property>
<property name="visible">
<bool>false</bool>
</property>
<property name="placeholderText"> <property name="placeholderText">
<string>选择或输入 QSS 样式表文件路径...</string> <string>选择或输入 QSS 样式表文件路径...</string>
</property> </property>
@@ -301,17 +301,33 @@
<widget class="QPushButton" name="BrowseQssButton"> <widget class="QPushButton" name="BrowseQssButton">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>60</width> <width>25</width>
<height>25</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>25</width>
<height>25</height> <height>25</height>
</size> </size>
</property> </property>
<property name="text"> <property name="text">
<string>导入</string> <string>...</string>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</item> </item>
<item>
<widget class="QLabel" name="ThemeInfoLabel">
<property name="text">
<string/>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item> <item>
<layout class="QHBoxLayout" name="QssActionLayout"> <layout class="QHBoxLayout" name="QssActionLayout">
<property name="spacing"> <property name="spacing">
@@ -319,15 +335,15 @@
</property> </property>
<item> <item>
<widget class="QPushButton" name="ApplyQssButton"> <widget class="QPushButton" name="ApplyQssButton">
<property name="visible">
<bool>false</bool>
</property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>80</width> <width>80</width>
<height>25</height> <height>25</height>
</size> </size>
</property> </property>
<property name="visible">
<bool>false</bool>
</property>
<property name="text"> <property name="text">
<string>应用样式</string> <string>应用样式</string>
</property> </property>
@@ -364,7 +380,7 @@
<item> <item>
<widget class="QLabel" name="QssStatusLabel"> <widget class="QLabel" name="QssStatusLabel">
<property name="text"> <property name="text">
<string>当前使用程序默认外观。</string> <string>当前使用程序 默认 外观。</string>
</property> </property>
<property name="wordWrap"> <property name="wordWrap">
<bool>true</bool> <bool>true</bool>
-1
View File
@@ -70,7 +70,6 @@ class CfgKey:
ROOT = ConfigPath(ConfigType.GLOBAL, "appearance") ROOT = ConfigPath(ConfigType.GLOBAL, "appearance")
THEME = ConfigPath(ConfigType.GLOBAL, "appearance.theme") THEME = ConfigPath(ConfigType.GLOBAL, "appearance.theme")
STYLE = ConfigPath(ConfigType.GLOBAL, "appearance.style") STYLE = ConfigPath(ConfigType.GLOBAL, "appearance.style")
CUSTOM_QSS = ConfigPath(ConfigType.GLOBAL, "appearance.custom_qss")
CUSTOM_THEME = ConfigPath(ConfigType.GLOBAL, "appearance.custom_theme") CUSTOM_THEME = ConfigPath(ConfigType.GLOBAL, "appearance.custom_theme")
class TIMERTASK: class TIMERTASK:
-1
View File
@@ -58,7 +58,6 @@ class ConfigTemplate:
"appearance": { "appearance": {
"theme": "system", "theme": "system",
"style": "Fusion", "style": "Fusion",
"custom_qss": "",
"custom_theme": "" "custom_theme": ""
} }
} }