hide/show event no lag hopefully yayay

pull/36039/head
Shane Smiskol 1 week ago
parent 712b1606c6
commit 234b635965
  1. 6
      selfdrive/ui/layouts/settings/settings.py
  2. 28
      system/ui/lib/wifi_manager_v2.py
  3. 6
      system/ui/widgets/__init__.py
  4. 9
      system/ui/widgets/network.py

@ -58,9 +58,9 @@ class SettingsLayout(Widget):
# self.wifi_manager = WifiManagerWrapper()
self.wifi_manager = WifiManager()
self.wifi_manager.set_active(False)
self.wifi_ui = WifiManagerUI(self.wifi_manager)
self._panels = {
PanelType.DEVICE: PanelInfo("Device", DeviceLayout()),
PanelType.NETWORK: PanelInfo("Network", self.wifi_ui),
@ -76,7 +76,7 @@ class SettingsLayout(Widget):
self._close_callback: Callable | None = None
# def __del__(self):
# self.wifi_manager.shutdown()
# self.wifi_manager.stop()
def set_callbacks(self, on_close: Callable):
self._close_callback = on_close
@ -162,7 +162,9 @@ class SettingsLayout(Widget):
def set_current_panel(self, panel_type: PanelType):
if panel_type != self._current_panel:
self._panels[self._current_panel].instance.hide_event()
self._current_panel = panel_type
self._panels[self._current_panel].instance.show_event()
def close_settings(self):
if self._close_callback:

@ -154,6 +154,7 @@ class WifiManager:
while self._running:
if self._active:
print('moritring state ACTivE!!1')
dev_state = int(props_dev.Get(NM_DEVICE_IFACE, "State"))
state_reason = props_dev.Get(NM_DEVICE_IFACE, "StateReason") # (u state, u reason)
reason = int(state_reason[1]) if isinstance(state_reason, (list, tuple)) and len(state_reason) == 2 else 0
@ -198,11 +199,17 @@ class WifiManager:
self._disconnected = disconnected
def _run(self):
i = 0
while self._running:
if self._active:
self._update_networks()
print('we;re acti!!!!!!!!!!!!')
# Scan for networks every 5 seconds
if i % 5 == 0:
self._update_networks()
self._request_scan()
time.sleep(3)
i += 1
time.sleep(1)
def set_active(self, active: bool):
self._active = active
@ -323,6 +330,23 @@ class WifiManager:
# if self._activated is not None:
# self._activated()
def _request_scan(self):
device_path = self._get_wifi_device()
if device_path is None:
cloudlog.warning("No WiFi device found")
return
wifi_iface = dbus.Interface(self._bus.get_object(NM, device_path), NM_WIRELESS_IFACE)
try:
wifi_iface.RequestScan({})
print('Requested scan')
except dbus.exceptions.DBusException as e:
# TODO: copilot is wrong, this never happens
if "org.freedesktop.NetworkManager.Device.Error.AlreadyScanning" in str(e):
print('Already scanning, skipping')
else:
cloudlog.exception("Failed to request scan")
def _update_networks(self):
# TODO: only run this function on scan complete!
print('UPDATING NETWORKS!!!!')

@ -129,3 +129,9 @@ class Widget(abc.ABC):
def _handle_mouse_release(self, mouse_pos: MousePos) -> bool:
"""Optionally handle mouse release events."""
return False
def show_event(self):
"""Optionally handle show event. Parent must manually call this"""
def hide_event(self):
"""Optionally handle hide event. Parent must manually call this"""

@ -82,6 +82,15 @@ class WifiManagerUI(Widget):
networks_updated=self._on_network_updated,
disconnected=self._on_disconnected)
def show_event(self):
print('networking widget shown, stasrting wifisz scaing')
# start/stop scanning when widget is visible
self.wifi_manager.set_active(True)
def hide_event(self):
print('networkign widet hidden, stopping wifisz')
self.wifi_manager.set_active(False)
def _render(self, rect: rl.Rectangle):
with self._lock:
if not self._networks:

Loading…
Cancel
Save