1 Minimum Profit: Creating interactive dialog boxes
2 =================================================
4 This document is a reference to the mp.form() function and associated
5 tools that ease interaction with the user from inside the Minimum Profit
11 Alert boxes are simple popups or message notifications that interrupts the
12 user with a message. Their usage is trivial:
14 mp.alert("It's coffee time!!!");
19 Confirmation boxes are simple forms that show a message and ask for
20 confirmation. The user response is returned as an integer value. Its use
23 local r = mp.confirm("File has changed. Save changes?");
25 The returned values can be 1 if user said _yes_, 2 if user said _no_, and
28 Open and save file boxes
29 ------------------------
31 Open and save file boxes are system-dependent dialog boxes that show a
32 prompt and ask for a filename to open or save into. They both return the
33 file name on confirmation or NULL on cancellation:
35 local r = mp.openfile("File to open:");
37 local s = mp.savefile("Save as:");
42 Forms can be created in MP by using the mp.form() function. It implements a
43 simplified, common interface for GUI and text modes while trying to be as
46 The following is an example taken from mp_search.mpsl:
49 { 'label' => L("Text to seek:"),
51 'history' => 'search' },
52 { 'label' => L("Case sensitive") ~ ':',
54 'value' => mp.config.case_sensitive_search }
57 As can be seen, mp.form() accepts a list of hashes describing the fields
58 to be shown to the user and returns an array with the filled values. On
59 user cancellation, mp.form() return NULL; otherwise, an array with the
60 same number of elements as the array sent as argument is returned, having
61 each entered value in each element.
63 The following _widget_ types exist:
65 * text: A field to enter text.
66 * password: A field to enter text, but hiding its input.
67 * checkbox: A field to enter yes/no values.
68 * list: A field to select an element from a given list of values.
70 Every widget can have some common attributes:
72 * value: The initial value.
73 * label: A text string to be shown near the field, describing it.
75 Other attributes can exist for each widget.
77 Depending on the driver, a dialog box can show `OK' and `Cancel' buttons,
78 and accept cancellation by hitting the `escape' hey.
83 Text widgets are used, unsurprisingly, for entering free text. No limit
84 exist on the string size nor the accepted character set. If a `value'
85 attribute is set, it's shown as the default value, allowing edition.
87 The following additional attributes can be used in text widgets:
89 * history: A tag marking the history set. Every time a dialog is
90 accepted (i.e. not cancelled), the entered value is stored in the
91 history set named by this attribute. History is accesible by pressing
92 the `cursor-up' and `cursor-down' keys.
100 'label' => 'Enter your name:'
106 mp.alert('Your name is ' ~ r[0] ~ '!');
111 Password widgets are the same as text widgets, but its content is not
112 shown. For each character, an asterisk or similar placeholder character is
113 shown. No `history' attributes are allowed.
124 'type' => 'password',
125 'label' => 'Password:'
131 login_into_system(r[0], r[1]);
136 Checkbox widgets are used to set alternatives, i.e., values that can be
137 true or false. Depending on the driver, they are shown as real checkboxes
138 or [Y/N] questions. The initial `value' can be non-zero for _true_ and
139 zero for _false_. On return, the value can be 1 or 0.
145 'label' => 'Tab size:',
149 'type' => 'checkbox',
150 'label' => 'Convert to spaces:',
159 List widgets are used to select one from an array of values. The `value'
160 attribute is the initially selected item from the supplied list.
162 The additional attributes are:
164 * list: The mandatory list of values, as an array of strings.
166 On return, the value is the subscript of the selected item.
174 'label' => 'Which C source file to open:',
175 'list' => glob("*.c"),
179 'type' => 'checkbox',
180 'label' => 'Read only:',
187 Angel Ortega <angel@triptico.com>