diff --git a/selfdrive/ui/mici/layouts/settings/network/wifi_ui.py b/selfdrive/ui/mici/layouts/settings/network/wifi_ui.py index b974b502a..1c5bd5887 100644 --- a/selfdrive/ui/mici/layouts/settings/network/wifi_ui.py +++ b/selfdrive/ui/mici/layouts/settings/network/wifi_ui.py @@ -363,7 +363,7 @@ class WifiUIMici(BigMultiOptionDialog): # Clear scroller items and update from latest scan results super().show_event() self._wifi_manager.set_active(True) - self._scroller._items.clear() + self._scroller.items.clear() self._update_buttons() def hide_event(self): @@ -379,22 +379,22 @@ class WifiUIMici(BigMultiOptionDialog): # Only add new buttons to the end. Update existing buttons without re-sorting so user can freely scroll around for network in self._networks.values(): - network_button_idx = next((i for i, btn in enumerate(self._scroller._items) if btn.option == network.ssid), None) + network_button_idx = next((i for i, btn in enumerate(self._scroller.items) if btn.option == network.ssid), None) if network_button_idx is not None: # Update network on existing button - self._scroller._items[network_button_idx].set_current_network(network) + self._scroller.items[network_button_idx].set_current_network(network) else: network_button = WifiItem(network, lambda: self._wifi_manager.wifi_state) self._scroller.add_widget(network_button) # Move connecting/connected network to the start - connected_btn_idx = next((i for i, btn in enumerate(self._scroller._items) if self._wifi_manager.wifi_state.ssid == btn._network.ssid), None) + connected_btn_idx = next((i for i, btn in enumerate(self._scroller.items) if self._wifi_manager.wifi_state.ssid == btn._network.ssid), None) if connected_btn_idx is not None and connected_btn_idx > 0: - self._scroller._items.insert(0, self._scroller._items.pop(connected_btn_idx)) + self._scroller.items.insert(0, self._scroller.items.pop(connected_btn_idx)) self._scroller._layout() # fixes selected style single frame stutter # Disable networks no longer present - for btn in self._scroller._items: + for btn in self._scroller.items: if btn.option not in self._networks: btn.set_enabled(False) btn.set_network_missing(True) diff --git a/selfdrive/ui/mici/widgets/dialog.py b/selfdrive/ui/mici/widgets/dialog.py index c695949e4..32624bbdd 100644 --- a/selfdrive/ui/mici/widgets/dialog.py +++ b/selfdrive/ui/mici/widgets/dialog.py @@ -313,7 +313,7 @@ class BigMultiOptionDialog(BigDialogBase): def _on_option_selected(self, option: str): y_pos = 0.0 - for btn in self._scroller._items: + for btn in self._scroller.items: btn = cast(BigDialogOptionButton, btn) if btn.option == option: rect_center_y = self._rect.y + self._rect.height / 2 @@ -350,7 +350,7 @@ class BigMultiOptionDialog(BigDialogBase): return # select current option - for btn in self._scroller._items: + for btn in self._scroller.items: btn = cast(BigDialogOptionButton, btn) if btn.option == self._selected_option: self._on_option_selected(btn.option) @@ -362,13 +362,13 @@ class BigMultiOptionDialog(BigDialogBase): # get selection by whichever button is closest to center center_y = self._rect.y + self._rect.height / 2 closest_btn = (None, float('inf')) - for btn in self._scroller._items: + for btn in self._scroller.items: dist_y = abs((btn.rect.y + btn.rect.height / 2) - center_y) if dist_y < closest_btn[1]: closest_btn = (btn, dist_y) if closest_btn[0]: - for btn in self._scroller._items: + for btn in self._scroller.items: btn.set_selected(btn.option == closest_btn[0].option) self._selected_option = closest_btn[0].option diff --git a/system/ui/widgets/scroller.py b/system/ui/widgets/scroller.py index e50a48bbc..8de86fca9 100644 --- a/system/ui/widgets/scroller.py +++ b/system/ui/widgets/scroller.py @@ -117,6 +117,10 @@ class Scroller(Widget): def is_auto_scrolling(self) -> bool: return self._scrolling_to is not None + @property + def items(self) -> list[Widget]: + return self._items + def add_widget(self, item: Widget) -> None: self._items.append(item) item.set_touch_valid_callback(lambda: self.scroll_panel.is_touch_valid() and self.enabled)