Add caching logging packaging and annotation management

This commit is contained in:
2026-06-29 15:26:55 +08:00
parent d34529c7bf
commit 736f9249b9
11 changed files with 303 additions and 25 deletions
+33 -1
View File
@@ -1,19 +1,51 @@
from __future__ import annotations
import logging
import sys
from pathlib import Path
from PySide6.QtCore import QStandardPaths
from PySide6.QtGui import QIcon
from PySide6.QtWidgets import QApplication
from PySide6.QtWidgets import QApplication, QMessageBox
from pdfreaderlite import __version__
from pdfreaderlite.resources import software_icon_path
from pdfreaderlite.ui.main_window import MainWindow
def configure_logging() -> Path:
log_dir = Path(
QStandardPaths.writableLocation(QStandardPaths.StandardLocation.AppDataLocation)
)
log_dir.mkdir(parents=True, exist_ok=True)
log_path = log_dir / "PDFReaderLite.log"
logging.basicConfig(
filename=log_path,
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
encoding="utf-8",
)
logging.info("PDFReaderLite %s started", __version__)
return log_path
def main() -> int:
app = QApplication(sys.argv)
app.setApplicationName("PDFReaderLite")
app.setOrganizationName("PDFReaderLite")
app.setApplicationVersion(__version__)
app.setWindowIcon(QIcon(software_icon_path().as_posix()))
log_path = configure_logging()
def handle_exception(exc_type, exc_value, exc_traceback) -> None:
logging.exception("Unhandled exception", exc_info=(exc_type, exc_value, exc_traceback))
QMessageBox.critical(
None,
"程序错误",
f"PDFReaderLite 遇到未处理错误。\n\n日志位置:{log_path}",
)
sys.excepthook = handle_exception
window = MainWindow()
window.show()