Skip to content

Commit e229972

Browse files
Update utils.py
Fix resource_path to resolve assets relative to Tool/ when running from source
1 parent 0e5785b commit e229972

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

Tool/utils.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@
1717
# --- Helper Functions ---
1818
def resource_path(relative_path):
1919
"""Get absolute path to resource, works for dev and for PyInstaller."""
20-
try:
20+
# PyInstaller runtime
21+
if hasattr(sys, "_MEIPASS"):
2122
base_path = sys._MEIPASS
22-
except Exception:
23-
base_path = os.path.abspath(".")
23+
else:
24+
# Source run: base is Tool/ (where utils.py lives)
25+
base_path = os.path.dirname(os.path.abspath(__file__))
26+
2427
return os.path.join(base_path, relative_path)
2528

29+
2630
def get_square_remove_btn_style():
2731
"""Returns CSS string for the small 'x' button."""
2832
return """
@@ -65,4 +69,4 @@ def natural_sort_key(s):
6569
# Safety check for None or non-string
6670
if not isinstance(s, str):
6771
return []
68-
return [int(text) if text.isdigit() else text.lower() for text in re.split('([0-9]+)', s)]
72+
return [int(text) if text.isdigit() else text.lower() for text in re.split('([0-9]+)', s)]

0 commit comments

Comments
 (0)