Dialog¶
swiftDialog integration for user-facing dialogs and notifications (macOS only).
- class Dialog(binary_path: str | None = None, temp_dir: str | Path | None = None, use_temp_file: bool = False)[source]¶
Bases:
objectExecutor class for displaying swiftDialog dialogs.
This class handles binary discovery, command building, subprocess execution, and temp file management for displaying
DialogTemplateconfigurations.By default, passes JSON configuration via –jsonstring (in-memory) to avoid file permission issues when running as root via MDM. When use_temp_file=True, creates a world-readable temp file for compatibility with all users.
- Parameters:
binary_path (str | None, optional) – Path to swiftDialog binary, or None to auto-discover
temp_dir (str | Path, optional) – Directory for temp file creation. Defaults to /Users/Shared for multi-user accessibility. Only used when use_temp_file=True
use_temp_file (bool, optional) – If True, write JSON config to a temp file instead of passing as string. The temp file is created with world-readable permissions (0o644) for MDM compatibility. Defaults to False
- Example:
>>> dialog = Dialog() >>> template = DialogTemplate(title="Hello", message="World") >>> result = dialog.show(template) >>> if result.ok: ... print("User clicked OK")
- show(template: DialogTemplate | SystemNotification, logger: MdmLogger | None = None, timeout: int | None = None, check_console_user: bool = True) DialogReturn[source]¶
Display the dialog using swiftDialog.
- Parameters:
template (DialogTemplate | SystemNotification) – DialogTemplate or SystemNotification with dialog configuration
logger (MdmLogger | None, optional) – Optional MdmLogger instance for logging, defaults to None
timeout (int | None, optional) – Timeout in seconds for dialog execution, defaults to None
check_console_user (bool, optional) – Whether to check for console user before showing dialog, defaults to True
- Returns:
DialogReturn instance with results
- Return type:
- class DialogTemplate(title: str = '', subtitle: str | None = None, message: str | None = None, style: Style | None = None, alignment: MessageAlignment | None = None, position: MessagePosition | None = None, help_message: str | None = None, help_image: str | Path | None = None, icon: str | Path | None = None, icon_size: int | None = None, icon_alpha: int | None = None, overlay_icon: str | Path | None = None, banner_image: str | Path | None = None, banner_title: str | None = None, banner_text: str | None = None, button1_text: str | None = None, button1_action: str | None = None, button2_text: str | None = None, button2_action: str | None = None, info_button_text: str | None = None, info_button_action: str | None = None, button_style: ButtonStyle | None = None, button_size: ButtonSize | None = None, small: bool = False, big: bool = False, fullscreen: bool = False, ontop: bool = False, moveable: bool = False, width: int | None = None, height: int | None = None, textfields: list[TextField] = <factory>, selectitems: list[SelectItem] = <factory>, radioitems: list[SelectItem] = <factory>, checkboxes: list[CheckboxItem] = <factory>, infobox: str | None = None, timer: int | None = None, timerbar: bool = False, progress: int | None = None, commandfile: str | Path | None = None, json: bool = True, webcontent: str | None = None, video: str | Path | None = None, video_position: str | None = None, quitkey: str | None = None, quit_on_info: bool = False)[source]¶
Template for configuring swiftDialog dialogs.
This dataclass provides a comprehensive interface for defining dialog configurations including text fields, selects, checkboxes, timers, and more. Use the
Dialogclass to display templates.- Parameters:
title (str) – Dialog title (required)
subtitle (str | None, optional) – Optional subtitle text
message (str | None, optional) – Main message content (supports markdown)
style (Style | None)
alignment (MessageAlignment | None)
position (MessagePosition | None)
help_message (str | None)
icon_size (int | None)
icon_alpha (int | None)
banner_title (str | None)
banner_text (str | None)
button1_text (str | None)
button1_action (str | None)
button2_text (str | None)
button2_action (str | None)
info_button_text (str | None)
info_button_action (str | None)
button_style (ButtonStyle | None)
button_size (ButtonSize | None)
small (bool)
big (bool)
fullscreen (bool)
ontop (bool)
moveable (bool)
width (int | None)
height (int | None)
selectitems (list[SelectItem])
radioitems (list[SelectItem])
checkboxes (list[CheckboxItem])
infobox (str | None)
timer (int | None)
timerbar (bool)
progress (int | None)
json (bool)
webcontent (str | None)
video_position (str | None)
quitkey (str | None)
quit_on_info (bool)
- Example:
>>> template = DialogTemplate( ... title="Welcome", ... message="Please enter your details", ... textfields=[TextField(title="Username", required=True)], ... ) >>> dialog = Dialog() >>> result = dialog.show(template)
- selectitems: list[SelectItem]¶
- radioitems: list[SelectItem]¶
- checkboxes: list[CheckboxItem]¶
- to_jsonstring() str[source]¶
Convert DialogTemplate to JSON string for swiftDialog.
- Returns:
JSON string representation
- Return type:
- classmethod from_dict(data: dict[str, Any]) DialogTemplate[source]¶
Create DialogTemplate from a dictionary.
- class DialogReturn(exit_code: int, raw_output: str = '', data: dict[str, ~typing.Any]=<factory>, textfields: dict[str, str]=<factory>, selects: dict[str, ~pymdm.dialog.SelectResult]=<factory>, checkboxes: dict[str, bool]=<factory>)[source]¶
Structured result from a swiftDialog invocation.
- Captures:
exit_code: The process return code (see DialogExitCode)
raw_output: The raw stdout string
data: Parsed JSON dict when –json flag was used
textfields: Dict of textfield label -> user input
selects: Dict of select title -> SelectResult
checkboxes: Dict of checkbox label -> bool
- Parameters:
- selects: dict[str, SelectResult]¶
- get_select(title: str) SelectResult | None[source]¶
Get a select result by title.
- Parameters:
title (str)
- Return type:
SelectResult | None
- classmethod from_subprocess(result: CompletedProcess) DialogReturn[source]¶
Create from a subprocess.CompletedProcess result.
- Parameters:
result (CompletedProcess)
- Return type:
- class DialogExitCode(*values)[source]¶
swiftDialog exit codes.
- ok = 0¶
- button2 = 2¶
- info_button = 3¶
- timer_expired = 4¶
- quit_command = 5¶
- user_quit = 10¶
- timer_zero = 20¶
- auth_failed = 30¶
- image_not_found = 201¶
- file_not_found = 202¶
- invalid_color = 203¶
- class SystemNotification(title: str, message: str | None = None, subtitle: str | None = None, icon: str | Path | None = None, button1_text: str | None = None, button1_action: str | None = None, button2_text: str | None = None, button2_action: str | None = None)[source]¶
Configuration for swiftDialog system notifications (toast).
Unlike full dialogs, notifications only support a limited set of properties. All other DialogTemplate properties are ignored by swiftDialog when –notification is used.
Docs: https://github.com/swiftDialog/swiftDialog/wiki/Notifications
- Parameters:
- class CheckboxItem(label: str, checked: bool = False, disabled: bool = False, icon: str | None = None)[source]¶
Configuration for a checkbox item in swiftDialog.
- Parameters:
- class SelectItem(title: str, values: list[str] = <factory>, default: str | None = None)[source]¶
Configuration for a select/dropdown in swiftDialog.
Each SelectItem represents a single dropdown menu with a label and options.
- Parameters:
- class SelectResult(selected_value: str, selected_index: int)[source]¶
Parsed result from a dropdown/select field.
- class TextField(title: str, prompt: str | None = None, value: str | None = None, secure: bool = False, required: bool = False, regex: str | None = None, regexerror: str | None = None)[source]¶
Configuration for a text field in swiftDialog.
- Parameters:
title (str) – Title/label for the text field (displayed to user)
prompt (str | None, optional) – Prompt text shown inside the field, defaults to None
value (str | None, optional) – Default value, defaults to None
secure (bool, optional) – Whether input should be masked (password field), defaults to False
required (bool, optional) – Whether field is required, defaults to False
regex (str | None, optional) – Validation regex pattern, defaults to None
regexerror (str | None, optional) – Error message to show when regex validation fails, defaults to None