Files
StarPilot/openpilot/starpilot/ui/network_panel.py
T
firestar5683 a82935f326 User interfaces and Android Auto
Integrate onroad views, configurable widgets, local settings, steering-profile contracts, Bluetooth and Android Auto with their device and runtime services.

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
Co-authored-by: Daniel Koepping <elkoled@gmail.com>
Co-authored-by: Danny <dannyirwin31@yahoo.com>
Co-authored-by: DimitriChrysafis <Dimitri.chrysafis@gmail.com>
Co-authored-by: Dom <168790843+firestar5683@users.noreply.github.com>
Co-authored-by: Harald Schäfer <harald.the.engineer@gmail.com>
Co-authored-by: Prabhaav Pillai <prabhaav@msu.edu>
Co-authored-by: Shane Smiskol <shane@smiskol.com>
Co-authored-by: dirwin31 <83434411+dirwin31@users.noreply.github.com>
Co-authored-by: firestarsdog <229254897+firestarsdog@users.noreply.github.com>
Co-authored-by: stef <19478336+stefpi@users.noreply.github.com>
Co-authored-by: whoisdomi <dcantu83@gmail.com>

Co-authored-by: Intelli <contact@intelli.software>
Co-authored-by: pharmacomaniac <blittle65@gmail.com>

Co-authored-by: prabhaavp <prabhaav@msu.edu>
2026-10-14 20:02:39 -05:00

71 lines
1.7 KiB
Python

"""Lifecycle boundary for the existing large native NetworkUI instance."""
from collections.abc import Callable
import pyray as rl
from openpilot.system.ui.widgets.network import NetworkUI
from openpilot.system.ui.widgets import Widget
class NetworkPanelBridge:
def __init__(self, panel: NetworkUI, authority: Callable[[], bool]):
self.panel = panel
self.presentation: Widget = panel
self.authority = authority
self.active = False
self.generation = 0
self.panel.set_action_guard(lambda: False)
def _allowed(self, generation: int) -> bool:
if not self.active or generation != self.generation:
return False
try:
return bool(self.authority())
except Exception:
return False
def enter(self) -> bool:
if self.active:
return self._allowed(self.generation)
try:
allowed = bool(self.authority())
except Exception:
allowed = False
if not allowed:
return False
self.generation += 1
self.active = True
token = self.generation
self.panel.set_action_guard(lambda: self._allowed(token))
try:
self.presentation.show_event()
except Exception:
self.leave()
return False
if not self._allowed(token):
self.leave()
return False
return True
def leave(self) -> None:
if not self.active:
return
self.active = False
self.generation += 1
self.presentation.hide_event()
def render(self, rect: rl.Rectangle) -> bool:
if not self.active or not self._allowed(self.generation):
self.leave()
return False
try:
self.presentation.render(rect)
except Exception:
self.leave()
return False
if not self._allowed(self.generation):
self.leave()
return False
return True