diff --git a/.gitignore b/.gitignore index 099e558..7d3c81b 100644 --- a/.gitignore +++ b/.gitignore @@ -141,3 +141,4 @@ cython_debug/ .vscode/ working/ /src/disco_hue/desktop/ui/main_window.py +src/disco_hue/desktop/ui/generated/ diff --git a/src/disco_hue/desktop/main.py b/src/disco_hue/desktop/main.py index 540cda1..14d1c47 100644 --- a/src/disco_hue/desktop/main.py +++ b/src/disco_hue/desktop/main.py @@ -4,12 +4,14 @@ from PyQt6.QtWidgets import QMainWindow, QMessageBox, QFileDialog from desktop import BridgeNotRegisteredException, DiscoverBridgesThread from services import DiscoBall +from .utils import resource_path class App(QMainWindow): def __init__(self, parent=None): super().__init__(parent) - uic.loadUi('./desktop/ui/main.ui', self) + + uic.loadUi(resource_path('desktop/ui/main.ui'), self) self._settings = QSettings('disco_hue') self._manager = None self._selected_light = None diff --git a/src/disco_hue/desktop/utils.py b/src/disco_hue/desktop/utils.py new file mode 100644 index 0000000..4e93e64 --- /dev/null +++ b/src/disco_hue/desktop/utils.py @@ -0,0 +1,13 @@ +import os +import sys + + +def resource_path(relative_path): + """ Get absolute path to resource, works for dev and for PyInstaller """ + try: + # PyInstaller creates a temp folder and stores path in _MEIPASS + base_path = sys._MEIPASS + except Exception: + base_path = os.path.abspath(".") + + return os.path.join(base_path, relative_path)