Module GToolbox

Useful functions for LablGTK.

type menu_entry = [
| `I of string * (unit -> unit)
| `C of string * bool * (bool -> unit)
| `R of (string * bool * (bool -> unit)) list
| `M of string * menu_entry list
]

Tree description of a menu

val build_menu : GMenu.menu -> entries:menu_entry list -> unit

Build a menu from a tree description

val popup_menu : entries:menu_entry list -> button:int -> time:int32 -> unit

Popup a menu created from the given list of labels and functions.

Parametrized dialog windows

val question_box : ?⁠parent:GWindow.#window_skel -> title:string -> buttons:string list -> ?⁠default:int -> ?⁠icon:GObj.#widget -> string -> int

This function is used to display a question in a dialog box, with a parametrized list of buttons. The function returns the number of the clicked button (starting at 1), or 0 if the window is savagedly destroyed.

parameter parent

the parent window in the front of which it should be displayed. this also sets the destroy_with_parent property.

parameter title

the title of the dialog

parameter buttons

the list of button labels.

parameter default

the index of the default answer

parameter icon

a widget (usually a pixmap) which can be displayed on the left of the window.

parameter message

the text to display

val message_box : ?⁠parent:GWindow.#window_skel -> title:string -> ?⁠icon:GObj.#widget -> ?⁠ok:string -> string -> unit

This function is used to display a message in a dialog box with just an Ok button. We use question_box with just an ok button.

parameter parent

the parent window in the front of which it should be displayed. this also sets the destroy_with_parent property.

parameter title

the title of the dialog

parameter icon

a widget (usually a pixmap) which can be displayed on the left of the window.

parameter ok

the text for the ok button (default is "Ok")

parameter message

the text to display

val input_string : ?⁠parent:GWindow.#window_skel -> title:string -> ?⁠ok:string -> ?⁠cancel:string -> ?⁠text:string -> string -> string option

Make the user type in a string.

returns

None if the user clicked on cancel, or Some s if the user clicked on the ok button.

parameter parent

the parent window in the front of which it should be displayed. this also sets the destroy_with_parent property.

parameter title

the title of the dialog

parameter ok

the text for the confirmation button (default is "Ok")

parameter cancel

the text for the cancel button (default is "Cancel")

parameter text

the default text displayed in the entry widget

parameter message

the text to display

val input_text : ?⁠parent:GWindow.#window_skel -> title:string -> ?⁠ok:string -> ?⁠cancel:string -> ?⁠text:string -> string -> string option

Make the user type in a text.

returns

None if the user clicked on cancel, or Some s if the user clicked on the ok button.

parameter parent

the parent window in the front of which it should be displayed. this also sets the destroy_with_parent property.

parameter title

the title of the dialog

parameter ok

the text for the confirmation button (default is "Ok")

parameter cancel

the text for the cancel button (default is "Cancel")

parameter text

the default text displayed in the entry widget (utf8)

parameter message

the text to display

type key_combination = [ `A | `C | `S ] list * char

A keyboard shorcut: a combination of Alt, Control and Shift and a letter.

type 'a shortcut_specification = {
name : string;
keys : key_combination list;
message : 'a;
}

A shortcut specification: name of a GTK+ signal to emit, keyboard shortcuts and the message to send. The name must be unique.

val create_shortcuts : window:GWindow.#window_skel -> shortcuts:'a shortcut_specification list -> callback:('a -> unit) -> unit

Setup the given shortcut spec list for the given window and callback. This create the GTK+ signal, associate the keyboard shortcuts to it, make the window listen to these shortcuts and eventually call the given callback with the messages from the shortcut specification.