mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-11-30 00:33:41 +08:00
ui: move BigPillButton into button.py (#39297)
This commit is contained in:
@@ -9,7 +9,7 @@ from openpilot.system.ui.widgets import Widget
|
||||
from openpilot.system.ui.widgets.button import SmallCircleIconButton
|
||||
from openpilot.system.ui.widgets.scroller import NavScroller, Scroller
|
||||
from openpilot.system.ui.widgets.nav_widget import NavWidget
|
||||
from openpilot.system.ui.mici_setup import GreyBigButton, BigPillButton
|
||||
from openpilot.selfdrive.ui.mici.widgets.button import GreyBigButton, BigPillButton
|
||||
from openpilot.system.ui.widgets.label import gui_label
|
||||
from openpilot.system.ui.lib.multilang import tr
|
||||
from openpilot.common.version import terms_version, training_version
|
||||
|
||||
@@ -6,7 +6,7 @@ from collections.abc import Callable
|
||||
from openpilot.system.ui.widgets import Widget
|
||||
from openpilot.system.ui.widgets.label import UnifiedLabel
|
||||
from openpilot.system.ui.widgets.scroller import DO_ZOOM
|
||||
from openpilot.system.ui.lib.application import gui_app, FontWeight, MousePos, TextAlignmentVertical, FONT_SCALE
|
||||
from openpilot.system.ui.lib.application import gui_app, FontWeight, MousePos, TextAlignment, TextAlignmentVertical, FONT_SCALE
|
||||
from openpilot.common.filter_simple import BounceFilter
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -397,6 +397,42 @@ class GreyBigButton(BigButton):
|
||||
self._draw_content(self._rect.y)
|
||||
|
||||
|
||||
class BigPillButton(BigButton):
|
||||
def __init__(self, *args, green: bool = False, disabled_background: bool = False, **kwargs):
|
||||
self._green = green
|
||||
self._disabled_background = disabled_background
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self._label.set_font_size(48)
|
||||
self._label.set_alignment(TextAlignment.CENTER)
|
||||
self._label.set_alignment_vertical(TextAlignmentVertical.MIDDLE)
|
||||
|
||||
def _load_images(self):
|
||||
if self._green:
|
||||
self._txt_default_bg = gui_app.texture("icons_mici/setup/start_button.png", 402, 180)
|
||||
self._txt_pressed_bg = gui_app.texture("icons_mici/setup/start_button_pressed.png", 402, 180)
|
||||
else:
|
||||
self._txt_default_bg = gui_app.texture("icons_mici/setup/continue.png", 402, 180)
|
||||
self._txt_pressed_bg = gui_app.texture("icons_mici/setup/continue_pressed.png", 402, 180)
|
||||
self._txt_disabled_bg = gui_app.texture("icons_mici/setup/continue_disabled.png", 402, 180)
|
||||
|
||||
def set_green(self, green: bool):
|
||||
if self._green != green:
|
||||
self._green = green
|
||||
self._load_images()
|
||||
|
||||
def _update_label_layout(self):
|
||||
# Don't change label text size
|
||||
pass
|
||||
|
||||
def _handle_background(self) -> tuple[rl.Texture, float, float, float]:
|
||||
txt_bg, btn_x, btn_y, scale = super()._handle_background()
|
||||
|
||||
if self._disabled_background:
|
||||
txt_bg = self._txt_disabled_bg
|
||||
return txt_bg, btn_x, btn_y, scale
|
||||
|
||||
|
||||
class BigMultiParamToggle(BigMultiToggle):
|
||||
def __init__(self, text: str, param: str, options: list[str], toggle_callback: Callable | None = None,
|
||||
select_callback: Callable | None = None, *, description: str = "", description_icon: Union[rl.Texture, None] = None):
|
||||
|
||||
@@ -28,7 +28,7 @@ from openpilot.system.ui.widgets.slider import LargerSlider
|
||||
from openpilot.selfdrive.ui.mici.layouts.settings.network import WifiNetworkButton
|
||||
from openpilot.selfdrive.ui.mici.layouts.settings.network.wifi_ui import WifiUIMici
|
||||
from openpilot.selfdrive.ui.mici.widgets.dialog import BigInputDialog, BigConfirmationCircleButton
|
||||
from openpilot.selfdrive.ui.mici.widgets.button import BigButton, GreyBigButton
|
||||
from openpilot.selfdrive.ui.mici.widgets.button import GreyBigButton, BigPillButton
|
||||
|
||||
NetworkType = log.DeviceState.NetworkType
|
||||
|
||||
@@ -254,42 +254,6 @@ class FailedPage(NavScroller):
|
||||
self._reason_card.set_visible(False)
|
||||
|
||||
|
||||
class BigPillButton(BigButton):
|
||||
def __init__(self, *args, green: bool = False, disabled_background: bool = False, **kwargs):
|
||||
self._green = green
|
||||
self._disabled_background = disabled_background
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self._label.set_font_size(48)
|
||||
self._label.set_alignment(TextAlignment.CENTER)
|
||||
self._label.set_alignment_vertical(TextAlignmentVertical.MIDDLE)
|
||||
|
||||
def _load_images(self):
|
||||
if self._green:
|
||||
self._txt_default_bg = gui_app.texture("icons_mici/setup/start_button.png", 402, 180)
|
||||
self._txt_pressed_bg = gui_app.texture("icons_mici/setup/start_button_pressed.png", 402, 180)
|
||||
else:
|
||||
self._txt_default_bg = gui_app.texture("icons_mici/setup/continue.png", 402, 180)
|
||||
self._txt_pressed_bg = gui_app.texture("icons_mici/setup/continue_pressed.png", 402, 180)
|
||||
self._txt_disabled_bg = gui_app.texture("icons_mici/setup/continue_disabled.png", 402, 180)
|
||||
|
||||
def set_green(self, green: bool):
|
||||
if self._green != green:
|
||||
self._green = green
|
||||
self._load_images()
|
||||
|
||||
def _update_label_layout(self):
|
||||
# Don't change label text size
|
||||
pass
|
||||
|
||||
def _handle_background(self) -> tuple[rl.Texture, float, float, float]:
|
||||
txt_bg, btn_x, btn_y, scale = super()._handle_background()
|
||||
|
||||
if self._disabled_background:
|
||||
txt_bg = self._txt_disabled_bg
|
||||
return txt_bg, btn_x, btn_y, scale
|
||||
|
||||
|
||||
class NetworkSetupPageBase(Scroller):
|
||||
def __init__(self, network_monitor: NetworkConnectivityMonitor, continue_callback: Callable[[bool], None],
|
||||
disable_connect_hint: bool = False):
|
||||
|
||||
@@ -11,8 +11,8 @@ from openpilot.system.ui.lib.application import gui_app, FontWeight, TextAlignme
|
||||
from openpilot.system.ui.widgets.nav_widget import NavWidget
|
||||
from openpilot.system.ui.widgets.scroller import Scroller
|
||||
from openpilot.system.ui.widgets.label import UnifiedLabel
|
||||
from openpilot.system.ui.mici_setup import (NetworkSetupPage, FailedPage, NetworkConnectivityMonitor,
|
||||
GreyBigButton, BigPillButton)
|
||||
from openpilot.system.ui.mici_setup import (NetworkSetupPage, FailedPage, NetworkConnectivityMonitor)
|
||||
from openpilot.selfdrive.ui.mici.widgets.button import GreyBigButton, BigPillButton
|
||||
|
||||
|
||||
class UpdaterNetworkSetupPage(NetworkSetupPage):
|
||||
|
||||
Reference in New Issue
Block a user