diff --git a/EyeTrackApp/leap.py b/EyeTrackApp/leap.py index 5640e89..2f567c5 100644 --- a/EyeTrackApp/leap.py +++ b/EyeTrackApp/leap.py @@ -41,9 +41,11 @@ from one_euro_filter import OneEuroFilter import psutil, os import sys from utils.misc_utils import resource_path -import platform +from pathlib import Path + frames = 0 +models = Path("Models") def run_model(input_queue, output_queue, session): @@ -70,10 +72,7 @@ class LEAP_C(object): # Config variables self.num_threads = 4 # Number of python threads to use (using ~1 more than needed to achieve wanted fps yields lower cpu usage) self.queue_max_size = 1 # Optimize for best CPU usage, Memory, and Latency. A maxsize is needed to not create a potential memory leak. - if platform.system() == "Darwin": - self.model_path = resource_path("Models/leap123023.onnx") # funny MacOS files issues :P - else: - self.model_path = resource_path("Models\leap123023.onnx") + self.model_path = resource_path(models / 'leap123023.onnx') self.low_priority = ( False # set process priority to low (may cause issues when unfocusing? reported by one, not reproducable) diff --git a/EyeTrackApp/utils/misc_utils.py b/EyeTrackApp/utils/misc_utils.py index dbf70ec..960c45a 100644 --- a/EyeTrackApp/utils/misc_utils.py +++ b/EyeTrackApp/utils/misc_utils.py @@ -2,6 +2,9 @@ import os import typing import sys +from pathlib import Path +from typing import Union + is_nt = True if os.name == "nt" else False def PlaySound(*args, **kwargs): pass @@ -60,12 +63,14 @@ class FastMedian: self.__median = lst_median(all, ordered=False) return self.__median -def resource_path(relative_path): - """ Get absolute path to resource, works for dev and for PyInstaller """ +def resource_path(relative_path: Union[str, Path]) -> str: + """ + 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 + base_path = Path(sys._MEIPASS) except AttributeError: - base_path = os.path.abspath(".") + base_path = Path(".") - return os.path.join(base_path, relative_path) \ No newline at end of file + return str(base_path / relative_path)