forked from VisoMasterFusion/VisoMaster-Fusion
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
74 lines (64 loc) · 2.25 KB
/
Copy pathmain.py
File metadata and controls
74 lines (64 loc) · 2.25 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
62
63
64
65
66
67
68
69
70
71
72
73
74
import sys
import traceback
from datetime import datetime
from pathlib import Path
def _write_crash_log(exc: BaseException) -> Path:
"""Persist a full traceback to disk so the diagnostic survives even if the
console window closes before the user can copy it.
Returns the path of the written log so the caller can print it.
"""
log_dir = Path(__file__).resolve().parent / "crash_logs"
log_dir.mkdir(exist_ok=True)
stamp = datetime.now().strftime("%Y%m%d_%H%M%S")
log_path = log_dir / f"crash_{stamp}.log"
with open(log_path, "w", encoding="utf-8") as f:
f.write(f"VisoMaster crash report — {datetime.now().isoformat()}\n")
f.write("=" * 70 + "\n")
try:
import platform
f.write(f"Python: {sys.version}\n")
f.write(f"Platform: {platform.platform()}\n")
except Exception:
pass
f.write("=" * 70 + "\n\n")
traceback.print_exception(type(exc), exc, exc.__traceback__, file=f)
return log_path
def _run_app() -> None:
"""Boot the Qt app. Imports are inside the function so any startup error is
captured by the outer try/except (otherwise a top-level import error would
bypass the crash-log writer)."""
from app.ui import main_ui
from PySide6 import QtWidgets
import qdarktheme
from app.ui.core.proxy_style import ProxyStyle
app = QtWidgets.QApplication(sys.argv)
app.setStyle(ProxyStyle())
with open("app/ui/styles/true_dark_styles.qss", "r") as f:
_style = f.read()
_style = (
qdarktheme.load_stylesheet(
theme="dark", custom_colors={"primary": "#4090a3"}
)
+ "\n"
+ _style
)
app.setStyleSheet(_style)
window = main_ui.MainWindow()
window.show()
app.exec()
if __name__ == "__main__":
try:
_run_app()
except KeyboardInterrupt:
pass
except Exception as e:
log_path = _write_crash_log(e)
print("\n" + "=" * 70)
print("[FATAL] VisoMaster crashed.")
print(" Crash log written to:")
print(f" {log_path}")
print(f" Error: {e}")
print("=" * 70)
print("\nFull traceback:")
traceback.print_exc()
sys.exit(1)