11.52Class GtkDialog

Create popup windows

Class GtkDialog

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 GtkVBox, and is where widgets such as a GtkLabel or a GtkEntry 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. The two areas are separated by a GtkHSeparator.

GtkDialog boxes are created with their constructor or new_with_buttons(). 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 get_content_area() and 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 set_modal() on the dialog. Use the GTK_WINDOW() macro to cast the widget returned from new() into a GtkWindow. When using new_with_buttons() you can also pass the GTK_DIALOG_MODAL flag to make a dialog modal.

If you add buttons to GtkDialog using new_with_buttons(), add_button(), add_buttons(), or add_action_widget(), clicking the button will emit a signal called "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 the GtkResponseType enumeration (these all have values less than zero). If a dialog receives a delete event, the "response" signal will be emitted with a response ID of GTK_RESPONSE_DELETE_EVENT.

If you want to block waiting for a dialog to return before returning control flow to your code, you can call 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 GtkMessageDialog 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.

[...]

Methods
add_action_widgetAdds an activatable widget to the action area of a GtkDialog, connecting a signal handler that will emit the "response" signal on the dialog when the widget is activated.
add_buttonAdds a button with the given text (or a stock button, if button_text is a stock ID) and sets things up so that clicking the button will emit the "response" signal with the given response_id.
get_action_areaReturns the action area of dialog.
get_content_areaReturns the content area of dialog.
get_has_separatorAccessor for whether the dialog has a separator.
get_response_for_widgetGets the response id of a widget in the action area of a dialog.
get_widget_for_responseGets the widget button that uses the given response ID in the action area of a dialog.
responseEmits the "response" signal with the given response ID.
runTo be completed..
set_default_responseSets the last widget in the dialog's action area with the given response_id as the default widget for the dialog.
set_has_separatorSets whether the dialog has a separator above the buttons. TRUE by default.
set_response_sensitiveCalls gtk_widget_set_sensitive (widget, setting) for each widget in the dialog's action area with the given response_id.

Methods

add_action_widget

Adds an activatable widget to the action area of a GtkDialog, connecting a signal handler that will emit the "response" signal on the dialog when the widget is activated.

GtkDialog.add_action_widget( child, response_id )
child an activatable widget
response_id response ID for child

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 the GtkDialog struct.

add_button

Adds a button with the given text (or a stock button, if button_text is a stock ID) and sets things up so that clicking the button will emit the "response" signal with the given response_id.

GtkDialog.add_button( button_text, response_id )
button_text text of button, or stock ID
response_id response ID for the button
Returnthe button widget that was added (GtkWidget)

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.

get_action_area

Returns the action area of dialog.

GtkDialog.get_action_area()
Returnthe action area.

get_content_area

Returns the content area of dialog.

GtkDialog.get_content_area()
Returnthe content area.

get_has_separator

Accessor for whether the dialog has a separator.

GtkDialog.get_has_separator()
Returntrue if the dialog has a separator.

get_response_for_widget

Gets the response id of a widget in the action area of a dialog.

GtkDialog.get_response_for_widget( widget )
widget a widget in the action area of dialog
Returnthe response id of widget, or GTK_RESPONSE_NONE if widget doesn't have a response id set.

get_widget_for_response

Gets the widget button that uses the given response ID in the action area of a dialog.

GtkDialog.get_widget_for_response( response_id )
response_id the response ID used by the dialog widget
Returnthe widget button that uses the given response_id, or nil.

response

Emits the "response" signal with the given response ID.

GtkDialog.response( response_id )
response_id response ID

Used to indicate that the user has responded to the dialog in some way; typically either you or gtk_dialog_run() will be monitoring the ::response signal and take appropriate action

run

To be completed..

GtkDialog.run()
Returnresponse ID

set_default_response

Sets the last widget in the dialog's action area with the given response_id as the default widget for the dialog.

GtkDialog.set_default_response( response_id )
response_id a response ID

Pressing "Enter" normally activates the default widget.

set_has_separator

Sets whether the dialog has a separator above the buttons. TRUE by default.

GtkDialog.set_has_separator( setting )
setting true to have a separator

set_response_sensitive

Calls gtk_widget_set_sensitive (widget, setting) for each widget in the dialog's action area with the given response_id.

GtkDialog.set_response_sensitive( response_id, setting )
response_id a response ID
setting true for sensitive

A convenient way to sensitize/desensitize dialog buttons.

Made with http://www.falconpl.org