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 (
_setActiveStyleName,
_applyTheme,
_applyQss,
)
from interfaces.ConfigProvider import CfgKey
from managers.config.ConfigManager import instance as configInstance
@@ -80,7 +79,6 @@ def _initializeAppearance(
cfg = configInstance()
saved_style = cfg.get(CfgKey.GLOBAL.APPEARANCE.STYLE, "Fusion")
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, "")
app.setStyle(saved_style)
_setActiveStyleName(saved_style)
@@ -89,9 +87,7 @@ def _initializeAppearance(
from managers.theme.ThemeManager import instance as themeInstance
themeInstance().applyTheme(saved_custom_theme)
except Exception:
_applyQss(saved_qss)
else:
_applyQss(saved_qss)
pass
_applyTheme(saved_theme)
def initializeApp(
+29 -27
View File
@@ -69,31 +69,6 @@ def _applyThemeByName(
except Exception:
_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(
theme: str
):
@@ -173,6 +148,7 @@ class ALSettingsWidget(QWidget, Ui_ALSettingsWidget):
):
self.BrowseQssButton.clicked.connect(self.onImportThemeButtonClicked)
self.ThemeComboBox.currentTextChanged.connect(self.onThemeComboBoxChanged)
self.ResetQssButton.clicked.connect(self.onResetQssButtonClicked)
self.CancelButton.clicked.connect(self.onCancelButtonClicked)
self.ApplyButton.clicked.connect(self.onApplyButtonClicked)
@@ -233,6 +209,7 @@ class ALSettingsWidget(QWidget, Ui_ALSettingsWidget):
if idx >= 0:
self.ThemeComboBox.setCurrentIndex(idx)
self.updateThemeStatus()
self._updateThemeInfo()
def updateThemeStatus(
self
@@ -240,9 +217,25 @@ class ALSettingsWidget(QWidget, Ui_ALSettingsWidget):
name = self.ThemeComboBox.currentText()
if name and name != "默认":
self.QssStatusLabel.setText(f"已加载主题:{name}")
self.QssStatusLabel.setText(f"当前使用 {name} 主题。")
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(
self,
@@ -287,6 +280,7 @@ class ALSettingsWidget(QWidget, Ui_ALSettingsWidget):
_applyTheme(theme)
self.setNavigationIcons()
self.updateThemeStatus()
self._updateThemeInfo()
self.__original_style = self.currentStyleKey()
def maybeRestart(
@@ -341,6 +335,7 @@ class ALSettingsWidget(QWidget, Ui_ALSettingsWidget):
if idx >= 0:
self.ThemeComboBox.setCurrentIndex(idx)
self.updateThemeStatus()
self._updateThemeInfo()
except Exception as e:
QMessageBox.warning(
self,
@@ -348,6 +343,13 @@ class ALSettingsWidget(QWidget, Ui_ALSettingsWidget):
f"无法导入主题文件:{e}"
)
@Slot()
def onThemeComboBoxChanged(
self
):
self._updateThemeInfo()
@Slot()
def onResetQssButtonClicked(
self
+25 -9
View File
@@ -283,15 +283,15 @@
</item>
<item>
<widget class="QLineEdit" name="QssPathEdit">
<property name="visible">
<bool>false</bool>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
</size>
</property>
<property name="visible">
<bool>false</bool>
</property>
<property name="placeholderText">
<string>选择或输入 QSS 样式表文件路径...</string>
</property>
@@ -301,17 +301,33 @@
<widget class="QPushButton" name="BrowseQssButton">
<property name="minimumSize">
<size>
<width>60</width>
<width>25</width>
<height>25</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>25</width>
<height>25</height>
</size>
</property>
<property name="text">
<string>导入</string>
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="ThemeInfoLabel">
<property name="text">
<string/>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="QssActionLayout">
<property name="spacing">
@@ -319,15 +335,15 @@
</property>
<item>
<widget class="QPushButton" name="ApplyQssButton">
<property name="visible">
<bool>false</bool>
</property>
<property name="minimumSize">
<size>
<width>80</width>
<height>25</height>
</size>
</property>
<property name="visible">
<bool>false</bool>
</property>
<property name="text">
<string>应用样式</string>
</property>
@@ -364,7 +380,7 @@
<item>
<widget class="QLabel" name="QssStatusLabel">
<property name="text">
<string>当前使用程序默认外观。</string>
<string>当前使用程序 默认 外观。</string>
</property>
<property name="wordWrap">
<bool>true</bool>
-1
View File
@@ -70,7 +70,6 @@ class CfgKey:
ROOT = ConfigPath(ConfigType.GLOBAL, "appearance")
THEME = ConfigPath(ConfigType.GLOBAL, "appearance.theme")
STYLE = ConfigPath(ConfigType.GLOBAL, "appearance.style")
CUSTOM_QSS = ConfigPath(ConfigType.GLOBAL, "appearance.custom_qss")
CUSTOM_THEME = ConfigPath(ConfigType.GLOBAL, "appearance.custom_theme")
class TIMERTASK:
-1
View File
@@ -58,7 +58,6 @@ class ConfigTemplate:
"appearance": {
"theme": "system",
"style": "Fusion",
"custom_qss": "",
"custom_theme": ""
}
}