-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPartsPack.py
More file actions
92 lines (71 loc) · 2.48 KB
/
Copy pathPartsPack.py
File metadata and controls
92 lines (71 loc) · 2.48 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python3
# Parts Packing Generator - Copyright (C) 2026 InPoint Automation
# Licensed under the GNU General Public License v3 or later; see LICENSE.
#
# Launch the GUI. Deps: pip install -r requirements.txt
import io
import logging
import os
import sys
# Wayland fix
if sys.platform.startswith("linux"):
os.environ.setdefault("QT_QPA_PLATFORM", "xcb")
def _frozen():
# Nuitka sets __compiled__, not sys.frozen
return getattr(sys, "frozen", False) or "__compiled__" in globals()
def _app_dir():
return os.path.dirname(sys.executable if _frozen()
else os.path.abspath(__file__))
LOG_PATH = os.path.join(_app_dir(), "PartsPack.log")
def _setup_logging():
try:
logf = open(LOG_PATH, "w", encoding="utf-8", buffering=1)
except OSError:
return
logging.basicConfig(
stream=logf, level=logging.INFO,
format="%(asctime)s %(levelname)s %(name)s: %(message)s")
if _frozen():
sys.stdout = logf
sys.stderr = logf
for _fd in (1, 2):
try:
os.dup2(logf.fileno(), _fd)
except (OSError, ValueError, io.UnsupportedOperation):
pass
def _hook(exc_type, exc, tb):
logging.error("Uncaught exception", exc_info=(exc_type, exc, tb))
sys.excepthook = _hook
logging.info("=== PartsPack start (frozen=%s) ===", _frozen())
def _report_fatal(title, message):
logging.error("%s\n%s", title, message)
if sys.platform.startswith("win"):
try:
import ctypes
ctypes.windll.user32.MessageBoxW(0, message, title, 0x10)
except Exception:
pass
_setup_logging()
_MISSING = []
for _mod, _pip in (("PySide6", "PySide6"), ("pydantic", "pydantic"),
("build123d", "build123d"), ("shapely", "shapely")):
try:
__import__(_mod)
except ImportError:
import traceback
_MISSING.append((_pip, traceback.format_exc()))
if _MISSING:
_detail = "\n\n".join("=== %s ===\n%s" % (name, tb)
for name, tb in _MISSING)
_report_fatal("Parts Packing Generator dependency import failed",
"These imports failed:\n\n" + _detail)
sys.exit(1)
if __name__ == "__main__":
try:
from partspack.gui.app import main
main()
except Exception:
import traceback
_report_fatal("Parts Packing Generator startup error",
traceback.format_exc())
sys.exit(1)