juno.dialogs¶
Native UIKit dialogs from Python — alerts, action sheets, date / time pickers, and single-line text input.
All functions are blocking: each call presents a modal dialog and
returns the user’s response. Stop / KeyboardInterrupt is
honoured while a dialog is up — the dialog dismisses and the
script continues at the interrupt point.
Typical usage:
from juno import dialogs
if dialogs.confirm("Delete?", "This cannot be undone.",
destructive=True):
...
name = dialogs.input_alert("Hello", "What's your name?",
placeholder="e.g. Alex")
if name:
print(f"Hi {name}")
choice = dialogs.action_sheet(
"Quality",
buttons=["Low", "Medium", "High", "Cancel"],
cancel=3,
)
when = dialogs.pick_datetime(
title="Reminder",
initial=datetime.datetime.now(),
)
- juno.dialogs.alert(title, message='', buttons=None, *, cancel=None, destructive=None)¶
Present a modal alert with one or more buttons.
- Parameters:
title (str) – Alert title text. May be empty.
message (str) – Secondary message below the title. May be empty.
buttons (list[str] | None) – Button labels in display order. Defaults to
["OK"]when omitted.cancel (int | None) – Index of the cancel button (gets
.cancelstyling — bold). Optional.destructive (int | None) – Index of the destructive button (red text). Optional. Cannot equal
cancel.
- Returns:
The pressed button’s index in
buttons.- Raises:
TypeError – If any argument has the wrong type.
ValueError – If
buttonsis empty, orcancel/destructiveare out of range or collide.DialogsError – If the dialog cannot be presented (no top-most view controller available).
- Return type:
- juno.dialogs.confirm(title, message='', *, ok_text='OK', cancel_text='Cancel', destructive=False)¶
Present a two-button confirmation alert.
- Parameters:
- Returns:
Truewhen OK was pressed,Falsewhen Cancel was pressed.- Raises:
TypeError – If
destructiveis not a realbool(rejects0/1).DialogsError – If the dialog cannot be presented.
- Return type:
- juno.dialogs.input_alert(title, message='', *, initial='', placeholder='', ok_text='OK', cancel_text='Cancel', secure=False)¶
Present an alert with a single-line text input field.
- Parameters:
title (str) – Alert title.
message (str) – Secondary message above the input. May be empty.
initial (str) – Pre-filled text in the field. Empty by default.
placeholder (str) – Grey hint text shown when the field is empty.
ok_text (str) – Label for the OK button.
cancel_text (str) – Label for the Cancel button.
secure (bool) – When True, masks input as a password field.
- Returns:
The entered string when the user tapped OK or pressed the on-screen keyboard’s Return key — including the empty string when the user submitted with no input.
Nonewhen the user tapped Cancel.- Raises:
TypeError – If any string argument is not
strorsecureis not a realbool.DialogsError – If the alert cannot be presented.
- Return type:
str | None
- juno.dialogs.action_sheet(title='', message='', buttons=None, *, cancel=None, destructive=None)¶
Present a UIActionSheet (bottom sheet on iPhone, popover on iPad).
- Parameters:
- Returns:
The pressed button’s index, or
Noneif the user dismissed the sheet without selecting an option (iPad outside-tap, iPhone interactive swipe-down) and nocancelindex was set. Whencancelis set, dismissal without selection returns the cancel index — symmetric with tapping the cancel button explicitly.- Raises:
TypeError – If any argument has the wrong type.
ValueError – If
buttonsis empty or indices are invalid.DialogsError – If the sheet cannot be presented.
- Return type:
int | None
- juno.dialogs.pick_date(*, title='', initial=None, minimum=None, maximum=None)¶
Present a date picker sheet.
- Parameters:
- Returns:
The picked
datetime.date, orNoneif the user cancelled (Cancel button or interactive sheet dismissal).- Raises:
TypeError – If any argument has the wrong type. In particular,
datetime.datetimeis not an accepteddatehere.ValueError – If
minimum > maximumorinitialis outside[minimum, maximum].DialogsError – If the picker cannot be presented.
- Return type:
date | None
- juno.dialogs.pick_time(*, title='', initial=None)¶
Present a time-of-day picker sheet.
Note
UIDatePickerexposes minute granularity. The picker ignoressecondandmicrosecondon the input side (truncated to zero before display) and always returns adatetime.timewithsecond=0andmicrosecond=0.- Parameters:
- Returns:
The picked
datetime.time, orNoneon cancel.- Raises:
TypeError – If
initialis not adatetime.time.DialogsError – If the picker cannot be presented.
- Return type:
time | None
- juno.dialogs.pick_datetime(*, title='', initial=None, minimum=None, maximum=None)¶
Present a combined date + time picker sheet.
Note
Values are interpreted in the device’s current calendar and time zone (local-naive). Aware datetimes are rejected — convert with
dt.replace(tzinfo=None)first. Sub-minute precision is silently truncated; the returned datetime always hassecond=0andmicrosecond=0.- Parameters:
- Returns:
The picked
datetime.datetime, orNoneon cancel.- Raises:
TypeError – If any argument has the wrong type. Plain
datetime.dateis not accepted.ValueError – If
initialis timezone-aware, orminimum > maximum(after truncation), orinitialis outside the bounds.DialogsError – If the picker cannot be presented.
- Return type:
datetime | None