diff --git a/.gitignore b/.gitignore index f76b227..e4c049e 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ dist/* venv *.pyc dist/* -*.csv \ No newline at end of file +*.csv +data/* \ No newline at end of file diff --git a/apps/appUtils/ActivationZone.py b/apps/appUtils/ActivationZone.py index 96b9066..b2107d2 100644 --- a/apps/appUtils/ActivationZone.py +++ b/apps/appUtils/ActivationZone.py @@ -445,6 +445,10 @@ def show(self): print(f"showing: {self.rois[key]}") self.rois[key].show() + def close_event(self): + if self.t != None and self.root != None: + self.stop_painting() + def rectangle_class(): app = QApplication(sys.argv) RM = RoIMan() diff --git a/apps/appUtils/data_saver.py b/apps/appUtils/data_saver.py index 41e5829..d37ef1b 100644 --- a/apps/appUtils/data_saver.py +++ b/apps/appUtils/data_saver.py @@ -31,9 +31,12 @@ def __send_screenshot(self, filename, screenshot): def __save_screenshots(self): while self.screenshots_enable: if self.ipc.not_empty: - print("saving screenshots") - filename, screenshot = self.ipc.get() - screenshot.save(filename) + try: + filename, screenshot = self.ipc.get(True,0.2) + screenshot.save(filename) + except: + print("no item available") + print("exiting saving") def add_frame(self,directory,gevent,rois_to_save): timestamp = datetime.datetime.now().timestamp() diff --git a/apps/app_win.py b/apps/app_win.py index d558edf..10b2ce5 100644 --- a/apps/app_win.py +++ b/apps/app_win.py @@ -6,6 +6,7 @@ import pyautogui from screeninfo import get_monitors from PySide2.QtWidgets import QApplication +from PySide2.QtCore import QObject, QThread dir_path = os.path.dirname(os.path.realpath(__file__)) sys.path.append(f'{dir_path}\\..') @@ -14,7 +15,6 @@ from eyeGestures.eyegestures import EyeGestures from appUtils.EyeGestureWidget import EyeGestureWidget from appUtils.CalibrationWidget import CalibrationWidget -from lab.pupillab import Worker from appUtils.dot_windows import WindowsCursor from appUtils.data_saver import DataManager @@ -24,6 +24,35 @@ class CalibrationTypes: TOP = "top" BOTTOM = "bottom" + +class Worker(QObject): + + def __init__(self,thread): + super().__init__() + + self.__displayPool = dict() + self.__thread = thread + + self.__run = True + + self.thread = QThread() + self.moveToThread(self.thread) + + self.thread.started.connect(self.run) + self.thread.start() + + def on_quit(self): + if self.__run == True: + self.__run = False + self.thread.quit() + self.thread.wait() + print("worker quitted") + + def run(self): + while self.__run: + self.__thread() + print("exiting worker") + class Calibrator: def __init__(self,width,height,start_x, start_y, show, disappear): @@ -168,7 +197,7 @@ def clear_up(self): class Lab: - def __init__(self): + def __init__(self,main_quit): self.step = 10 self.monitor = list(filter(lambda monitor: monitor.is_primary == True ,get_monitors()))[0] @@ -192,10 +221,11 @@ def __init__(self): self.cap = VideoCapture(0) - self.eyegesture_widget.add_close_event(self.calibration_widget.close_event) - self.eyegesture_widget.add_close_event(self.on_quit) self.eyegesture_widget.add_close_event(self.cap.close) self.eyegesture_widget.add_close_event(self.dot_widget.close_event) + self.eyegesture_widget.add_close_event(self.calibration_widget.close_event) + self.eyegesture_widget.add_close_event(self.on_quit) + self.eyegesture_widget.add_close_event(main_quit) self.__run = False self.power_off = False @@ -219,7 +249,8 @@ def start(self): def stop(self): self.dataSavingMan.disable_screenshots() self.__run = False - self.calibrator.clear_up() + if self.calibrator: + self.calibrator.clear_up() pass def cursor_visible(self): @@ -247,8 +278,11 @@ def update_radius(self,radius): self.radius = radius def on_quit(self): + self.stop() self.__run = False self.power_off = True + self.worker.on_quit() + print("main on quit finished") def save_data(self,event,rois_to_save): filename = f"{self.eyegesture_widget.get_text()}" @@ -301,9 +335,9 @@ def run(self): self.__display_eye(frame) except Exception as e: print(f"crashed in debug {e}") - + print("Exiting main loop.") if __name__ == '__main__': app = QApplication(sys.argv) - lab = Lab() + lab = Lab(app.quit) sys.exit(app.exec_()) \ No newline at end of file diff --git a/apps/app_win.spec b/apps/app_win.spec index 3a7af08..1773548 100644 --- a/apps/app_win.spec +++ b/apps/app_win.spec @@ -1,12 +1,13 @@ # -*- mode: python ; coding: utf-8 -*- -# -*- mode: python ; coding: utf-8 -*- - a = Analysis( ['app_win.py'], pathex=[], binaries=[], - datas=[('./venv/Lib/site-packages/mediapipe/modules', 'mediapipe/modules'),], + datas=[ + ('../venv/Lib/site-packages/mediapipe/modules', 'mediapipe/modules'), + ('../lab', '.'), + ], hiddenimports=[], hookspath=[], hooksconfig={}, diff --git a/pybuild.bat b/pybuild.bat index e422753..a46190f 100644 --- a/pybuild.bat +++ b/pybuild.bat @@ -1,3 +1,3 @@ -./venv/Scripts/activate; -pyinstaller app_win.spec; -deactivate; +@REM .\venv\Scripts\activate +pyinstaller ./apps/app_win.spec +@REM deactivate; diff --git a/pyproject.toml b/pyproject.toml index 3df50b4..7595ce6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,7 +21,7 @@ exclude = [ [project] name = "eyeGestures" -version = "1.3.3" +version = "1.3.4" authors = [ { name="Piotr Walas", email="piotr.walas@eyegestures.com" }, ] diff --git a/requirements.txt b/requirements.txt index f18ee2b..7736b4a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,5 +14,5 @@ scikit_learn==1.3.2 scipy==1.12.0 screeninfo==0.8.1 setuptools==69.0.2 -skimage==0.0 +scikit-image==0.23.1 xlwt==1.3.0