mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-02-18 17:43:54 +08:00
fix callback
This commit is contained in:
@@ -8,9 +8,10 @@ from openpilot.system.ui.sunnypilot.lib.styles import style
|
||||
|
||||
|
||||
class ToggleActionSP(ToggleAction):
|
||||
def __init__(self, initial_state: bool = False, width: int = style.TOGGLE_WIDTH, enabled: bool | Callable[[], bool] = True, param: str | None = None):
|
||||
ToggleAction.__init__(self, initial_state, width, enabled)
|
||||
self.toggle = ToggleSP(initial_state=initial_state, param=param)
|
||||
def __init__(self, initial_state: bool = False, width: int = style.TOGGLE_WIDTH, enabled: bool | Callable[[], bool] = True,
|
||||
callback: Callable[[bool], None] | None = None, param: str | None = None):
|
||||
ToggleAction.__init__(self, initial_state, width, enabled, callback)
|
||||
self.toggle = ToggleSP(initial_state=initial_state, callback=callback, param=param)
|
||||
|
||||
class ListItemSP(ListItem):
|
||||
def __init__(self, title: str | Callable[[], str] = "", icon: str | None = None, description: str | Callable[[], str] | None = None,
|
||||
@@ -90,5 +91,5 @@ class ListItemSP(ListItem):
|
||||
|
||||
def toggle_item_sp(title: str | Callable[[], str], description: str | Callable[[], str] | None = None, initial_state: bool = False,
|
||||
callback: Callable | None = None, icon: str = "", enabled: bool | Callable[[], bool] = True, param: str | None = None) -> ListItem:
|
||||
action = ToggleActionSP(initial_state=initial_state, enabled=enabled, param=param)
|
||||
action = ToggleActionSP(initial_state=initial_state, enabled=enabled, callback=callback, param=param)
|
||||
return ListItemSP(title=title, description=description, action_item=action, icon=icon, callback=callback)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import pyray as rl
|
||||
from collections.abc import Callable
|
||||
from openpilot.common.params import Params
|
||||
from openpilot.system.ui.lib.application import MousePos
|
||||
from openpilot.system.ui.widgets.toggle import Toggle
|
||||
@@ -9,12 +10,12 @@ KNOB_RADIUS = style.TOGGLE_BG_HEIGHT / 2 - KNOB_PADDING
|
||||
SYMBOL_SIZE = KNOB_RADIUS / 2
|
||||
|
||||
class ToggleSP(Toggle):
|
||||
def __init__(self, initial_state=False, param: str | None = None):
|
||||
def __init__(self, initial_state=False, callback: Callable[[bool], None] | None = None, param: str | None = None):
|
||||
self.param_key = param
|
||||
self.params = Params()
|
||||
if self.param_key:
|
||||
initial_state = self.params.get_bool(self.param_key)
|
||||
Toggle.__init__(self, initial_state)
|
||||
Toggle.__init__(self, initial_state, callback)
|
||||
|
||||
def _handle_mouse_release(self, mouse_pos: MousePos):
|
||||
super()._handle_mouse_release(mouse_pos)
|
||||
|
||||
Reference in New Issue
Block a user