@@ -64,33 +64,31 @@ def _render(self, rect: rl.Rectangle):
6464 rl.draw_texture_ex(self._fcc_logo, fcc_pos, 0.0, 1.0, rl.WHITE)
6565
6666
67- def _engaged_confirmation_callback (callback: Callable, action_text: str):
67+ def _engaged_confirmation_click (callback: Callable, action_text: str, icon: rl.Texture, exit_on_confirm: bool = True, red: bool = False ):
6868 if not ui_state.engaged:
6969 def confirm_callback():
7070 # Check engaged again in case it changed while the dialog was open
71+ # TODO: if true, we stay on the dialog if not exit_on_confirm until normal onroad timeout
7172 if not ui_state.engaged:
7273 callback()
7374
74- red = False
75- if action_text == "power off":
76- icon = gui_app.texture("icons_mici/settings/device/power.png", 64, 66)
77- red = True
78- elif action_text == "reboot":
79- icon = gui_app.texture("icons_mici/settings/device/reboot.png", 64, 70)
80- elif action_text == "reset":
81- icon = gui_app.texture("icons_mici/settings/device/lkas.png", 122, 64)
82- elif action_text == "uninstall":
83- icon = gui_app.texture("icons_mici/settings/device/uninstall.png", 64, 64)
84- else:
85- # TODO: check
86- icon = gui_app.texture("icons_mici/settings/comma_icon.png", 36, 64)
87-
88- dlg: BigConfirmationDialog | BigDialog = BigConfirmationDialog(f"slide to\n{action_text.lower()}", icon, confirm_callback,
89- red=red, exit_on_confirm=action_text == "reset")
90- gui_app.push_widget(dlg)
75+ gui_app.push_widget(BigConfirmationDialog(f"slide to\n{action_text.lower()}", icon, confirm_callback, exit_on_confirm=exit_on_confirm, red=red))
9176 else:
92- dlg = BigDialog(f"Disengage to {action_text}", "")
93- gui_app.push_widget(dlg)
77+ gui_app.push_widget(BigDialog(f"Disengage to {action_text}", ""))
78+
79+
80+ class EngagedConfirmationCircleButton(BigCircleButton):
81+ def __init__(self, title: str, icon: rl.Texture, callback: Callable[[], None], exit_on_confirm: bool = True,
82+ red: bool = False, icon_offset: tuple[int, int] = (0, 0)):
83+ super().__init__(icon, red, icon_offset)
84+ self.set_click_callback(lambda: _engaged_confirmation_click(callback, title, icon, exit_on_confirm=exit_on_confirm, red=red))
85+
86+
87+ class EngagedConfirmationButton(BigButton):
88+ def __init__(self, text: str, action_text: str, icon: rl.Texture, callback: Callable[[], None],
89+ exit_on_confirm: bool = True, red: bool = False):
90+ super().__init__(text, "", icon)
91+ self.set_click_callback(lambda: _engaged_confirmation_click(callback, action_text, icon, exit_on_confirm=exit_on_confirm, red=red))
9492
9593
9694class DeviceInfoLayoutMici(Widget):
@@ -310,17 +308,18 @@ def reset_calibration_callback():
310308 def uninstall_openpilot_callback():
311309 ui_state.params.put_bool("DoUninstall", True)
312310
313- reset_calibration_btn = BigButton ("reset calibration", "", gui_app.texture("icons_mici/settings/device/lkas.png", 122, 64))
314- reset_calibration_btn.set_click_callback(lambda: _engaged_confirmation_callback(reset_calibration_callback, "reset") )
311+ reset_calibration_btn = EngagedConfirmationButton ("reset calibration", "reset ", gui_app.texture("icons_mici/settings/device/lkas.png", 122, 64),
312+ reset_calibration_callback )
315313
316- uninstall_openpilot_btn = BigButton("uninstall openpilot", "", gui_app.texture("icons_mici/settings/device/uninstall.png", 64, 64))
317- uninstall_openpilot_btn.set_click_callback(lambda: _engaged_confirmation_callback(uninstall_openpilot_callback, "uninstall"))
314+ uninstall_openpilot_btn = EngagedConfirmationButton("uninstall openpilot", "uninstall",
315+ gui_app.texture("icons_mici/settings/device/uninstall.png", 64, 64),
316+ uninstall_openpilot_callback, exit_on_confirm=False)
318317
319- reboot_btn = BigCircleButton( gui_app.texture("icons_mici/settings/device/reboot.png", 64, 70))
320- reboot_btn.set_click_callback(lambda: _engaged_confirmation_callback( reboot_callback, "reboot") )
318+ reboot_btn = EngagedConfirmationCircleButton("reboot", gui_app.texture("icons_mici/settings/device/reboot.png", 64, 70),
319+ reboot_callback, exit_on_confirm=False )
321320
322- self._power_off_btn = BigCircleButton( gui_app.texture("icons_mici/settings/device/power.png", 64, 66), red=True)
323- self._power_off_btn.set_click_callback(lambda: _engaged_confirmation_callback( power_off_callback, "power off") )
321+ self._power_off_btn = EngagedConfirmationCircleButton("power off", gui_app.texture("icons_mici/settings/device/power.png", 64, 66),
322+ power_off_callback, exit_on_confirm=False, red=True )
324323 self._power_off_btn.set_visible(lambda: not ui_state.ignition)
325324
326325 regulatory_btn = BigButton("regulatory info", "", gui_app.texture("icons_mici/settings/device/info.png", 64, 64))
0 commit comments