mirror of
https://github.com/EyeTrackVR/EyeTrackVR.git
synced 2025-11-04 14:39:42 +08:00
Merge pull request #119 from SnuffSocket/focus-branch
Feat: Lower CPU usage when not in focus
This commit is contained in:
commit
9a64b1e38a
@ -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)],
|
||||
]
|
||||
|
||||
|
||||
@ -284,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")],
|
||||
@ -296,7 +298,7 @@ def main():
|
||||
|
||||
# Event loop
|
||||
while True:
|
||||
eventg, valuesg = windowg.read(timeout=30)
|
||||
eventg, valuesg = windowg.read(timeout=tint)
|
||||
|
||||
if eventg == sg.WINDOW_CLOSED:
|
||||
config.settings.gui_disable_gui = False
|
||||
@ -313,8 +315,10 @@ def main():
|
||||
|
||||
# First off, check for any events from the GUI
|
||||
window = create_window(config, settings, eyes)
|
||||
|
||||
|
||||
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 in ("Exit", sg.WIN_CLOSED) and not config.settings.gui_disable_gui:
|
||||
@ -327,6 +331,25 @@ def main():
|
||||
os._exit(0) # I do not like this, but for now this fixes app hang on close
|
||||
return
|
||||
|
||||
try:
|
||||
# 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
|
||||
|
||||
if values[key_manager.RIGHT_EYE_RADIO_NAME] and config.eye_display_id != EyeId.RIGHT:
|
||||
config.settings.gui_disable_gui = False
|
||||
eyes[0].start()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user