Gtk.Dialog¶
- Subclasses:
Gtk.AboutDialog
,Gtk.AppChooserDialog
,Gtk.ColorChooserDialog
,Gtk.ColorSelectionDialog
,Gtk.FileChooserDialog
,Gtk.FontChooserDialog
,Gtk.FontSelectionDialog
,Gtk.MessageDialog
,Gtk.RecentChooserDialog
Methods¶
- Inherited:
Gtk.Window (119), Gtk.Bin (1), Gtk.Container (35), Gtk.Widget (278), GObject.Object (37), Gtk.Buildable (10)
- Structs:
Gtk.ContainerClass (5), Gtk.WidgetClass (12), GObject.ObjectClass (5)
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
Gtk.Window (5), Gtk.Container (10), Gtk.Widget (82), GObject.Object (7), Gtk.Buildable (10)
|
|
|
Properties¶
- Inherited:
Name |
Type |
Flags |
Short Description |
---|---|---|---|
r/w/co |
Use Header Bar for actions. |
Style Properties¶
- Inherited:
Name |
Type |
Default |
Flags |
Short Description |
---|---|---|---|---|
|
|
r |
Width of border around the button area at the bottom of the dialog |
|
|
|
r |
Spacing between buttons |
|
|
|
r |
Width of border around the main dialog area |
|
|
|
r |
Spacing between elements of the main dialog area |
Signals¶
- Inherited:
Gtk.Window (5), Gtk.Container (4), Gtk.Widget (69), GObject.Object (1)
Name |
Short Description |
---|---|
The |
|
Emitted when an action widget is clicked, the dialog receives a delete event, or the application programmer calls |
Fields¶
- Inherited:
Gtk.Window (5), Gtk.Container (4), Gtk.Widget (69), GObject.Object (1)
Name |
Type |
Access |
Description |
---|---|---|---|
window |
r |
Class Details¶
- class Gtk.Dialog(*args, **kwargs)¶
- Bases:
- Abstract:
No
- Structure:
Dialog boxes are a convenient way to prompt the user for a small amount of input, e.g. to display a message, ask a question, or anything else that does not require extensive effort on the user’s part.
GTK+ treats a dialog as a window split vertically. The top section is a
Gtk.VBox
, and is where widgets such as aGtk.Label
or aGtk.Entry
should be packed. The bottom area is known as the “action area”. This is generally used for packing buttons into the dialog which may perform functions such as cancel, ok, or apply.Gtk.Dialog
boxes are created with a call toGtk.Dialog.new
() or gtk_dialog_new_with_buttons(). gtk_dialog_new_with_buttons() is recommended; it allows you to set the dialog title, some convenient flags, and add simple buttons.If “dialog” is a newly created dialog, the two primary areas of the window can be accessed through
Gtk.Dialog.get_content_area
() andGtk.Dialog.get_action_area
(), as can be seen from the example below.A “modal” dialog (that is, one which freezes the rest of the application from user input), can be created by calling
Gtk.Window.set_modal
() on the dialog. Use the GTK_WINDOW() macro to cast the widget returned fromGtk.Dialog.new
() into aGtk.Window
. When using gtk_dialog_new_with_buttons() you can also pass theGtk.DialogFlags.MODAL
flag to make a dialog modal.If you add buttons to
Gtk.Dialog
using gtk_dialog_new_with_buttons(),Gtk.Dialog.add_button
(),Gtk.Dialog.add_buttons
(), orGtk.Dialog.add_action_widget
(), clicking the button will emit a signal calledGtk.Dialog
::response
with a response ID that you specified. GTK+ will never assign a meaning to positive response IDs; these are entirely user-defined. But for convenience, you can use the response IDs in theGtk.ResponseType
enumeration (these all have values less than zero). If a dialog receives a delete event, theGtk.Dialog
::response
signal will be emitted with a response ID ofGtk.ResponseType.DELETE_EVENT
.If you want to block waiting for a dialog to return before returning control flow to your code, you can call
Gtk.Dialog.run
(). This function enters a recursive main loop and waits for the user to respond to the dialog, returning the response ID corresponding to the button the user clicked.For the simple dialog in the following example, in reality you’d probably use
Gtk.MessageDialog
to save yourself some effort. But you’d need to create the dialog contents manually if you had more than a simple message in the dialog.An example for simple
Gtk.Dialog
usage:// Function to open a dialog box with a message void quick_message (GtkWindow *parent, gchar *message) { GtkWidget *dialog, *label, *content_area; GtkDialogFlags flags; // Create the widgets flags = GTK_DIALOG_DESTROY_WITH_PARENT; dialog = gtk_dialog_new_with_buttons ("Message", parent, flags, _("_OK"), GTK_RESPONSE_NONE, NULL); content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog)); label = gtk_label_new (message); // Ensure that the dialog box is destroyed when the user responds g_signal_connect_swapped (dialog, "response", G_CALLBACK (gtk_widget_destroy), dialog); // Add the label, and show everything we’ve added gtk_container_add (GTK_CONTAINER (content_area), label); gtk_widget_show_all (dialog); }
The
Gtk.Dialog
implementation of theGtk.Buildable
interface exposes the vbox and action_area as internal children with the names “vbox” and “action_area”.Gtk.Dialog
supports a custom<action-widgets>
element, which can contain multiple<action-widget>
elements. The “response” attribute specifies a numeric response, and the content of the element is the id of widget (which should be a child of the dialogs action_area). To mark a response as default, set the “default“ attribute of the<action-widget>
element to true.Gtk.Dialog
supports adding action widgets by specifying “action“ as the “type“ attribute of a<child>
element. The widget will be added either to the action area or the headerbar of the dialog, depending on the “use-header-bar“ property. The response id has to be associated with the action widget using the<action-widgets>
element.An example of a
Gtk.Dialog
UI definition fragment:<object class="GtkDialog" id="dialog1"> <child type="action"> <object class="GtkButton" id="button_cancel"/> </child> <child type="action"> <object class="GtkButton" id="button_ok"> <property name="can-default">True</property> </object> </child> <action-widgets> <action-widget response="cancel">button_cancel</action-widget> <action-widget response="ok" default="true">button_ok</action-widget> </action-widgets> </object>
- classmethod new()[source]¶
- Returns:
the new dialog as a
Gtk.Widget
- Return type:
Creates a new dialog box.
Widgets should not be packed into this
Gtk.Window
directly, but into the vbox and action_area, as described above.
- add_action_widget(child, response_id)[source]¶
- Parameters:
child (
Gtk.Widget
) – an activatable widgetresponse_id (
int
) – response ID for child
Adds an activatable widget to the action area of a
Gtk.Dialog
, connecting a signal handler that will emit theGtk.Dialog
::response
signal on the dialog when the widget is activated. The widget is appended to the end of the dialog’s action area. If you want to add a non-activatable widget, simply pack it into the action_area field of theGtk.Dialog
struct.
- add_button(button_text, response_id)[source]¶
- Parameters:
- Returns:
the
Gtk.Button
widget that was added- Return type:
Adds a button with the given text and sets things up so that clicking the button will emit the
Gtk.Dialog
::response
signal with the given response_id. The button is appended to the end of the dialog’s action area. The button widget is returned, but usually you don’t need it.
- add_buttons(*args)[source]¶
The add_buttons() method adds several buttons to the Gtk.Dialog using the button data passed as arguments to the method. This method is the same as calling the Gtk.Dialog.add_button() repeatedly. The button data pairs - button text (or stock ID) and a response ID integer are passed individually. For example:
dialog.add_buttons(Gtk.STOCK_OPEN, 42, "Close", Gtk.ResponseType.CLOSE)
will add “Open” and “Close” buttons to dialog.
- get_action_area()[source]¶
- Returns:
the action area
- Return type:
Returns the action area of self.
New in version 2.14.
Deprecated since version 3.12: Direct access to the action area is discouraged; use
Gtk.Dialog.add_button
(), etc.
- get_header_bar()[source]¶
- Returns:
the header bar
- Return type:
Returns the header bar of self. Note that the headerbar is only used by the dialog if the
Gtk.Dialog
:use-header-bar
property isTrue
.New in version 3.12.
- get_response_for_widget(widget)[source]¶
- Parameters:
widget (
Gtk.Widget
) – a widget in the action area of self- Returns:
the response id of widget, or
Gtk.ResponseType.NONE
if widget doesn’t have a response id set.- Return type:
Gets the response id of a widget in the action area of a dialog.
New in version 2.8.
- get_widget_for_response(response_id)[source]¶
- Parameters:
response_id (
int
) – the response ID used by the self widget- Returns:
the widget button that uses the given response_id, or
None
.- Return type:
Gtk.Widget
orNone
Gets the widget button that uses the given response ID in the action area of a dialog.
New in version 2.20.
- response(response_id)[source]¶
- Parameters:
response_id (
int
) – response ID
Emits the
Gtk.Dialog
::response
signal with the given response ID. Used to indicate that the user has responded to the dialog in some way; typically either you orGtk.Dialog.run
() will be monitoring the::response
signal and take appropriate action.
- run()[source]¶
- Returns:
response ID
- Return type:
Blocks in a recursive main loop until the self either emits the
Gtk.Dialog
::response
signal, or is destroyed. If the dialog is destroyed during the call toGtk.Dialog.run
(),Gtk.Dialog.run
() returnsGtk.ResponseType.NONE
. Otherwise, it returns the response ID from the::response
signal emission.Before entering the recursive main loop,
Gtk.Dialog.run
() callsGtk.Widget.show
() on the dialog for you. Note that you still need to show any children of the dialog yourself.During
Gtk.Dialog.run
(), the default behavior ofGtk.Widget
::delete-event
is disabled; if the dialog receives ::delete_event, it will not be destroyed as windows usually are, andGtk.Dialog.run
() will returnGtk.ResponseType.DELETE_EVENT
. Also, duringGtk.Dialog.run
() the dialog will be modal. You can forceGtk.Dialog.run
() to return at any time by callingGtk.Dialog.response
() to emit the::response
signal. Destroying the dialog duringGtk.Dialog.run
() is a very bad idea, because your post-run code won’t know whether the dialog was destroyed or not.After
Gtk.Dialog.run
() returns, you are responsible for hiding or destroying the dialog if you wish to do so.Typical usage of this function might be:
GtkWidget *dialog = gtk_dialog_new (); // Set up dialog... int result = gtk_dialog_run (GTK_DIALOG (dialog)); switch (result) { case GTK_RESPONSE_ACCEPT: // do_application_specific_something (); break; default: // do_nothing_since_dialog_was_cancelled (); break; } gtk_widget_destroy (dialog);
Note that even though the recursive main loop gives the effect of a modal dialog (it prevents the user from interacting with other windows in the same window group while the dialog is run), callbacks such as timeouts, IO channel watches, DND drops, etc, will be triggered during a
Gtk.Dialog.run
() call.
- set_alternative_button_order_from_array(new_order)[source]¶
- Parameters:
new_order ([
int
]) – an array of response ids of self’s buttons
Sets an alternative button order. If the
Gtk.Settings
:gtk-alternative-button-order
setting is set toTrue
, the dialog buttons are reordered according to the order of the response ids in new_order.See gtk_dialog_set_alternative_button_order() for more information.
This function is for use by language bindings.
New in version 2.6.
Deprecated since version 3.10: Deprecated
- set_default_response(response_id)[source]¶
- Parameters:
response_id (
int
) – a response ID
Sets the last widget in the dialog’s action area with the given response_id as the default widget for the dialog. Pressing “Enter” normally activates the default widget.
- set_response_sensitive(response_id, setting)[source]¶
-
Calls
gtk_widget_set_sensitive (widget, @setting)
for each widget in the dialog’s action area with the given response_id. A convenient way to sensitize/desensitize dialog buttons.
- do_close() virtual¶
Signal emitted when the user uses a keybinding to close the dialog.
- do_response(response_id) virtual¶
- Parameters:
response_id (
int
) – response ID
Emits the
Gtk.Dialog
::response
signal with the given response ID. Used to indicate that the user has responded to the dialog in some way; typically either you orGtk.Dialog.run
() will be monitoring the::response
signal and take appropriate action.
Signal Details¶
- Gtk.Dialog.signals.close(dialog)¶
- Signal Name:
close
- Flags:
- Parameters:
dialog (
Gtk.Dialog
) – The object which received the signal
The
::close
signal is akeybinding signal
which gets emitted when the user uses a keybinding to close the dialog.The default binding for this signal is the Escape key.
- Gtk.Dialog.signals.response(dialog, response_id)¶
- Signal Name:
response
- Flags:
- Parameters:
dialog (
Gtk.Dialog
) – The object which received the signalresponse_id (
int
) – the response ID
Emitted when an action widget is clicked, the dialog receives a delete event, or the application programmer calls
Gtk.Dialog.response
(). On a delete event, the response ID isGtk.ResponseType.DELETE_EVENT
. Otherwise, it depends on which action widget was clicked.
Property Details¶
- Gtk.Dialog.props.use_header_bar¶
- Name:
use-header-bar
- Type:
- Default Value:
-1
- Flags:
True
if the dialog uses aGtk.HeaderBar
for action buttons instead of the action-area.For technical reasons, this property is declared as an integer property, but you should only set it to
True
orFalse
.New in version 3.12.