AlertDialog
Added in version 4.10.
Superclasses: Object
A GtkAlertDialog
object collects the arguments that
are needed to present a message to the user.
The message is shown with the choose
function. This API follows the GIO async pattern, and the result can
be obtained by calling choose_finish
.
If you don’t need to wait for a button to be clicked, you can use
show
.
Methods
- class AlertDialog
- choose(parent: Window | None = None, cancellable: Cancellable | None = None, callback: Callable[[...], None] | None = None, *user_data: Any) None
This function shows the alert to the user.
The
callback
will be called when the alert is dismissed. It should callchoose_finish
to obtain the result.It is ok to pass
NULL
for the callback if the alert does not have more than one button. A simpler API for this case isshow
.Added in version 4.10.
- Parameters:
parent – the parent
GtkWindow
cancellable – a
GCancellable
to cancel the operationcallback – a callback to call when the operation is complete
user_data – data to pass to
callback
- choose_finish(result: AsyncResult) int
Finishes the
choose
call and returns the index of the button that was clicked.Added in version 4.10.
- Parameters:
result – a
GAsyncResult
- get_modal() bool
Returns whether the alert blocks interaction with the parent window while it is presented.
Added in version 4.10.
- set_buttons(labels: Sequence[str]) None
Sets the button labels for the alert.
Added in version 4.10.
- Parameters:
labels – the new button labels
- set_cancel_button(button: int) None
Sets the index of the cancel button.
See
cancel_button
for details of how this value is used.Added in version 4.10.
- Parameters:
button – the new cancel button
- set_default_button(button: int) None
Sets the index of the default button.
See
default_button
for details of how this value is used.Added in version 4.10.
- Parameters:
button – the new default button
- set_detail(detail: str) None
Sets the detail text that will be shown in the alert.
Added in version 4.10.
- Parameters:
detail – the new detail text
- set_message(message: str) None
Sets the message that will be shown in the alert.
Added in version 4.10.
- Parameters:
message – the new message
- set_modal(modal: bool) None
Sets whether the alert blocks interaction with the parent window while it is presented.
Added in version 4.10.
- Parameters:
modal – the new value
- show(parent: Window | None = None) None
Show the alert to the user.
This function is a simple version of
choose
intended for dialogs with a single button. If you want to cancel the dialog or if the alert has more than one button, you should use that function instead and provide it with aCancellable
or callback respectively.Added in version 4.10.
- Parameters:
parent – the parent
GtkWindow
Properties
- class AlertDialog
- props.buttons: Sequence[str]
Labels for buttons to show in the alert.
The labels should be translated and may contain a _ to indicate the mnemonic character.
If this property is not set, then a ‘Close’ button is automatically created.
Added in version 4.10.
- props.cancel_button: int
This property determines what happens when the Escape key is pressed while the alert is shown.
If this property holds the index of a button in
buttons
, then pressing Escape is treated as if that button was pressed. If it is -1 or not a valid index for thebuttons
array, then an error is returned.If
buttons
isNULL
, then the automatically created ‘Close’ button is treated as both cancel and default button, so 0 is returned.Added in version 4.10.
- props.default_button: int
This property determines what happens when the Return key is pressed while the alert is shown.
If this property holds the index of a button in
buttons
, then pressing Return is treated as if that button was pressed. If it is -1 or not a valid index for thebuttons
array, then nothing happens.If
buttons
isNULL
, then the automatically created ‘Close’ button is treated as both cancel and default button, so 0 is returned.Added in version 4.10.