-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
49 lines (41 loc) · 1.49 KB
/
Copy pathmain.py
File metadata and controls
49 lines (41 loc) · 1.49 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
import sys
import traceback
import logging
from PyQt6.QtWidgets import QApplication
from config import ensure_dirs, setup_logging
from core.migrator import Migrator
from ui.main_window import PCPlanner
def excepthook(exc_type, exc_value, exc_tb):
"""Global exception handler to catch crashes."""
tb = "".join(traceback.format_exception(exc_type, exc_value, exc_tb))
logging.critical("Uncaught exception:\n" + tb)
# Print to stderr as well for console visibility
print("Critical Error! Check logs for details.", file=sys.stderr)
sys.__excepthook__(exc_type, exc_value, exc_tb)
def main():
sys.excepthook = excepthook
# robust setup
try:
ensure_dirs()
setup_logging()
except Exception as e:
print(f"Critical initialization failure: {e}", file=sys.stderr)
sys.exit(1)
# Run data migration if needed
try:
Migrator.run_migration()
except Exception as e:
logging.critical(f"Migration failed during startup: {e}", exc_info=True)
# We continue startup; DataManager will initialize an empty DB if needed.
try:
app = QApplication(sys.argv)
# Set app metadata
app.setApplicationName("PC Planner")
window = PCPlanner()
window.show()
sys.exit(app.exec())
except Exception as e:
logging.critical(f"Application crash: {e}", exc_info=True)
raise
if __name__ == '__main__':
main()