22 lines
654 B
Python
22 lines
654 B
Python
from os import path
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
def resource_path(relative_path: str) -> Path:
|
|
"""
|
|
Get absolute path to resource, works for dev and for PyInstaller bundle.
|
|
|
|
PyInstaller stores bundled files in _MEIPASS folder.
|
|
"""
|
|
try:
|
|
base_path = Path(sys._MEIPASS) # PyInstaller temp folder
|
|
except AttributeError:
|
|
base_path = Path(__file__).parent.parent # Dev environment: source/ folder
|
|
|
|
return path.join(base_path, relative_path)
|
|
|
|
def get_data_dir() -> Path:
|
|
return resource_path("data")
|
|
|
|
def get_asset_path(asset: str) -> Path:
|
|
return path.join(get_data_dir(), "assets", f"{asset}.png") |