ui: unify model source predicate and per-source bundle lookup in model_info

This commit is contained in:
Jason Wen
2026-08-26 02:48:03 -04:00
parent a1c904bb9a
commit 5c3505b25f
3 changed files with 26 additions and 34 deletions
@@ -10,11 +10,10 @@ import time
import pyray as rl
from openpilot.cereal import custom
from openpilot.sunnypilot.models.fetcher import ModelFetcher, get_cached_bundles
from openpilot.sunnypilot.models.helpers import ACTIVE_BUNDLE_KEYS, get_selected_bundle, resolve_bundle_by_ref
from openpilot.common.constants import CV
from openpilot.selfdrive.ui.ui_state import device, ui_state
from openpilot.selfdrive.ui.sunnypilot.model_info import model_info
from openpilot.selfdrive.ui.sunnypilot.model_info import active_source, bundles_for_source, model_info
from openpilot.system.ui.lib.multilang import tr
from openpilot.system.ui.lib.application import gui_app
from openpilot.system.ui.widgets import DialogResult, Widget
@@ -207,12 +206,7 @@ class ModelsLayout(Widget):
ui_state.params.put("ModelManager_DownloadRef", selected_bundle.ref)
def _resolve_selected_bundle(self, ref):
"""Finds the bundle for a ref across both hardware manifests."""
active = ModelFetcher.active_source(ui_state.sm["deviceState"].chestnutPresent)
source_bundles = {
source: self.model_manager.availableBundles if source == active else get_cached_bundles(ui_state.params, source)
for source in ("qcom", "usbgpu")
}
source_bundles = {source: bundles_for_source(source) for source in ("qcom", "usbgpu")}
resolved = resolve_bundle_by_ref(ref, source_bundles)
return resolved[0] if resolved else None
@@ -236,11 +230,10 @@ class ModelsLayout(Widget):
return folders_list
def _handle_current_model_clicked(self):
self._open_source_dialog(ModelFetcher.active_source(ui_state.sm["deviceState"].chestnutPresent))
self._open_source_dialog(active_source())
def _handle_other_model_clicked(self):
active = ModelFetcher.active_source(ui_state.sm["deviceState"].chestnutPresent)
self._open_source_dialog("qcom" if active == "usbgpu" else "usbgpu")
self._open_source_dialog("qcom" if active_source() == "usbgpu" else "usbgpu")
def _open_source_dialog(self, source):
"""Opens the picker for one hardware: its model folders plus the Default reset entry."""
@@ -256,9 +249,7 @@ class ModelsLayout(Widget):
gui_app.push_widget(self.model_dialog)
def _source_folders(self, favorites, source):
"""Default reset entry on top, then the hardware's model folders."""
active = ModelFetcher.active_source(ui_state.sm["deviceState"].chestnutPresent)
bundles = self.model_manager.availableBundles if source == active else get_cached_bundles(ui_state.params, source)
bundles = bundles_for_source(source)
if not bundles:
return []
folders_list = [TreeFolder("", [TreeNode("Default", {'display_name': "Default"})])]
@@ -8,11 +8,10 @@ import pyray as rl
from openpilot.cereal import custom
from openpilot.selfdrive.ui.mici.widgets.dialog import BigDialog
from openpilot.sunnypilot.models.fetcher import ModelFetcher, get_cached_bundles
from openpilot.sunnypilot.models.helpers import ACTIVE_BUNDLE_KEYS
from openpilot.selfdrive.ui.mici.widgets.button import BigButton
from openpilot.selfdrive.ui.ui_state import ui_state, device
from openpilot.selfdrive.ui.sunnypilot.model_info import model_info
from openpilot.selfdrive.ui.sunnypilot.model_info import bundles_for_source, model_info
from openpilot.system.ui.lib.application import FontWeight, gui_app
from openpilot.system.ui.lib.multilang import tr
from openpilot.system.ui.widgets import Widget
@@ -111,16 +110,12 @@ class ModelsLayoutMici(NavScroller):
favs = ui_state.params.get("ModelManager_Favs")
favorites = set(favs.split(';')) if favs else set()
active = ModelFetcher.active_source(ui_state.sm["deviceState"].chestnutPresent)
if source != active:
bundles = get_cached_bundles(ui_state.params, source)
if not bundles:
gui_app.push_widget(BigDialog(title=tr("No models available"),
description=tr("No models are available for this hardware yet. Connect to the internet and refresh the model list.")))
return
else:
bundles = self.model_manager.availableBundles
bundles = bundles_for_source(source)
if not bundles:
gui_app.push_widget(BigDialog(title=tr("No models available"),
description=tr("No models are available for this hardware yet. Connect to the internet and refresh the model list.")))
return
folders = self._get_grouped_bundles(bundles, favorites)
folder_buttons = []
@@ -155,13 +150,8 @@ class ModelsLayoutMici(NavScroller):
return
favs = ui_state.params.get("ModelManager_Favs")
favorites = set(favs.split(';')) if favs else set()
active = ModelFetcher.active_source(ui_state.sm["deviceState"].chestnutPresent)
if source != active:
bundles = get_cached_bundles(ui_state.params, source)
else:
bundles = self.model_manager.availableBundles
folders = self._get_grouped_bundles(bundles, favorites)
folders = self._get_grouped_bundles(bundles_for_source(source), favorites)
bundles = sorted(folders.get(folder_name, []), key=lambda b: b.index, reverse=True)
btns = []
@@ -5,15 +5,26 @@ This file is part of sunnypilot and is licensed under the MIT License.
See the LICENSE.md file in the root directory for more details.
"""
from openpilot.selfdrive.ui.ui_state import ui_state
from openpilot.sunnypilot.models.fetcher import get_cached_bundles
from openpilot.sunnypilot.models.helpers import get_active_source, get_selected_bundle
from openpilot.sunnypilot.models.model_name import DEFAULT_BIG_MODEL, DEFAULT_MODEL
def active_source() -> str:
return get_active_source(usbgpu=ui_state.usbgpu,
usbgpu_active=ui_state.usbgpu_active, usbgpu_loading=ui_state.usbgpu_loading,
offroad=ui_state.is_offroad())
def bundles_for_source(source: str):
if source == active_source():
return ui_state.sm["modelManagerSP"].availableBundles
return get_cached_bundles(ui_state.params, source)
def model_info() -> tuple[str, str, str]:
"""returns (active source, active model name, other model name)"""
source = get_active_source(usbgpu=ui_state.usbgpu,
usbgpu_active=ui_state.usbgpu_active, usbgpu_loading=ui_state.usbgpu_loading,
offroad=ui_state.is_offroad())
source = active_source()
other = "qcom" if source == "usbgpu" else "usbgpu"
active_bundle = get_selected_bundle(ui_state.params, source)
other_bundle = get_selected_bundle(ui_state.params, other)