Next: , Previous: curve, Up: Widgets

6.2.22 dialog

— Class: dialog

Superclass: gtk-window atk-implementor-iface buildable

Subclasses: recent-chooser-dialog message-dialog input-dialog font-selection-dialog file-chooser-dialog color-selection-dialog about-dialog

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 v-box, and is where widgets such as a label or a entry should be packed. The bottom area is known as the dialog-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 h-separator.

If 'dialog' is a newly created dialog, the two primary areas of the window can be accessed through dialog-content-area and dialog-action-area.

A 'modal' dialog (that is, one which freezes the rest of the application from user input), can be created by setting gtk-window-modal (e.g., by specifying :modal t initarg).

If you add buttons to dialog using dialog-add-button, or dialog-add-action-widget, clicking the button will emit a dialog::response signal with a response ID that was 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 response-type enumeration (these all have values less than zero). If a dialog receives a delete event, the dialog::response signal will be emitted with a response ID of :delete-event.

TODO: cl-gtk2 does not yet support specifying custom response IDs.

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

     (defun quick-message (message)
       "Function to open a dialog box display the MESSAGE"
       (let ((dialog (make-instance 'gtk:dialog :title "Message")))
         (gtk:dialog-add-button dialog "gtk-ok" :none)
         (gtk:container-add (gtk:dialog-content-area dialog)
                            (make-instance 'gtk:label :label message))
         (gobject:connect-signal dialog "response"
                                 (lambda (dialog1 response-id)
                                   (declare (ignore dialog1 response-id))
                                   (gtk:object-destroy dialog)))
         (gtk:widget-show dialog)))



— Method: dialog-run
     (dialog-run dialog) => response

Blocks in a recursive main loop until the dialog either emits the dialog::response signal, or is destroyed. If the dialog is destroyed during the call to dialog-run, it returns :none. Otherwise, it returns the response ID from the dialog::response signal emission.

Before entering the recursive main loop, dialog-run calls widget-show on the dialog for you. Note that you still need to show any children of the dialog yourself.

During dialog-run, the default behavior of widget::delete-event is disabled; if the dialog receives widget::delete-event, it will not be destroyed as windows usually are, and dialog-run will return :delete-event. Also, during dialog-run the dialog will be modal. You can force dialog-run to return at any time by calling dialog-response to emit the dialog::response signal. Destroying the dialog during dialog-run is a very bad idea, because your post-run code won't know whether the dialog was destroyed or not.

After dialog-run returns, you are responsible for hiding or destroying the dialog if you wish to do so.

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 dialog-run call.

— Method: dialog-response
     (dialog-response dialog response)

Emits the dialog::response signal with the given response (of type response-type). Used to indicate that the user has responded to the dialog in some way; typically either you or dialog-run will be monitoring the dialog::response signal and take appropriate action.

— Method: dialog-add-button
     (dialog-add-button dialog text response) => button

Adds a button with the given text (or a stock button, if text is a stock ID) and sets things up so that clicking the button will emit the dialog::response signal with the given response. 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.

— Method: dialog-add-action-widget
     (dialog-add-action-widget dialog widget response)

Adds an activatable widget to the action area of a dialog, connecting a signal handler that will emit the 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 dialog-action-area field of the dialog.

— Method: dialog-set-response-sensitive
     (dialog-set-response-sensitive dialog response setting)

Sets the widget-sensitive for each widget in the dialog's action area with the given response. A convenient way to sensitize/desensitize dialog buttons.

— Method: dialog-response-for-widget
     (dialog-response-for-widget dialog widget) => response

Gets the response (of type response-type) of a widget in the action area of a dialog.

— Method: dialog-alternative-button-order-on-screen
     (dialog-alternative-button-order-on-screen screen) => boolean

Returns True if dialogs are expected to use an alternative button order on the screen screen. See dialog-alternative-button-order for more details about alternative button order.

If you need to use this method, you should probably connect to the ::notify:gtk-alternative-button-order signal on the GtkSettings object associated to screen, in order to be notified if the button order setting changes.

screen: a screen or a NIL if to use a default screen.