-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpdfapps.py
More file actions
61 lines (48 loc) · 1.6 KB
/
pdfapps.py
File metadata and controls
61 lines (48 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""PDFApps – entry point."""
import sys
import os
from PySide6.QtWidgets import QApplication, QMessageBox
try:
from pypdf import PdfReader, PdfWriter
except ImportError:
_app = QApplication(sys.argv)
QMessageBox.critical(None, "Missing dependency",
"Install the pypdf library:\n\npip install pypdf")
sys.exit(1)
try:
import fitz # PyMuPDF — used by viewer render, editor, most tools
del fitz
except ImportError:
_app = QApplication(sys.argv)
QMessageBox.critical(None, "Missing dependency",
"Install PyMuPDF:\n\npip install pymupdf")
sys.exit(1)
from app.window import MainWindow
from app.styles import STYLE, STYLE_LIGHT
from app.utils import _make_palette
def _load_dark_pref() -> bool:
try:
import json
from app.i18n import _CONFIG_PATH
with open(_CONFIG_PATH, "r", encoding="utf-8") as f:
return json.load(f).get("dark_mode", True)
except Exception:
return True
def main():
app = QApplication(sys.argv)
app.setApplicationName(" ")
app.setApplicationDisplayName(" ")
app.setStyle("Fusion")
dark = _load_dark_pref()
app.setPalette(_make_palette(dark))
app.setStyleSheet(STYLE if dark else STYLE_LIGHT)
window = MainWindow()
window.show()
# Open PDF passed as argument (e.g.: double-click on a .pdf file)
if len(sys.argv) > 1:
pdf_arg = sys.argv[1]
if os.path.isfile(pdf_arg) and pdf_arg.lower().endswith(".pdf"):
window._viewer.load(pdf_arg)
sys.exit(app.exec())
if __name__ == "__main__":
main()