-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
55 lines (43 loc) · 1.36 KB
/
Copy pathmain.py
File metadata and controls
55 lines (43 loc) · 1.36 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
"""
Shapearator desktop application entry point.
"""
from __future__ import annotations
import logging
import sys
import tkinter as tk
import traceback
from datetime import datetime
from pathlib import Path
from gui.main_window import MainWindow
def setup_logging() -> None:
log_dir = Path("logs")
log_dir.mkdir(exist_ok=True)
log_file = log_dir / f"shapearator_{datetime.now().strftime('%Y%m%d_%H%M%S')}.log"
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
handlers=[
logging.FileHandler(log_file, mode="w", encoding="utf-8"),
logging.StreamHandler(sys.stdout),
],
force=True,
)
logging.info("Logging initialized: %s", log_file)
def handle_exception(exc_type, exc_value, exc_traceback) -> None:
if issubclass(exc_type, KeyboardInterrupt):
sys.__excepthook__(exc_type, exc_value, exc_traceback)
return
logging.error("Uncaught exception", exc_info=(exc_type, exc_value, exc_traceback))
def main() -> None:
try:
setup_logging()
sys.excepthook = handle_exception
root = tk.Tk()
MainWindow(root)
root.mainloop()
except Exception as exc:
logging.error("Fatal error: %s", exc)
traceback.print_exc()
sys.exit(1)
if __name__ == "__main__":
main()