From 9e8aa1d5e88bdc7e4cbf67a99fefaacbf0ecaa00 Mon Sep 17 00:00:00 2001 From: deanlee Date: Sat, 8 Mar 2025 15:56:23 +0800 Subject: [PATCH] fix ui --- system/ui/lib/keyboard.py | 4 ++-- system/ui/lib/wifi_manager.py | 21 +++++++++++++-------- system/ui/network.py | 5 +++-- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/system/ui/lib/keyboard.py b/system/ui/lib/keyboard.py index 81e0d95754..4d1ad1b2cd 100644 --- a/system/ui/lib/keyboard.py +++ b/system/ui/lib/keyboard.py @@ -55,8 +55,8 @@ class Keyboard: self._input_text = "" def render(self, rect, title, sub_title): - gui_label((rect.x, rect.y, rect.width, 95), title, 90) - gui_label((rect.x, rect.y + 95, rect.width, 60), sub_title, 55, rl.GRAY) + gui_label(rl.Rectangle(rect.x, rect.y, rect.width, 95), title, 90) + gui_label(rl.Rectangle(rect.x, rect.y + 95, rect.width, 60), sub_title, 55, rl.GRAY) if gui_button(rl.Rectangle(rect.x + rect.width - 300, rect.y, 300, 100), "Cancel"): return -1 diff --git a/system/ui/lib/wifi_manager.py b/system/ui/lib/wifi_manager.py index f7d0e363da..17be8522a1 100644 --- a/system/ui/lib/wifi_manager.py +++ b/system/ui/lib/wifi_manager.py @@ -57,9 +57,6 @@ class WifiManager: self.scan_task: asyncio.Task | None = None self.running: bool = True - def is_saved(self, ssid: str) -> bool: - return ssid in self.saved_connections - async def connect(self): """Connect to the DBus system bus.""" try: @@ -110,7 +107,6 @@ class WifiManager: try: nm_iface = await self._get_interface(NM, path, NM_CONNECTION_IFACE) await nm_iface.call_delete() - self.saved_connections.pop(ssid) return True except DBusError as e: cloudlog.error(f"Failed to delete connection for SSID: {ssid}. Error: {e}") @@ -122,7 +118,7 @@ class WifiManager: async def activate_connection(self, ssid: str) -> None: connection_path = self.saved_connections.get(ssid) if connection_path: - cloudlog.info('activate connection:', connection_path) + print('activate connection:', connection_path) introspection = await self.bus.introspect(NM, NM_PATH) proxy = self.bus.get_proxy_object(NM, NM_PATH, introspection) interface = proxy.get_interface(NM_IFACE) @@ -132,7 +128,7 @@ class WifiManager: async def connect_to_network(self, ssid: str, password: str = None, is_hidden: bool = False): """Connect to a selected WiFi network.""" try: - settings_iface = await self._get_interface(NM, NM_SETTINGS_PATH, NM_SETTINGS_IFACE) + # settings_iface = await self._get_interface(NM, NM_SETTINGS_PATH, NM_SETTINGS_IFACE) connection = { 'connection': { 'type': Variant('s', '802-11-wireless'), @@ -159,7 +155,14 @@ class WifiManager: 'psk': Variant('s', password), } - await settings_iface.call_add_connection(connection) + # nm_iface = self._get_interface(NM, NM_PATH, NM_IFACE) + # await nm_iface.call_add_and_activate_connection(connection, self.device_path, '/') + # await settings_iface.call_add_connection(connection) + # introspection = await self.bus.introspect(NM, NM_PATH) + # nm_proxy = self.bus.get_proxy_object(NM, NM_PATH, introspection) + nm_iface = await self._get_interface(NM, NM_PATH, NM_IFACE) + result = await nm_iface.call_add_and_activate_connection(connection, self.device_path, "/") + print(result) for network in self.networks: network.is_connected = True if network.ssid == ssid else False @@ -167,6 +170,9 @@ class WifiManager: except DBusError as e: cloudlog.error(f"Error connecting to network: {e}") + def is_saved(self, ssid: str) -> bool: + return ssid in self.saved_connections + async def _find_wifi_device(self) -> bool: nm_iface = await self._get_interface(NM, NM_PATH, NM_IFACE) devices = await nm_iface.get_devices() @@ -295,7 +301,6 @@ class WifiManager: continue bssid = properties.get('HwAddress', Variant('s', '')).value - print(bssid) flags = properties['Flags'].value wpa_flags = properties['WpaFlags'].value rsn_flags = properties['RsnFlags'].value diff --git a/system/ui/network.py b/system/ui/network.py index cdb6d71fdd..bbbb09a333 100644 --- a/system/ui/network.py +++ b/system/ui/network.py @@ -4,6 +4,7 @@ from enum import IntEnum from dbus_next.constants import MessageType from openpilot.system.ui.lib.wifi_manager import WifiManager, NetworkInfo from openpilot.system.ui.lib.application import gui_app +from openpilot.system.ui.lib.button import gui_button from openpilot.system.ui.lib.label import gui_label from openpilot.system.ui.lib.scroll_panel import GuiScrollPanel from openpilot.system.ui.lib.keyboard import Keyboard @@ -77,7 +78,7 @@ class WifiManagerUI: def render_network_item(self, rect, network: NetworkInfo, clicked: bool): label_rect = rl.Rectangle(rect.x, rect.y, rect.width - self.btn_width * 2, self.item_height) state_rect = rl.Rectangle( - rect.x + rect.width - self.btn_width * 2 - 30, rect.y, self.btn_width, self.item_height + rect.x + rect.width - self.btn_width * 2 - 150, rect.y, 300, self.item_height ) gui_label(label_rect, network.ssid, 55) @@ -99,7 +100,7 @@ class WifiManagerUI: self.btn_width, 80, ) - if rl.gui_button(forget_btn_rect, "Forget") and self.current_action == ActionState.NONE: + if gui_button(forget_btn_rect, "Forget") and self.current_action == ActionState.NONE: self._selected_network = network asyncio.create_task(self.forgot_network())