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
+56 -1
View File
@@ -12,7 +12,7 @@ os.environ.setdefault("QTWEBENGINE_DISABLE_SANDBOX", "1")
PROJECT_ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(PROJECT_ROOT))
from PySide6.QtCore import QTimer
from PySide6.QtCore import QTimer, QUrl
from PySide6.QtWidgets import QApplication
from mdhelper.main_window import MainWindow, ReaderView
@@ -27,6 +27,8 @@ def main() -> int:
checks: list[str] = []
def verify() -> None:
window.find_box.setText("斐波那契")
window.find_next()
if window.current_file != (project_root / "sample.md").resolve():
checks.append("current_file")
if window.tabs.count() < 1:
@@ -37,8 +39,61 @@ def main() -> int:
checks.append("export_pdf_action")
if not window.export_html_action.isEnabled():
checks.append("export_html_action")
if hasattr(window, "theme_action"):
checks.append("theme_toolbar_action")
if not hasattr(window, "theme_menu"):
checks.append("theme_menu")
if window.search_index.search("斐波那契") == []:
checks.append("search_index")
if not window._is_current_page_anchor_url(QUrl("#2-表格示例")):
checks.append("plain_anchor_url")
base_anchor = QUrl.fromLocalFile(str((project_root / "sample.md").resolve().parent))
base_anchor.setFragment("2-表格示例")
if not window._is_current_page_anchor_url(base_anchor):
checks.append("base_anchor_url")
if window._is_current_page_anchor_url(QUrl("mailto:user@example.com#message")):
checks.append("external_fragment_url")
window.katex_action.trigger()
if window.math_engine != "katex":
checks.append("katex_action")
window.mathjax_action.trigger()
if window.math_engine != "mathjax":
checks.append("mathjax_action")
snapshot = window._configuration_snapshot()
if snapshot.get("version") is None:
checks.append("config_version")
if "external_applications" not in snapshot:
checks.append("config_external_applications")
if snapshot.get("reader", {}).get("theme_background") is None:
checks.append("config_theme_background")
window._apply_configuration(
{
"reader": {
"theme_color": "dark_gray",
"theme_background": "circuit",
"math_engine": "katex",
"font_scale": 1.2,
"document_font_family": "Microsoft YaHei UI",
"document_font_size": 18,
"ui_font_family": "Microsoft YaHei UI",
"ui_font_point_size": 10,
},
"recent_files": [str(project_root / "sample.md")],
"bookmarks": [{"path": str(project_root / "sample.md"), "fragment": "", "label": "sample"}],
"scroll_positions": {str(project_root / "sample.md"): 42},
"external_applications": {".mp4": "C:/Tools/player.exe"},
}
)
if window.theme != "dark" or window.theme_color != "dark_gray" or window.math_engine != "katex":
checks.append("config_apply_reader")
if window.theme_background != "circuit":
checks.append("config_apply_theme_background")
if window.document_font_size != 18 or window.document_font_family != "Microsoft YaHei UI":
checks.append("config_apply_document_font")
if window.ui_font_family != "Microsoft YaHei UI" or window.ui_font_point_size != 10:
checks.append("config_apply_ui_font")
if ".mp4" not in window.external_applications:
checks.append("config_apply_external_apps")
window.close()
app.quit()