Adw.MessageDialog¶
- Subclasses:
None
Methods¶
- Inherited:
Gtk.Window (62), Gtk.Widget (181), GObject.Object (37), Gtk.Accessible (15), Gtk.Buildable (1), Gtk.Native (6), Gtk.Root (3)
- Structs:
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
Gtk.Window (5), Gtk.Widget (25), GObject.Object (7), Gtk.Accessible (6), Gtk.Buildable (9), Gtk.ShortcutManager (2)
|
Properties¶
- Inherited:
Name |
Type |
Flags |
Short Description |
---|---|---|---|
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
r/w/en |
|||
r/w/en |
Signals¶
- Inherited:
Name |
Short Description |
---|---|
This signal is emitted when the dialog is closed. |
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
---|---|---|---|
parent_instance |
r |
Class Details¶
- class Adw.MessageDialog(*args, **kwargs)¶
- Bases:
- Abstract:
No
- Structure:
A dialog presenting a message or a question.
<picture> <source srcset=”message-dialog-dark.png” media=”(prefers-color-scheme: dark)”> <img src=”message-dialog.png” alt=”message-dialog”> </picture>
Message dialogs have a heading, a body, an optional child widget, and one or multiple responses, each presented as a button.
Each response has a unique string ID, and a button label. Additionally, each response can be enabled or disabled, and can have a suggested or destructive appearance.
When one of the responses is activated, or the dialog is closed, the [signal`MessageDialog`:py:func:::response<Adw.MessageDialog.signals.response>] signal will be emitted. This signal is detailed, and the detail, as well as the
response
parameter will be set to the ID of the activated response, or to the value of the [property`MessageDialog`:py:data::close-response<Adw.MessageDialog.props.close_response>] property if the dialog had been closed without activating any of the responses.Response buttons can be presented horizontally or vertically depending on available space.
When a response is activated,
AdwMessageDialog
is closed automatically.An example of using a message dialog:
```c
Gtk.Widget
*dialog;dialog =
Adw.MessageDialog.new
(parent, _(“Replace File?”),None
);adw_message_dialog_format_body (ADW_MESSAGE_DIALOG (dialog), _(“A file named “%s” already exists. Do you want to replace it?”), filename);
adw_message_dialog_add_responses (ADW_MESSAGE_DIALOG (dialog), “cancel”, _(”_Cancel”), “replace”, _(”_Replace”),
None
);Adw.MessageDialog.set_response_appearance
(ADW_MESSAGE_DIALOG (dialog), “replace”,Adw.ResponseAppearance.DESTRUCTIVE
);Adw.MessageDialog.set_default_response
(ADW_MESSAGE_DIALOG (dialog), “cancel”);Adw.MessageDialog.set_close_response
(ADW_MESSAGE_DIALOG (dialog), “cancel”);g_signal_connect (dialog, “response”, G_CALLBACK (response_cb), self);
Gtk.Window.present
(GTK_WINDOW (dialog)); ```- Async API
AdwMessageDialog
can also be used via the [method`MessageDialog`.choose] method. This API follows the GIO async pattern, and the result can be obtained by calling [method`MessageDialog`.choose_finish], for example:```c static void dialog_cb (
Adw.MessageDialog
*dialog,Gio.AsyncResult
*result, MyWindow *self) { conststr
*response =Adw.MessageDialog.choose_finish
(dialog, result);// … }
static void show_dialog (MyWindow *self) {
Gtk.Widget
*dialog;dialog =
Adw.MessageDialog.new
(GTK_WINDOW (self), _(“Replace File?”),None
);adw_message_dialog_format_body (ADW_MESSAGE_DIALOG (dialog), _(“A file named “%s” already exists. Do you want to replace it?”), filename);
adw_message_dialog_add_responses (ADW_MESSAGE_DIALOG (dialog), “cancel”, _(”_Cancel”), “replace”, _(”_Replace”),
None
);Adw.MessageDialog.set_response_appearance
(ADW_MESSAGE_DIALOG (dialog), “replace”,Adw.ResponseAppearance.DESTRUCTIVE
);Adw.MessageDialog.set_default_response
(ADW_MESSAGE_DIALOG (dialog), “cancel”);Adw.MessageDialog.set_close_response
(ADW_MESSAGE_DIALOG (dialog), “cancel”);Adw.MessageDialog.choose
(ADW_MESSAGE_DIALOG (dialog),None
, (Gio.AsyncReadyCallback
) dialog_cb, self); } ```AdwMessageDialog
supports adding responses in UI definitions by via the<responses>
element that may contain multiple<response>
elements, each respresenting a response.Each of the
<response>
elements must have theid
attribute specifying the response ID. The contents of the element are used as the response label.Response labels can be translated with the usual
translatable
,context
andcomments
attributes.The
<response>
elements can also haveenabled
and/orappearance
attributes. See [method`MessageDialog`.set_response_enabled] and [method`MessageDialog`.set_response_appearance] for details.Example of an
AdwMessageDialog
UI definition:``xml <object class=”AdwMessageDialog” id=”dialog”>
<property name=”heading” translatable=”yes”>Save Changes?</property> <property name=”body” translatable=”yes”>Open documents contain unsaved changes. Changes which are not saved will be permanently lost.</property> <property name=”default-response”>save</property> <property name=”close-response”>cancel</property> <signal name=”response” handler=”response_cb”/> <responses>
<response id=”cancel” translatable=”yes”>_Cancel</response> <response id=”discard” translatable=”yes” appearance=”destructive”>_Discard</response> <response id=”save” translatable=”yes” appearance=”suggested” enabled=”false”>_Save</response>
</responses>
</object> ``
- Accessibility
AdwMessageDialog
uses theGTK_ACCESSIBLE_ROLE_DIALOG
role.New in version 1.2.
- classmethod new(parent, heading, body)¶
- Parameters:
- Returns:
the newly created
AdwMessageDialog
- Return type:
Creates a new
AdwMessageDialog
.heading and body can be set to
NULL
. This can be useful if they need to be formatted or use markup. In that case, set them toNULL
and call [method`MessageDialog`.format_body] or similar methods afterwards:```c
Gtk.Widget
*dialog;dialog =
Adw.MessageDialog.new
(parent, _(“Replace File?”),None
); adw_message_dialog_format_body (ADW_MESSAGE_DIALOG (dialog), _(“A file named “%s” already exists. Do you want to replace it?”), filename); ```New in version 1.2.
- add_response(id, label)¶
-
Adds a response with id and label to self.
Responses are represented as buttons in the dialog.
Response ID must be unique. It will be used in [signal`MessageDialog`:py:func:::response<Adw.MessageDialog.signals.response>] to tell which response had been activated, as well as to inspect and modify the response later.
An embedded underline in label indicates a mnemonic.
[method`MessageDialog`.set_response_label] can be used to change the response label after it had been added.
[method`MessageDialog`.set_response_enabled] and [method`MessageDialog`.set_response_appearance] can be used to customize the responses further.
New in version 1.2.
- choose(cancellable, callback, *user_data)¶
- Parameters:
cancellable (
Gio.Cancellable
orNone
) – aGCancellable
to cancel the operationcallback (
Gio.AsyncReadyCallback
orNone
) – a callback to call when the operation is complete
This function shows self to the user.
The callback will be called when the alert is dismissed. It should call [method`MessageDialog`.choose_finish] to obtain the result.
New in version 1.3.
- choose_finish(result)¶
- Parameters:
result (
Gio.AsyncResult
) – aGAsyncResult
- Returns:
the ID of the response that was selected, or [property`MessageDialog`:py:data::close-response<Adw.MessageDialog.props.close_response>] if the call was cancelled.
- Return type:
Finishes the [method`MessageDialog`.choose] call and returns the response ID.
New in version 1.3.
- get_body()¶
- Returns:
the body of self.
- Return type:
Gets the body text of self.
New in version 1.2.
- get_body_use_markup()¶
- Returns:
whether self uses markup for body text
- Return type:
Gets whether the body text of self includes Pango markup.
New in version 1.2.
- get_close_response()¶
- Returns:
the close response ID
- Return type:
Gets the ID of the close response of self.
New in version 1.2.
- get_default_response()¶
-
Gets the ID of the default response of self.
New in version 1.2.
- get_extra_child()¶
- Returns:
the child widget of self.
- Return type:
Gtk.Widget
orNone
Gets the child widget of self.
New in version 1.2.
- get_heading()¶
-
Gets the heading of self.
New in version 1.2.
- get_heading_use_markup()¶
- Returns:
whether self uses markup for heading
- Return type:
Gets whether the heading of self includes Pango markup.
New in version 1.2.
- get_response_appearance(response)¶
- Parameters:
response (
str
) – a response ID- Returns:
the appearance of response
- Return type:
Gets the appearance of response.
See [method`MessageDialog`.set_response_appearance].
New in version 1.2.
- get_response_enabled(response)¶
-
Gets whether response is enabled.
See [method`MessageDialog`.set_response_enabled].
New in version 1.2.
- get_response_label(response)¶
-
Gets the label of response.
See [method`MessageDialog`.set_response_label].
New in version 1.2.
- has_response(response)¶
- Parameters:
response (
str
) – response ID- Returns:
whether self has a response with the ID response.
- Return type:
Gets whether self has a response with the ID response.
New in version 1.2.
- remove_response(id)¶
- Parameters:
id (
str
) – the response ID
Removes a response from self.
New in version 1.5.
- response(response)¶
- Parameters:
response (
str
) – response ID
Emits the [signal`MessageDialog`:py:func:::response<Adw.MessageDialog.signals.response>] signal with the given response ID.
Used to indicate that the user has responded to the dialog in some way.
New in version 1.2.
- set_body(body)¶
- Parameters:
body (
str
) – the body of self
Sets the body text of self.
New in version 1.2.
- set_body_use_markup(use_markup)¶
- Parameters:
use_markup (
bool
) – whether to use markup for body text
Sets whether the body text of self includes Pango markup.
See [func`Pango`.parse_markup].
New in version 1.2.
- set_close_response(response)¶
- Parameters:
response (
str
) – the close response ID
Sets the ID of the close response of self.
It will be passed to [signal`MessageDialog`:py:func:::response<Adw.MessageDialog.signals.response>] if the window is closed by pressing <kbd>Escape</kbd> or with a system action.
It doesn’t have to correspond to any of the responses in the dialog.
The default close response is
close
.New in version 1.2.
- set_default_response(response)¶
-
Sets the ID of the default response of self.
If set, pressing <kbd>Enter</kbd> will activate the corresponding button.
If set to
NULL
or to a non-existent response ID, pressing <kbd>Enter</kbd> will do nothing.New in version 1.2.
- set_extra_child(child)¶
- Parameters:
child (
Gtk.Widget
orNone
) – the child widget
Sets the child widget of self.
The child widget is displayed below the heading and body.
New in version 1.2.
- set_heading(heading)¶
-
Sets the heading of self.
New in version 1.2.
- set_heading_use_markup(use_markup)¶
- Parameters:
use_markup (
bool
) – whether to use markup for heading
Sets whether the heading of self includes Pango markup.
See [func`Pango`.parse_markup].
New in version 1.2.
- set_response_appearance(response, appearance)¶
- Parameters:
response (
str
) – a response IDappearance (
Adw.ResponseAppearance
) – appearance for response
Sets the appearance for response.
<picture> <source srcset=”message-dialog-appearance-dark.png” media=”(prefers-color-scheme: dark)”> <img src=”message-dialog-appearance.png” alt=”message-dialog-appearance”> </picture>
Use
ADW_RESPONSE_SUGGESTED
to mark important responses such as the affirmative action, like the Save button in the example.Use
ADW_RESPONSE_DESTRUCTIVE
to draw attention to the potentially damaging consequences of using response. This appearance acts as a warning to the user. The Discard button in the example is using this appearance.The default appearance is
ADW_RESPONSE_DEFAULT
.Negative responses like Cancel or Close should use the default appearance.
New in version 1.2.
- set_response_enabled(response, enabled)¶
-
Sets whether response is enabled.
If response is not enabled, the corresponding button will have [property`Gtk`.Widget:sensitive] set to
FALSE
and it can’t be activated as a default response.response can still be used as [property`MessageDialog`:py:data::close-response<Adw.MessageDialog.props.close_response>] while it’s not enabled.
Responses are enabled by default.
New in version 1.2.
- set_response_label(response, label)¶
-
Sets the label of response to label.
Labels are displayed on the dialog buttons. An embedded underline in label indicates a mnemonic.
New in version 1.2.
Signal Details¶
- Adw.MessageDialog.signals.response(message_dialog, response)¶
- Signal Name:
response
- Flags:
- Parameters:
message_dialog (
Adw.MessageDialog
) – The object which received the signalresponse (
str
) – the response ID
This signal is emitted when the dialog is closed.
response will be set to the response ID of the button that had been activated.
if the dialog was closed by pressing <kbd>Escape</kbd> or with a system action, response will be set to the value of [property`MessageDialog`:py:data::close-response<Adw.MessageDialog.props.close_response>].
New in version 1.2.
Property Details¶
- Adw.MessageDialog.props.body¶
- Name:
body
- Type:
- Default Value:
''
- Flags:
The body text of the dialog.
New in version 1.2.
- Adw.MessageDialog.props.body_use_markup¶
- Name:
body-use-markup
- Type:
- Default Value:
- Flags:
Whether the body text includes Pango markup.
See [func`Pango`.parse_markup].
New in version 1.2.
- Adw.MessageDialog.props.close_response¶
- Name:
close-response
- Type:
- Default Value:
'close'
- Flags:
The ID of the close response.
It will be passed to [signal`MessageDialog`:py:func:::response<Adw.MessageDialog.signals.response>] if the window is closed by pressing <kbd>Escape</kbd> or with a system action.
It doesn’t have to correspond to any of the responses in the dialog.
The default close response is
close
.New in version 1.2.
- Adw.MessageDialog.props.default_response¶
- Name:
default-response
- Type:
- Default Value:
- Flags:
The response ID of the default response.
If set, pressing <kbd>Enter</kbd> will activate the corresponding button.
If set to
NULL
or a non-existent response ID, pressing <kbd>Enter</kbd> will do nothing.New in version 1.2.
- Adw.MessageDialog.props.extra_child¶
- Name:
extra-child
- Type:
- Default Value:
- Flags:
The child widget.
Displayed below the heading and body.
New in version 1.2.
- Adw.MessageDialog.props.heading¶
- Name:
heading
- Type:
- Default Value:
''
- Flags:
The heading of the dialog.
New in version 1.2.