mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-10-28 00:53:45 +08:00
52 lines
2.2 KiB
Python
52 lines
2.2 KiB
Python
"""Compact Device child for the shared saved display preferences."""
|
|
|
|
from typing import Protocol
|
|
|
|
from openpilot.starpilot.ui.feature_settings_state import FeatureSettingsRequest, FeatureSettingsState, row_change
|
|
from openpilot.system.ui.lib.application import gui_app
|
|
from openpilot.system.ui.widgets.scroller import NavScroller
|
|
from openpilot.selfdrive.ui.mici.widgets.button import BigButton, GreyBigButton
|
|
|
|
|
|
class DisplaySession(Protocol):
|
|
def display_snapshot(self) -> FeatureSettingsState: ...
|
|
def display_request(self, request: FeatureSettingsRequest) -> bool: ...
|
|
|
|
|
|
class DisplayCompact:
|
|
def __init__(self, session: DisplaySession):
|
|
self.session = session
|
|
|
|
def entry_button(self) -> BigButton:
|
|
button = BigButton("display", "brightness and screen timing")
|
|
button.set_click_callback(self.open)
|
|
return button
|
|
|
|
def open(self) -> None:
|
|
page = NavScroller()
|
|
self._populate(page)
|
|
gui_app.push_widget(page)
|
|
|
|
def _populate(self, page: NavScroller) -> None:
|
|
state = self.session.display_snapshot()
|
|
cards = [GreyBigButton("display", "saved brightness and screen timing")]
|
|
for row in state.rows:
|
|
description = row.value + (" " + row.unit if row.unit and row.value != "Auto" else "") + (". " + row.reason if row.reason else "")
|
|
if not row.available:
|
|
cards.append(GreyBigButton(row.label.lower(), description.lower()))
|
|
continue
|
|
numeric = row.step > 0 and row.value != "Auto" and not row.repair_value
|
|
for direction in ((-1, 1) if numeric else (1,)):
|
|
label = row.label.lower() + (" set " + row.repair_value.lower() if row.repair_value else
|
|
" -" if numeric and direction < 0 else " +" if numeric else "")
|
|
button = BigButton(label, description.lower())
|
|
button.set_enabled(row_change(row, direction) is not None)
|
|
def clicked(source=row, step=direction) -> None:
|
|
request = row_change(source, step)
|
|
if request is not None and self.session.display_request(request):
|
|
self._populate(page)
|
|
button.set_click_callback(clicked)
|
|
cards.append(button)
|
|
page._scroller.items.clear()
|
|
page._scroller.add_widgets(cards)
|