|
4 | 4 | from threading import Timer |
5 | 5 | from dash import Dash, html |
6 | 6 | import dash_bootstrap_components as dbc |
| 7 | +from pathlib import Path |
7 | 8 |
|
8 | 9 |
|
9 | 10 | import os, sys, io, contextlib |
|
34 | 35 | register_overlay_callbacks, |
35 | 36 | ) |
36 | 37 |
|
| 38 | +def get_path(rel: str) -> str: |
| 39 | + """ |
| 40 | + Resolve a path relative to the runtime root. |
| 41 | +
|
| 42 | + Frozen (PyInstaller onedir): |
| 43 | + <dist>/HWDBTools/_internal/<rel> |
| 44 | +
|
| 45 | + Non-frozen (repo checkout): |
| 46 | + <repo_root>/<rel> |
| 47 | + """ |
| 48 | + rel = rel.lstrip("/").replace("\\", "/") |
| 49 | + |
| 50 | + if getattr(sys, "frozen", False): |
| 51 | + # In onedir, the EXE lives in <dist>/HWDBTools/ |
| 52 | + # and _internal is a sibling folder. |
| 53 | + runtime_root = Path(sys.executable).resolve().parent / "_internal" |
| 54 | + return str(runtime_root / rel) |
| 55 | + |
| 56 | + # Non-frozen: infer repo root from this file location: |
| 57 | + # lib/Sisyphus/Gui/Dashboard/__main__.py -> repo root is 5 parents up |
| 58 | + # (__main__.py -> Dashboard -> Gui -> Sisyphus -> lib -> PROJECT_ROOT) |
| 59 | + runtime_root = Path(__file__).resolve().parents[4] |
| 60 | + return str(runtime_root / rel) |
| 61 | + |
37 | 62 | #------------- create the website and interface ------- |
38 | | -app = Dash( |
39 | | - __name__, |
| 63 | +dash_kwargs = dict( |
40 | 64 | external_stylesheets=[dbc.themes.BOOTSTRAP], |
41 | | - suppress_callback_exceptions=True |
| 65 | + suppress_callback_exceptions=True, |
| 66 | +) |
| 67 | + |
| 68 | +if getattr(sys, "frozen", False): |
| 69 | + # Frozen: our spec places Dashboard assets into _internal/assets/ |
| 70 | + dash_kwargs.update( |
| 71 | + assets_folder=get_path("assets"), |
| 72 | + assets_url_path="/assets", # optional; Dash default is already "/assets" |
42 | 73 | ) |
| 74 | + |
| 75 | +app = Dash(__name__, **dash_kwargs) |
| 76 | + |
| 77 | +#------------- create the website and interface ------- |
| 78 | +#app = Dash( |
| 79 | +# __name__, |
| 80 | +# external_stylesheets=[dbc.themes.BOOTSTRAP], |
| 81 | +# suppress_callback_exceptions=True, |
| 82 | +# assets_folder=get_path("assets"), |
| 83 | +# assets_url_path="/assets", |
| 84 | +# ) |
| 85 | + |
43 | 86 | app.title = "HWDB Dashboard" |
44 | 87 | app.layout = layout |
45 | 88 | # Force Dash to validate the layout before callback registration |
|
0 commit comments