mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-08-23 08:53:44 +08:00
layout
This commit is contained in:
committed by
discountchubbs
parent
05e3eaf2fc
commit
37ffa5ed21
+12
-10
@@ -21,22 +21,24 @@ IN_CLOSE_WRITE = 0x00000008
|
||||
|
||||
|
||||
def sync_layout_params(layout, param_name, params):
|
||||
for item in getattr(layout, 'items', []):
|
||||
items = getattr(layout, 'items', []) or getattr(getattr(layout, '_scroller', None), '_items', [])
|
||||
for item in items:
|
||||
if not (action := getattr(item, 'action_item', None)):
|
||||
continue
|
||||
|
||||
toggle_key = getattr(getattr(action, 'toggle', None), 'param_key', None)
|
||||
action_key = getattr(action, 'param_key', None)
|
||||
toggle = getattr(getattr(action, 'toggle', None), 'param_key', None)
|
||||
param_key = toggle or getattr(action, 'param_key', None)
|
||||
|
||||
if param_name is None or toggle_key == param_name or action_key == param_name:
|
||||
if toggle_key:
|
||||
action.set_state(params.get_bool(toggle_key))
|
||||
elif action_key:
|
||||
value = int(params.get(action_key, return_default=True))
|
||||
if param_key and (param_name is None or param_key == param_name):
|
||||
if toggle:
|
||||
action.set_state(params.get_bool(param_key))
|
||||
elif hasattr(action, 'set_value'):
|
||||
action.set_value(params.get(param_key, return_default=True))
|
||||
else:
|
||||
param_value = int(params.get(param_key, return_default=True))
|
||||
for attribute in ['selected_button', 'current_value']:
|
||||
if hasattr(action, attribute):
|
||||
setattr(action, attribute, value)
|
||||
|
||||
setattr(action, attribute, param_value)
|
||||
|
||||
class ParamWatcher(Params):
|
||||
def __init__(self):
|
||||
|
||||
@@ -44,12 +44,6 @@ class UIStateSP:
|
||||
if self.active_layout:
|
||||
sync_layout_params(self.active_layout, None, self.params)
|
||||
|
||||
if self.active_layout:
|
||||
for method in ['update_settings', '_update_state', '_update_toggles']:
|
||||
if function := getattr(self.active_layout, method, None):
|
||||
function()
|
||||
break
|
||||
|
||||
def update_params(self) -> None:
|
||||
CP_SP_bytes = self.params.get("CarParamsSPPersistent")
|
||||
if CP_SP_bytes is not None:
|
||||
|
||||
Reference in New Issue
Block a user