mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-08-21 08:14:00 +08:00
raylib: remove functional confirmation dialog (#36231)
* rm * yess * clean up
This commit is contained in:
@@ -10,7 +10,7 @@ from openpilot.selfdrive.ui.widgets.pairing_dialog import PairingDialog
|
||||
from openpilot.system.hardware import TICI
|
||||
from openpilot.system.ui.lib.application import gui_app
|
||||
from openpilot.system.ui.widgets import Widget, DialogResult
|
||||
from openpilot.system.ui.widgets.confirm_dialog import confirm_dialog, alert_dialog
|
||||
from openpilot.system.ui.widgets.confirm_dialog import ConfirmDialog, alert_dialog
|
||||
from openpilot.system.ui.widgets.html_render import HtmlRenderer
|
||||
from openpilot.system.ui.widgets.list_view import text_item, button_item, dual_button_item
|
||||
from openpilot.system.ui.widgets.option_dialog import MultiOptionDialog
|
||||
@@ -92,13 +92,11 @@ class DeviceLayout(Widget):
|
||||
|
||||
def _reset_calibration_prompt(self):
|
||||
if ui_state.engaged:
|
||||
gui_app.set_modal_overlay(lambda: alert_dialog("Disengage to Reset Calibration"))
|
||||
gui_app.set_modal_overlay(alert_dialog("Disengage to Reset Calibration"))
|
||||
return
|
||||
|
||||
gui_app.set_modal_overlay(
|
||||
lambda: confirm_dialog("Are you sure you want to reset calibration?", "Reset"),
|
||||
callback=self._reset_calibration,
|
||||
)
|
||||
dialog = ConfirmDialog("Are you sure you want to reset calibration?", "Reset")
|
||||
gui_app.set_modal_overlay(dialog, callback=self._reset_calibration)
|
||||
|
||||
def _reset_calibration(self, result: int):
|
||||
if ui_state.engaged or result != DialogResult.CONFIRM:
|
||||
@@ -113,13 +111,11 @@ class DeviceLayout(Widget):
|
||||
|
||||
def _reboot_prompt(self):
|
||||
if ui_state.engaged:
|
||||
gui_app.set_modal_overlay(lambda: alert_dialog("Disengage to Reboot"))
|
||||
gui_app.set_modal_overlay(alert_dialog("Disengage to Reboot"))
|
||||
return
|
||||
|
||||
gui_app.set_modal_overlay(
|
||||
lambda: confirm_dialog("Are you sure you want to reboot?", "Reboot"),
|
||||
callback=self._perform_reboot,
|
||||
)
|
||||
dialog = ConfirmDialog("Are you sure you want to reboot?", "Reboot")
|
||||
gui_app.set_modal_overlay(dialog, callback=self._perform_reboot)
|
||||
|
||||
def _perform_reboot(self, result: int):
|
||||
if not ui_state.engaged and result == DialogResult.CONFIRM:
|
||||
@@ -127,13 +123,11 @@ class DeviceLayout(Widget):
|
||||
|
||||
def _power_off_prompt(self):
|
||||
if ui_state.engaged:
|
||||
gui_app.set_modal_overlay(lambda: alert_dialog("Disengage to Power Off"))
|
||||
gui_app.set_modal_overlay(alert_dialog("Disengage to Power Off"))
|
||||
return
|
||||
|
||||
gui_app.set_modal_overlay(
|
||||
lambda: confirm_dialog("Are you sure you want to power off?", "Power Off"),
|
||||
callback=self._perform_power_off,
|
||||
)
|
||||
dialog = ConfirmDialog("Are you sure you want to power off?", "Power Off")
|
||||
gui_app.set_modal_overlay(dialog, callback=self._perform_power_off)
|
||||
|
||||
def _perform_power_off(self, result: int):
|
||||
if not ui_state.engaged and result == DialogResult.CONFIRM:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from openpilot.common.params import Params
|
||||
from openpilot.system.ui.lib.application import gui_app
|
||||
from openpilot.system.ui.widgets import Widget, DialogResult
|
||||
from openpilot.system.ui.widgets.confirm_dialog import confirm_dialog
|
||||
from openpilot.system.ui.widgets.confirm_dialog import ConfirmDialog
|
||||
from openpilot.system.ui.widgets.list_view import button_item, text_item
|
||||
from openpilot.system.ui.widgets.scroller import Scroller
|
||||
|
||||
@@ -36,7 +36,5 @@ class SoftwareLayout(Widget):
|
||||
if result == DialogResult.CONFIRM:
|
||||
self._params.put_bool("DoUninstall", True)
|
||||
|
||||
gui_app.set_modal_overlay(
|
||||
lambda: confirm_dialog("Are you sure you want to uninstall?", "Uninstall"),
|
||||
callback=handle_uninstall_confirmation,
|
||||
)
|
||||
dialog = ConfirmDialog("Are you sure you want to uninstall?", "Uninstall")
|
||||
gui_app.set_modal_overlay(dialog, callback=handle_uninstall_confirmation)
|
||||
|
||||
@@ -49,7 +49,7 @@ class SshKeyAction(ItemAction):
|
||||
# Show error dialog if there's an error
|
||||
if self._error_message:
|
||||
message = copy.copy(self._error_message)
|
||||
gui_app.set_modal_overlay(lambda: alert_dialog(message))
|
||||
gui_app.set_modal_overlay(alert_dialog(message))
|
||||
self._username = ""
|
||||
self._error_message = ""
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import pyray as rl
|
||||
from openpilot.system.ui.lib.application import gui_app, FontWeight
|
||||
from openpilot.system.ui.widgets import DialogResult
|
||||
from openpilot.system.ui.widgets.button import gui_button, ButtonStyle, Button
|
||||
from openpilot.system.ui.widgets.label import gui_text_box, Label
|
||||
from openpilot.system.ui.widgets.button import ButtonStyle, Button
|
||||
from openpilot.system.ui.widgets.label import Label
|
||||
from openpilot.system.ui.widgets import Widget
|
||||
|
||||
DIALOG_WIDTH = 1520
|
||||
@@ -12,6 +12,7 @@ MARGIN = 50
|
||||
TEXT_AREA_HEIGHT_REDUCTION = 200
|
||||
BACKGROUND_COLOR = rl.Color(27, 27, 27, 255)
|
||||
|
||||
|
||||
class ConfirmDialog(Widget):
|
||||
def __init__(self, text: str, confirm_text: str, cancel_text: str = "Cancel"):
|
||||
super().__init__()
|
||||
@@ -66,57 +67,6 @@ class ConfirmDialog(Widget):
|
||||
|
||||
return self._dialog_result
|
||||
|
||||
def confirm_dialog(message: str, confirm_text: str, cancel_text: str = "Cancel") -> DialogResult:
|
||||
dialog_x = (gui_app.width - DIALOG_WIDTH) / 2
|
||||
dialog_y = (gui_app.height - DIALOG_HEIGHT) / 2
|
||||
dialog_rect = rl.Rectangle(dialog_x, dialog_y, DIALOG_WIDTH, DIALOG_HEIGHT)
|
||||
|
||||
# Calculate button positions at the bottom of the dialog
|
||||
bottom = dialog_rect.y + dialog_rect.height
|
||||
button_width = (dialog_rect.width - 3 * MARGIN) // 2
|
||||
no_button_x = dialog_rect.x + MARGIN
|
||||
yes_button_x = dialog_rect.x + dialog_rect.width - button_width - MARGIN
|
||||
button_y = bottom - BUTTON_HEIGHT - MARGIN
|
||||
no_button = rl.Rectangle(no_button_x, button_y, button_width, BUTTON_HEIGHT)
|
||||
yes_button = rl.Rectangle(yes_button_x, button_y, button_width, BUTTON_HEIGHT)
|
||||
|
||||
# Draw the dialog background
|
||||
rl.draw_rectangle_rec(dialog_rect, BACKGROUND_COLOR)
|
||||
|
||||
# Draw the message in the dialog, centered
|
||||
text_rect = rl.Rectangle(dialog_rect.x + MARGIN, dialog_rect.y, dialog_rect.width - 2 * MARGIN, dialog_rect.height - TEXT_AREA_HEIGHT_REDUCTION)
|
||||
gui_text_box(
|
||||
text_rect,
|
||||
message,
|
||||
font_size=70,
|
||||
alignment=rl.GuiTextAlignment.TEXT_ALIGN_CENTER,
|
||||
alignment_vertical=rl.GuiTextAlignmentVertical.TEXT_ALIGN_MIDDLE,
|
||||
font_weight=FontWeight.BOLD,
|
||||
)
|
||||
|
||||
# Initialize result; -1 means no action taken yet
|
||||
result = DialogResult.NO_ACTION
|
||||
|
||||
# Check for keyboard input for accessibility
|
||||
if rl.is_key_pressed(rl.KeyboardKey.KEY_ENTER):
|
||||
result = DialogResult.CONFIRM
|
||||
elif rl.is_key_pressed(rl.KeyboardKey.KEY_ESCAPE):
|
||||
result = DialogResult.CANCEL
|
||||
|
||||
# Check for button clicks
|
||||
if cancel_text:
|
||||
if gui_button(yes_button, confirm_text, button_style=ButtonStyle.PRIMARY):
|
||||
result = DialogResult.CONFIRM
|
||||
if gui_button(no_button, cancel_text):
|
||||
result = DialogResult.CANCEL
|
||||
else:
|
||||
centered_button_x = dialog_rect.x + (dialog_rect.width - button_width) / 2
|
||||
centered_yes_button = rl.Rectangle(centered_button_x, button_y, button_width, BUTTON_HEIGHT)
|
||||
if gui_button(centered_yes_button, confirm_text, button_style=ButtonStyle.PRIMARY):
|
||||
result = DialogResult.CONFIRM
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def alert_dialog(message: str, button_text: str = "OK") -> DialogResult:
|
||||
return confirm_dialog(message, button_text, cancel_text="")
|
||||
def alert_dialog(message: str, button_text: str = "OK"):
|
||||
return ConfirmDialog(message, button_text, cancel_text="")
|
||||
|
||||
Reference in New Issue
Block a user