Improve MDHelper themes and packaging

This commit is contained in:
shenw
2026-05-25 22:00:37 +08:00
parent 2d896a618f
commit 0d2f62817b
41 changed files with 3729 additions and 86 deletions
+27 -7
View File
@@ -16,6 +16,8 @@ from PySide6.QtWidgets import (
@dataclass(frozen=True)
class AppPreferences:
theme: str
theme_color: str
theme_background: str
font_scale: float
auto_refresh: bool
non_preview_action: str
@@ -27,10 +29,25 @@ class SettingsDialog(QDialog):
self.setWindowTitle("设置")
self.setMinimumWidth(420)
self.theme_combo = QComboBox()
self.theme_combo.addItem("浅色", "light")
self.theme_combo.addItem("深色", "dark")
self.theme_combo.setCurrentIndex(max(0, self.theme_combo.findData(preferences.theme)))
self.theme_color_combo = QComboBox()
self.theme_color_combo.addItem("白色", "white")
self.theme_color_combo.addItem("黑色", "black")
self.theme_color_combo.addItem("深灰色", "dark_gray")
self.theme_color_combo.addItem("彩色", "colorful")
self.theme_color_combo.setCurrentIndex(max(0, self.theme_color_combo.findData(preferences.theme_color)))
self.theme_background_combo = QComboBox()
self.theme_background_combo.addItem("无", "none")
self.theme_background_combo.addItem("春天", "spring")
self.theme_background_combo.addItem("稻草", "straw")
self.theme_background_combo.addItem("电路", "circuit")
self.theme_background_combo.addItem("年轮", "tree_rings")
self.theme_background_combo.addItem("几何图形", "geometry")
self.theme_background_combo.addItem("书法", "calligraphy")
self.theme_background_combo.addItem("水下", "underwater")
self.theme_background_combo.setCurrentIndex(
max(0, self.theme_background_combo.findData(preferences.theme_background))
)
self.font_scale_spin = QDoubleSpinBox()
self.font_scale_spin.setRange(0.8, 1.6)
@@ -48,7 +65,8 @@ class SettingsDialog(QDialog):
self.non_preview_combo.setCurrentIndex(max(0, self.non_preview_combo.findData(preferences.non_preview_action)))
form = QFormLayout()
form.addRow("主题", self.theme_combo)
form.addRow("主题颜色", self.theme_color_combo)
form.addRow("主题背景", self.theme_background_combo)
form.addRow("正文字号倍率", self.font_scale_spin)
form.addRow("自动刷新", self.auto_refresh_checkbox)
form.addRow("其他本地文件", self.non_preview_combo)
@@ -62,10 +80,12 @@ class SettingsDialog(QDialog):
layout.addWidget(buttons)
def preferences(self) -> AppPreferences:
theme_color = str(self.theme_color_combo.currentData())
return AppPreferences(
theme=str(self.theme_combo.currentData()),
theme="dark" if theme_color in {"black", "dark_gray"} else "light",
theme_color=theme_color,
theme_background=str(self.theme_background_combo.currentData()),
font_scale=float(self.font_scale_spin.value()),
auto_refresh=self.auto_refresh_checkbox.isChecked(),
non_preview_action=str(self.non_preview_combo.currentData()),
)