From e3b2e8ed952c5f8fcf6d55501bd5064532293112 Mon Sep 17 00:00:00 2001 From: SnuffSocket <82658601+SnuffSocket@users.noreply.github.com> Date: Mon, 7 Oct 2024 02:00:09 +0300 Subject: [PATCH 1/3] Feat: Lower CPU usage when not in focus by stopping 'n slowing down the GUI loop. --- EyeTrackApp/eyetrackapp.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/EyeTrackApp/eyetrackapp.py b/EyeTrackApp/eyetrackapp.py index 95f3be0..f7eec32 100644 --- a/EyeTrackApp/eyetrackapp.py +++ b/EyeTrackApp/eyetrackapp.py @@ -328,6 +328,14 @@ def main(): os._exit(0) # I do not like this, but for now this fixes app hang on close return + # When focus is lost stop 'n slow down the loop here. + try: + if not window.TKroot.focus_get(): + time.sleep(0.2) + continue + except KeyError: + pass + if values[key_manager.RIGHT_EYE_RADIO_NAME] and config.eye_display_id != EyeId.RIGHT: config.settings.gui_disable_gui = False eyes[0].start() From 3e1a3a05d45a163e08b04c9fb125107094a5ff19 Mon Sep 17 00:00:00 2001 From: SnuffSocket <82658601+SnuffSocket@users.noreply.github.com> Date: Thu, 24 Oct 2024 18:59:25 +0300 Subject: [PATCH 2/3] Fix: Made intended behavior more clear to the user --- EyeTrackApp/eyetrackapp.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/EyeTrackApp/eyetrackapp.py b/EyeTrackApp/eyetrackapp.py index f7eec32..4a2b980 100644 --- a/EyeTrackApp/eyetrackapp.py +++ b/EyeTrackApp/eyetrackapp.py @@ -38,7 +38,6 @@ from settings.algo_settings_widget import AlgoSettingsWidget from osc.osc import OSCManager from osc.OSCMessage import OSCMessage from utils.misc_utils import is_nt, resource_path -import time import cv2 import numpy as np import uuid @@ -180,6 +179,8 @@ def create_window(config, settings, eyes): button_color="#6f4ca1", ), ], + # Keep at bottom! + [sg.Text("- - - Interface Paused - - -", key="-WINFOCUS-", background_color="#292929", text_color="#F0F0F0", justification="center", expand_x=True, visible=False)], ] @@ -296,7 +297,7 @@ def main(): # Event loop while True: - eventg, valuesg = windowg.read(timeout=30) + eventg, valuesg = windowg.read(timeout=33) if eventg == sg.WINDOW_CLOSED: config.settings.gui_disable_gui = False @@ -313,8 +314,11 @@ def main(): # First off, check for any events from the GUI window = create_window(config, settings, eyes) + + tint = 33 + fs = False while True: - event, values = window.read(timeout=30) # this higher timeout saves some cpu usage + event, values = window.read(timeout=tint) # this higher timeout saves some cpu usage # If we're in either mode and someone hits q, quit immediately if event == "Exit" or event == sg.WIN_CLOSED and not config.settings.gui_disable_gui: @@ -328,10 +332,21 @@ def main(): os._exit(0) # I do not like this, but for now this fixes app hang on close return - # When focus is lost stop 'n slow down the loop here. try: - if not window.TKroot.focus_get(): - time.sleep(0.2) + # If window isn't in focus increase timeout and stop loop early + if window.TKroot.focus_get(): + if fs: + fs = False + tint = 33 + window["-WINFOCUS-"].update(visible=False) + window["-WINFOCUS-"].hide_row() + window.refresh() + else: + if not fs: + fs = True + tint = 100 + window["-WINFOCUS-"].update(visible=True) + window["-WINFOCUS-"].unhide_row() continue except KeyError: pass From 0d3128d3972bb869974d1966ad8a09db646a0ade Mon Sep 17 00:00:00 2001 From: Prohurtz <48768484+RedHawk989@users.noreply.github.com> Date: Wed, 27 Nov 2024 13:55:57 -0600 Subject: [PATCH 3/3] minor: move variables for clarity and complete usage --- EyeTrackApp/eyetrackapp.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/EyeTrackApp/eyetrackapp.py b/EyeTrackApp/eyetrackapp.py index 4a2b980..f9a7927 100644 --- a/EyeTrackApp/eyetrackapp.py +++ b/EyeTrackApp/eyetrackapp.py @@ -285,7 +285,8 @@ def main(): osc_manager.start() while True: - + tint = 33 + fs = False if config.settings.gui_disable_gui: layoutg = [ [sg.Text("GUI Disabled!", background_color="#242224")], @@ -297,7 +298,7 @@ def main(): # Event loop while True: - eventg, valuesg = windowg.read(timeout=33) + eventg, valuesg = windowg.read(timeout=tint) if eventg == sg.WINDOW_CLOSED: config.settings.gui_disable_gui = False @@ -315,8 +316,7 @@ def main(): # First off, check for any events from the GUI window = create_window(config, settings, eyes) - tint = 33 - fs = False + while True: event, values = window.read(timeout=tint) # this higher timeout saves some cpu usage