expose more state from gui_app

This commit is contained in:
Adeeb Shihadeh
2025-10-30 16:03:28 -07:00
parent c4a0e57046
commit f57617c944

View File

@@ -14,11 +14,11 @@ from enum import StrEnum
from typing import NamedTuple
from importlib.resources import as_file, files
from openpilot.common.swaglog import cloudlog
from openpilot.system.hardware import HARDWARE, PC, TICI
from openpilot.system.hardware import HARDWARE, PC
from openpilot.system.ui.lib.multilang import multilang
from openpilot.common.realtime import Ratekeeper
_DEFAULT_FPS = int(os.getenv("FPS", 20 if TICI else 60))
_DEFAULT_FPS = int(os.getenv("FPS", {'tizi': 20}.get(HARDWARE.get_device_type(), 60)))
FPS_LOG_INTERVAL = 5 # Seconds between logging FPS drops
FPS_DROP_THRESHOLD = 0.9 # FPS drop threshold for triggering a warning
FPS_CRITICAL_THRESHOLD = 0.5 # Critical threshold for triggering strict actions
@@ -149,12 +149,15 @@ class GuiApplication:
self._textures: dict[str, rl.Texture] = {}
self._target_fps: int = _DEFAULT_FPS
self._last_fps_log_time: float = time.monotonic()
self._frame = 0
self._window_close_requested = False
self._trace_log_callback = None
self._modal_overlay = ModalOverlay()
self._modal_overlay_shown = False
self._mouse = MouseState(self._scale)
self._mouse_events: list[MouseEvent] = []
self._last_mouse_event: MouseEvent = MouseEvent(MousePos(0, 0), 0, False, False, False, 0.0)
self._should_render = True
@@ -163,6 +166,10 @@ class GuiApplication:
self._show_touches = SHOW_TOUCHES
self._show_fps = SHOW_FPS
@property
def frame(self):
return self._frame
def set_show_touches(self, show: bool):
self._show_touches = show
@@ -325,6 +332,10 @@ class GuiApplication:
def mouse_events(self) -> list[MouseEvent]:
return self._mouse_events
@property
def last_mouse_event(self) -> MouseEvent:
return self._last_mouse_event
def render(self):
try:
while not (self._window_close_requested or rl.window_should_close()):
@@ -334,6 +345,8 @@ class GuiApplication:
# Store all mouse events for the current frame
self._mouse_events = self._mouse.get_events()
if len(self._mouse_events) > 0:
self._last_mouse_event = self._mouse_events[-1]
# Skip rendering when screen is off
if not self._should_render:
@@ -357,6 +370,11 @@ class GuiApplication:
else:
raise Exception
# Send show event to Widget
if not self._modal_overlay_shown and hasattr(self._modal_overlay.overlay, 'show_event'):
self._modal_overlay.overlay.show_event()
self._modal_overlay_shown = True
if result >= 0:
# Clear the overlay and execute the callback
original_modal = self._modal_overlay
@@ -365,6 +383,7 @@ class GuiApplication:
original_modal.callback(result)
yield False
else:
self._modal_overlay_shown = False
yield True
if self._render_texture:
@@ -394,6 +413,7 @@ class GuiApplication:
rl.end_drawing()
self._monitor_fps()
self._frame += 1
except KeyboardInterrupt:
pass