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
+25 -2
View File
@@ -1,12 +1,14 @@
from __future__ import annotations
import argparse
import logging
import sys
from pathlib import Path
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QApplication
from . import __version__
from .doc_check import main as check_documents_main
from .logging_config import setup_logging
from .main_window import MainWindow
@@ -20,17 +22,38 @@ def parse_arguments(argv: list[str]) -> argparse.Namespace:
return parser.parse_args(argv)
def runtime_paths(project_root_arg: str | None = None) -> tuple[Path, Path]:
if project_root_arg:
root = Path(project_root_arg).resolve()
return root, root
if getattr(sys, "frozen", False):
content_root = Path(getattr(sys, "_MEIPASS")).resolve()
log_root = Path(sys.executable).resolve().parent
return content_root, log_root
root = Path(__file__).resolve().parent.parent
return root, root
def main(argv: list[str] | None = None) -> int:
args = parse_arguments(list(sys.argv[1:] if argv is None else argv))
project_root = Path(args.project_root).resolve() if args.project_root else Path(__file__).resolve().parent.parent
project_root, log_root = runtime_paths(args.project_root)
if args.check:
return check_documents_main([str(project_root)])
QApplication.setAttribute(Qt.ApplicationAttribute.AA_DontCreateNativeWidgetSiblings, True)
setup_logging(project_root)
setup_logging(log_root)
logging.getLogger(__name__).info(
"Starting MDHelper %s with project_root=%s log_root=%s",
__version__,
project_root,
log_root,
)
app = QApplication([sys.argv[0]])
app.setApplicationName("MDHelper")
app.setApplicationVersion(__version__)
app.setOrganizationName("MDHelper")
initial_path = Path(args.file).expanduser().resolve() if args.file else None