BigUI WIP: Long + Clean...er..ish

This commit is contained in:
firestarsdog
2026-05-02 01:45:28 -04:00
parent 873275374d
commit d98d1c3432
4 changed files with 1288 additions and 992 deletions
@@ -30,14 +30,13 @@ from openpilot.system.ui.widgets import DialogResult, Widget
from openpilot.system.ui.widgets.confirm_dialog import ConfirmDialog, alert_dialog
from openpilot.system.ui.widgets.label import gui_label
from openpilot.system.ui.widgets.option_dialog import MultiOptionDialog
from openpilot.selfdrive.ui.layouts.settings.starpilot.panel import StarPilotPanel
from openpilot.selfdrive.ui.layouts.settings.starpilot.panel import _SettingsPage
from openpilot.selfdrive.ui.layouts.settings.starpilot.aethergrid import (
AETHER_LIST_METRICS,
AetherButton,
AetherChip,
AetherListColors,
AetherScrollbar,
AetherSliderDialog,
DEFAULT_PANEL_STYLE,
_point_hits,
draw_action_rail,
@@ -616,7 +615,7 @@ class DrivingModelManagerView(Widget):
return alpha, offset_y, scale
class StarPilotDrivingModelLayout(StarPilotPanel):
class StarPilotDrivingModelLayout(_SettingsPage):
def __init__(self):
super().__init__()
@@ -647,17 +646,12 @@ class StarPilotDrivingModelLayout(StarPilotPanel):
def _render(self, rect: rl.Rectangle):
self._update_state()
self._manager_view.render(rect)
super()._render(rect)
def show_event(self):
super().show_event()
self._fetch_manifest_async()
self._update_model_metadata()
self._manager_view.show_event()
def hide_event(self):
super().hide_event()
self._manager_view.hide_event()
def _fetch_manifest_async(self):
if self._manifest_fetch_thread is not None and self._manifest_fetch_thread.is_alive():
@@ -1156,22 +1150,10 @@ class StarPilotDrivingModelLayout(StarPilotPanel):
self._update_model_metadata()
def _on_recovery_power_clicked(self):
def on_close(res, val):
if res == DialogResult.CONFIRM:
self._params.put_float("RecoveryPower", float(val))
gui_app.push_widget(
AetherSliderDialog(tr("Recovery Power"), 0.5, 2.0, 0.1, self._params.get_float("RecoveryPower"), on_close, unit="x", color="#597497")
)
self._show_slider("RecoveryPower", 0.5, 2.0, step=0.1, unit="x", value_type="float", title="Recovery Power")
def _on_stop_distance_clicked(self):
def on_close(res, val):
if res == DialogResult.CONFIRM:
self._params.put_float("StopDistance", float(val))
gui_app.push_widget(
AetherSliderDialog(tr("Stop Distance"), 4.0, 10.0, 0.1, self._params.get_float("StopDistance"), on_close, unit="m", color="#597497")
)
self._show_slider("StopDistance", 4.0, 10.0, step=0.1, unit="m", value_type="float", title="Stop Distance")
def _on_blacklist_clicked(self):
blacklisted = [m.strip() for m in (self._params.get("BlacklistedModels", encoding="utf-8") or "").split(",") if m.strip()]
File diff suppressed because it is too large Load Diff
@@ -7,8 +7,10 @@ import pyray as rl
from openpilot.common.params import Params
from openpilot.system.ui.lib.multilang import tr
from openpilot.system.ui.widgets import Widget
from openpilot.selfdrive.ui.layouts.settings.starpilot.aethergrid import TileGrid, HubTile, ToggleTile, ValueTile, SliderTile, SPACING
from openpilot.system.ui.lib.application import gui_app
from openpilot.system.ui.widgets import DialogResult, Widget
from openpilot.system.ui.widgets.option_dialog import MultiOptionDialog
from openpilot.selfdrive.ui.layouts.settings.starpilot.aethergrid import TileGrid, HubTile, ToggleTile, ValueTile, SliderTile, SPACING, AetherSliderDialog
from openpilot.selfdrive.ui.layouts.settings.starpilot.sectioned_panel import SectionedTileLayout, TileSection
@@ -288,3 +290,94 @@ def create_master_toggle_panel(toggle_specs: list[dict], sub_panels: dict[str, W
panel.CATEGORIES = categories + list(extra_categories or [])
panel._rebuild_grid()
return panel
# ═══════════════════════════════════════════════════════════════
# _SettingsPage — shared base for AetherSettingsView-backed panels
# ═══════════════════════════════════════════════════════════════
class _SettingsPage(StarPilotPanel):
"""Base for settings pages backed by an AetherSettingsView-like manager.
Provides default ``_render`` / ``show_event`` / ``hide_event`` that
delegate to ``_manager_view`` with automatic sub-panel routing, plus
shared slider and selector dialog helpers.
"""
SLIDER_COLOR = "#597497"
def __init__(self):
super().__init__()
self._manager_view: Widget | None = None
def _wire_sub_panels(self):
"""Wire navigation callbacks on all child sub-panels."""
for child in self._sub_panels.values():
if hasattr(child, "set_navigate_callback"):
child.set_navigate_callback(self._navigate_to)
if hasattr(child, "set_back_callback"):
child.set_back_callback(self._go_back)
def _render(self, rect):
if self._current_sub_panel and self._current_sub_panel in self._sub_panels:
self._sub_panels[self._current_sub_panel].render(rect)
elif self._manager_view is not None:
self._manager_view.render(rect)
def show_event(self):
super().show_event()
if self._current_sub_panel and self._current_sub_panel in self._sub_panels:
self._sub_panels[self._current_sub_panel].show_event()
elif self._manager_view is not None:
self._manager_view.show_event()
def hide_event(self):
super().hide_event()
if self._current_sub_panel and self._current_sub_panel in self._sub_panels:
self._sub_panels[self._current_sub_panel].hide_event()
elif self._manager_view is not None:
self._manager_view.hide_event()
# ── shared dialog helpers ──
def _show_slider(self, key, min_v, max_v, step=1, unit="",
value_type="int", current_value=None, title=None):
"""Unified slider dialog (int/float).
title: if provided, used as dialog title; otherwise uses tr(key).
"""
def on_close(res, val):
if res == DialogResult.CONFIRM:
if value_type == "float":
self._params.put_float(key, float(val))
else:
self._params.put_int(key, int(val))
if current_value is None:
current_value = self._params.get_float(key) if value_type == "float" else self._params.get_int(key)
dialog_title = tr(title) if title else tr(key)
gui_app.push_widget(AetherSliderDialog(dialog_title, min_v, max_v, step, current_value, on_close,
unit=unit, color=self.SLIDER_COLOR))
def _show_string_select(self, key, options, default="None"):
"""String-based multi-option selector (puts string via params.put)."""
current = self._params.get(key, encoding="utf-8") or default
def on_select(res):
if res == DialogResult.CONFIRM and dialog.selection:
self._params.put(key, dialog.selection)
dialog = MultiOptionDialog(tr(key), options, current, callback=on_select)
gui_app.push_widget(dialog)
def _show_labeled_select(self, title, key, options, current_value):
"""Integer-based multi-option selector with label/value pairs (puts int)."""
option_labels = [tr(label) for _, label in options]
label_to_value = {tr(label): value for value, label in options}
default = next((tr(label) for value, label in options if value == current_value), option_labels[0])
def on_select(res):
if res == DialogResult.CONFIRM and dialog.selection:
self._params.put_int(key, label_to_value[dialog.selection])
dialog = MultiOptionDialog(tr(title), option_labels, default, callback=on_select)
gui_app.push_widget(dialog)
@@ -22,7 +22,7 @@ from openpilot.system.ui.widgets.option_dialog import MultiOptionDialog
from openpilot.system.ui.widgets.label import gui_label
from openpilot.selfdrive.ui.ui_state import ui_state
from openpilot.selfdrive.ui.layouts.settings.starpilot.panel import StarPilotPanel
from openpilot.selfdrive.ui.layouts.settings.starpilot.panel import _SettingsPage
from openpilot.selfdrive.ui.layouts.settings.starpilot.aethergrid import (
AETHER_COMPACT_ROW_HEIGHT,
AETHER_LIST_METRICS,
@@ -811,7 +811,7 @@ class SystemSettingsManagerView(Widget):
subtitle_color=AetherListColors.SUBTEXT if not danger else rl.Color(203, 171, 178, 255),
)
class StarPilotSystemLayout(StarPilotPanel):
class StarPilotSystemLayout(_SettingsPage):
_BACKUP_NAME_SANITIZE_RE = re.compile(r"[^A-Za-z0-9._-]+")
def __init__(self):
@@ -826,13 +826,8 @@ class StarPilotSystemLayout(StarPilotPanel):
self._refresh_storage_cache(force=True)
def show_event(self):
super().show_event()
self._refresh_storage_cache(force=True)
self._manager_view.show_event()
def hide_event(self):
super().hide_event()
self._manager_view.hide_event()
super().show_event()
def _render(self, rect: rl.Rectangle):
if self._pending_storage_text is not None:
@@ -843,7 +838,7 @@ class StarPilotSystemLayout(StarPilotPanel):
self._storage_updated_at = rl.get_time()
self._storage_refresh_pending = False
self._refresh_storage_cache()
self._manager_view.render(rect)
super()._render(rect)
def _refresh_storage_cache(self, force: bool = False):
now = rl.get_time()