pyui: add DialogResult enum (#35500)

add DialogResult enum
pull/35494/head
Dean Lee 1 week ago committed by GitHub
parent ce93a7215d
commit e93a7234bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 6
      system/ui/lib/application.py
  2. 16
      system/ui/widgets/confirm_dialog.py

@ -27,6 +27,12 @@ ASSETS_DIR = files("openpilot.selfdrive").joinpath("assets")
FONT_DIR = ASSETS_DIR.joinpath("fonts")
class DialogResult(IntEnum):
CANCEL = 0
CONFIRM = 1
NO_ACTION = -1
class Widget(abc.ABC):
def __init__(self):
self._is_pressed = False

@ -1,9 +1,9 @@
import pyray as rl
from openpilot.system.ui.lib.application import gui_app
from openpilot.system.ui.lib.application import gui_app, DialogResult
from openpilot.system.ui.lib.button import gui_button, ButtonStyle
from openpilot.system.ui.lib.label import gui_text_box
# Constants for dialog dimensions and styling
DIALOG_WIDTH = 1520
DIALOG_HEIGHT = 600
BUTTON_HEIGHT = 160
@ -12,7 +12,7 @@ TEXT_AREA_HEIGHT_REDUCTION = 200
BACKGROUND_COLOR = rl.Color(27, 27, 27, 255)
def confirm_dialog(message: str, confirm_text: str, cancel_text: str = "Cancel") -> int:
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)
@ -40,18 +40,18 @@ def confirm_dialog(message: str, confirm_text: str, cancel_text: str = "Cancel")
)
# Initialize result; -1 means no action taken yet
result = -1
result = DialogResult.NO_ACTION
# Check for keyboard input for accessibility
if rl.is_key_pressed(rl.KeyboardKey.KEY_ENTER):
result = 1 # Confirm
result = DialogResult.CONFIRM
elif rl.is_key_pressed(rl.KeyboardKey.KEY_ESCAPE):
result = 0 # Cancel
result = DialogResult.CANCEL
# Check for button clicks
if gui_button(yes_button, confirm_text, button_style=ButtonStyle.PRIMARY):
result = 1 # Confirm
result = DialogResult.CONFIRM
if gui_button(no_button, cancel_text):
result = 0 # Cancel
result = DialogResult.CANCEL
return result

Loading…
Cancel
Save