Dialog widgets

The Dialog widget is very simple, and is actually just a window with a few things pre-packed into it for you.

It simply creates a window, and then packs a vbox into the top, which contains a separator and then an hbox called the “action_area”. After creating a dialog, you can reference the vbox and the action_area using the following methods:

method vbox : GPack.box
method action_area : GPack.button_box

The Dialog widget can be used for pop-up messages to the user, and other similar tasks. GWindow.dialog is the function which creates a new Dialog.

val GWindow.dialog:
	?no_separator:bool ->
	?parent:#window_skel ->
	?destroy_with_parent:bool ->
	?title:string ->
	?allow_grow:bool ->
	?allow_shrink:bool ->
	?icon:GdkPixbuf.pixbuf ->
	?modal:bool ->
	?resizable:bool ->
	?screen:Gdk.screen ->
	?type_hint:Gdk.Tags.window_type_hint ->
	?position:Gtk.Tags.window_position ->
	?wm_name:string ->
	?wm_class:string ->
	?border_width:int ->
	?width:int ->
	?height:int ->
	?show:bool -> unit -> [> `DELETE_EVENT ] dialog

no_separator : default value is false
destroy_with_parent : default value is false

This function will create an empty dialog, and it is now up to you to use it. You could pack a button in the action_area by doing something like this:

let w = GWindow.dialog ... () in
let button = GButton.button ... ~packing:w#action_area#add () in

And you could add to the vbox area by packing, for instance, a label in it, try something like this:

let w = GWindow.dialog ... () in
let label = GMisc.label ~text:"Dialogs are groovy" ~packing:w#vbox#add () in

As an example in using the dialog box, you could put two buttons in the action_area, a Cancel button and an Ok button, and a label in the vbox area, asking the user a question or giving an error etc. Then you could attach a different signal to each of the buttons and perform the operation the user selects.

If the simple functionality provided by the default vertical and horizontal boxes in the two areas doesn’t give you enough control for your application, then you can simply pack another layout widget into the boxes provided. For example, you could pack a table into the vertical box.

The optional arguments allows to set one or more of the following flags.

  • ?modal: make the dialog modal.

  • ?destroy_with_parent: ensures that the dialog window is destroyed together with the parent.

  • ?no_separator: omits the separator between the vbox and the action_area.

comments powered by Disqus