tepam::argument_dialogbox(n) | Tcl�s Enhanced Procedure and Argument Manager | tepam::argument_dialogbox(n) |
tepam::argument_dialogbox - TEPAM argument_dialogbox, reference manual
package require Tcl 8.3
package require Tk 8.3
package require tepam ?0.1?
tepam::argument_dialogbox item_name item_attributes ?item_name item_attributes? ?...?
tepam::argument_dialogbox {item_name item_attributes ?item_name item_attributes? ?...?}
TEPAM's argument_dialogbox is a flexible and easily usable entry form generator. Each entry element of a form is defined via a data entry item that can be provided to argument_dialogbox in two formats:
The argument_dialogbox returns ok if the entered data have been acknowledged (via the OK button) and validated by a data checker. If the entered data have been rejected (via the Cancel button) the argument_dialogbox returns cancel.
A small example is the simplest way to illustrate how the argument_dialogbox can be employed:
set DialogResult [tepam::argument_dialogbox \This example opens a dialog box that has the title Itinerary selection. A first entry element in this box allows selecting a report file. It follows two frames to define respectively an itinerary start and end location. Each of these locations, that is described with a comment, has three entry elements to specify respectively the city, street and the street number. Bellow the second frame there is a checkbutton that allows specifying if eventual highways should be ignored.
-title "Itinerary selection" \
-file {-label "Itinerary report" -variable report_file} \
-frame {-label "Itinerary start"} \
-comment {-text "Specify your itinerary start location"} \
-entry {-label "City" -variable start_city -type string} \
-entry {-label "Street" -variable start_street -type string -optional 1} \
-entry {-label "Street number" -variable start_street_nbr -type integer -optional 1} \
-frame {-label "Itinerary destination"} \
-comment {-text "Specify your itinerary destination"} \
-entry {-label "City" -variable dest_city -type string} \
-entry {-label "Street" -variable dest_street -type string -optional 1} \
-entry {-label "Street number" -variable dest_street_nbr -type integer -optional 1} \
-frame {} \
-checkbutton {-label "Don't use highways" -variable no_highway}]
set DialogResult [tepam::argument_dialogbox {
-title "Itinerary selection"
-file {-label "Itinerary report" -variable report_file}
...
-checkbutton {-label "Don't use highways" -variable no_highway} }]
The commands argument_dialogbox as well as procedure are exported from the namespace tepam. To use these commands without the tepam:: namespace prefix, it is sufficient to import them into the main namespace:
namespace import tepam::* set DialogResult [argument_dialogbox \The following subsections explain the different items that are accepted by the argument_dialogbox, classified into three groups. The first data entry item definition format will be used in the remaining document, knowing that this format can always be transformed into the second format by putting all arguments into a single list that is then provided to argument_dialogbox.
-title "Itinerary selection"
...
The first item group allows specifying some context aspects of an argument dialog box. These items are taking a simple character string as item data:
tepam::argument_dialogbox \
-<argument_name> string \
...
The following items are classified into this group:
tepam::argument_dialogbox \
-title "System configuration" \
...
tepam::argument_dialogbox \
-window .dialog \
...
tepam::argument_dialogbox \
-parent .my_appl \
...
tepam::argument_dialogbox \
-context destination_definitions \
...
Especially for big, complex forms it becomes important that the different data entry widgets are graphically well organized and commented to provide an immediate and clear overview to the user. A couple of items allow structuring and commenting the dialog boxes.
The items of this classification group require as item data an attribute definition list. The attribute definition list contains itself attribute name and data pairs:
tepam::argument_dialogbox \The following items are classified into this group:
...
-<argument_name> {
?-<attribute_name> <attribute_data>?
?-<attribute_name> <attribute_data>?
?...?
}
...
tepam::argument_dialogbox \
...
-frame {-label "Destination address"}
...
To close an open frame without opening a new one, an empty list has to be provided to the -frame statement.
tepam::argument_dialogbox \
...
-frame {}
...
tepam::argument_dialogbox \
...
-sep {}
...
tepam::argument_dialogbox \
...
-comment {-text "Specify bellow the destination address"}
...
Data entry widgets are created with the widget items. These items require as the formatting items an attribute definition list as item data:
tepam::argument_dialogbox \
...
-<argument_name> {
?-<attribute_name> <attribute_data>?
?-<attribute_name> <attribute_data>?
?...?
}
...
The attribute list can contain various attributes to describe and comment an entry widget and to constrain its entered data. All entry widgets are accepting a common set of attributes that are described in the section Entry Widget Item Attributes.
TEPAM defines a rich set of entry widgets. If necessary, this set can be extended with additional application specific entry widgets (see APPLICATION SPECIFIC ENTRY WIDGETS):
tepam::argument_dialogbox \
-entry {-label Name -variable Entry}
tepam::argument_dialogbox \If the check boxes' texts should differ from the option values, they can be defined with the -choicelabels attribute:
-checkbox {-label "Font sytle" -variable FontStyle \
-choices {bold italic underline} -default italic}
tepam::argument_dialogbox \In contrast to a radio box group, a check box group allows selecting simultaneously several choice options. The selection is stored for this reason inside the defined variable in form of a list, even if only one choice option has been selected.
-checkbox {-label "Font sytle" -variable FontStyle \
-choices {bold italic underline} \
-choicelabels {Bold Italic Underline} \
-default italic}
In contrast to a check box group, a radio box group allows selecting simultaneously only one choice option. The selected option value is stored directly, and not in form of a list, inside the defined variable.
tepam::argument_dialogbox \If the radio boxes' texts should differ from the option values, they can be defined with the -choicelabels attribute:
-radiobox {-label "Text adjustment" -variable Adjustment \
-choices {left center right} -default left}
tepam::argument_dialogbox \
-radiobox {-label "Text adjustment" -variable Adjustment \
-choices {left center right} \
-choicelabels {Left Center Right} -default left}
tepam::argument_dialogbox \
-checkbutton {-label Capitalize -variable Capitalize -default 1}
Several types of list and combo boxes are available to handle selection lists.
tepam::argument_dialogbox \And here is an example of using a variable to define the selection list:
-combobox {-label "Text size" -variable Size -choices {8 9 10 12 15 18} -default 12}
set TextSizes {8 9 10 12 15 18} tepam::argument_dialogbox \
-combobox {-label "Text size" -variable Size -choicevariable TextSizes -default 12}
set set AvailableSizes for {set k 0} {$k<16} {incr k} {lappend AvailableSizes [expr 1<<$k]} tepam::argument_dialogbox \Here is a multi element selection example. Please note that also the default selection can contain multiple elements:
-listbox {-label "Distance" -variable Distance \
-choicevariable AvailableSizes -default 6 -height 5}
tepam::argument_dialogbox \
-listbox {-label "Text styles" -variable Styles \
-choices {bold italic underline overstrike} \
-choicelabels {Bold Italic Underline Overstrike} \
-default {bold underline} -multiple_selection 1 \
-height 3}
Disjoint listboxes allow always selecting multiple elements. With the exception of the -multiple_selection attribute, disjointed list boxes are accepting the same attributes as the normal listbox, e.g. -height, -choices, -choicevariable, -default.
tepam::argument_dialogbox \
-disjointlistbox {-label "Preferred scripting languages" -variable Languages \
-comment "Please select your preferred languanges in the order" \
-choices {JavaScript Lisp Lua Octave PHP Perl Python Ruby Scheme Tcl} \
-default {Tcl Perl Python}}
The file and directory selectors are building a next group of entry widgets. A paragraph of section Entry Widget Item Attributes explains the dedicated attributes of these widgets to specify the targeted file types, active directory etc.
tepam::argument_dialogbox \
-file {-label "Image file" -variable ImageF \
-filetypes {{"GIF" {*.gif}} {"JPG" {*.jpg}}} \
-initialfile "picture.gif"}
tepam::argument_dialogbox \
-existingfile {-label "Image file" -variable ImageF \
-filetypes {{"GIF" {*.gif}} {"JPG" {*.jpg}}} \
-initialfile "picture.gif"}
tepam::argument_dialogbox \
-directory {-label "Report directory" -variable ReportDir}
tepam::argument_dialogbox \
-existingdirectory {-label "Report directory" -variable ReportDir}
Finally, there is a last group of some other special entry widgets.
tepam::argument_dialogbox \
-color {-label "Background color" -variable Color -default red}
The font browser allows selecting by default the font families provided by the font families command as well as a reasonable set of different font sizes between 6 points and 40 points. Different sets of font families and font sizes can be specified respectively via the -font_families or -font_sizes attributes.
If no default font is provided via the -default attribute, the font of the label widget to display the selected font will be used as default selected font. If the font family of this label widget is not part of the available families the first available family is used as default. If the font size of this label widget is not part of the available sizes the next close available size is selected as default.
tepam::argument_dialogbox \
-font {-label "Font" -variable Font \
-font_sizes {8 10 12 16} \
-default {Arial 20 italic}}
All the entry widget items are accepting the following attributes:
tepam::argument_dialogbox \
-entry {-text "Please enter your name bellow" -variable Name}
tepam::argument_dialogbox \
-entry {-label Name -variable Name}
tepam::argument_dialogbox \
-existingdirectory {-label "Report directory" -variable ReportDir}
tepam::argument_dialogbox \
-checkbox {-label "Font sytle" -variable FontStyle \
-choices {bold italic underline} -default italic}
In case an entry is optional and no data has been entered, e.g. the entry contains an empty character string, the entry will be considered as undefined and the assigned variable will not be defined.
tepam::argument_dialogbox \
-entry {-label "City" -variable start_city -type string} \
-entry {-label "Street" -variable start_street -type string -optional 0} \
-entry {-label "Street number" -variable start_street_nbr -type integer -optional 1} \
The argument dialog box accepts all types that have been specified by the TEPAM package and that are also used by tepam::procedure (see the tepam::procedure reference manual).
Some entry widgets like the file and directory widgets, as well as the color and font widgets are specifying automatically a default data type if no type has been specified explicitly with the -type attribute.
tepam::argument_dialogbox \
-entry {-label "Street number" -variable start_street_nbr -type integer} \
The -range attribute has to be used only for numerical arguments, like integers and doubles.
tepam::argument_dialogbox \
-entry {-label Month -variable Month -type integer -range {1 12}}
tepam::argument_dialogbox \
-entry {-label "Your comment" -variable YourCom \
-validatecommand "IllegalWordDetector %P"} ]
Some other attributes are supported by the list and combo boxes as well as by the radio and check buttons.
tepam::argument_dialogbox \
-listbox {-label "Text styles" -variable Styles \
-choices {bold italic underline} -default underline
tepam::argument_dialogbox \
-checkbox {-label "Font sytle" -variable FontStyle \
-choices {bold italic underline} \
-choicelabels {Bold Italic Underline}
set TextSizes {8 9 10 12 15 18} tepam::argument_dialogbox \
-combobox {-label "Text size" -variable Size -choicevariable TextSizes}
tepam::argument_dialogbox \
-listbox {-label "Text styles" -variable Styles \
-choices {bold italic underline} -default underline \
-multiple_selection 1 -height 3}
Some additional attributes are supported by the file and directory selection widgets.
tepam::argument_dialogbox \
-file {-label "Image file" -variable ImageF \
-filetypes {{"GIF" {*.gif}} {"JPG" {*.jpg}}}}
tepam::argument_dialogbox \
-file {-variable ImageF -initialfile "picture.gif"}
tepam::argument_dialogbox \
-file "-variable ImageF -activedir $pwd"
Finally, there is a last attribute supported by some widgets:
tepam::argument_dialogbox \If the no height has been explicitly specified the height of the widget will be adapted to the argument dialog box' size.
-listbox {-label "Text size" -variable Size \
-choices {8 9 10 12 15 18} -default 12 -height 3}
An application specific entry widget can be made available to the argument dialog box by adding a dedicated procedure to the tepam namespace. This procedure has three arguments; the first one is the widget path, the second one a subcommand and the third argument has various purposes:
proc tepam::ad_form(<WidgetName>) {W Command {Par ""}} {
upvar Option Option; # if required
variable argument_dialogbox; # if required
switch $Command {
"create" <CreateCommandSequence>
"set_choice" <SetChoiceCommandSequence>
"set" <SetCommandv>
"get" <GetCommandSequence>
} }
Argument_dialogbox takes care about the -label and -text attributes for all entry widgets. For the entry widget it creates a frame into which the entry widget components can be placed. The path to this frame is provided via the W argument. The entry widget procedure has to support 3 mandatory and an optional command, defined via the Command argument:
The frames that are made available by argument_dialogbox for the entry widgets are by default only extendable in the X direction. To make them also extendable in the Y direction, for example for extendable list boxes, the command ad_form(make_expandable) $W has to be executed when an entry widget is built.
The available selection list, either specified with the -choices or -choicevariable attribute is provided via the Par argument to the entry widget procedure which can initialize the selection list with this data.
Eventually specified entry widget item attributes are available via the Option array variable of the calling procedure. This variable becomes accessible inside the entry widget procedure via the upvar command.
There may be a need to store some information in a variable. The array variable argument_dialogbox has to be used for this purpose together with array indexes starting with "$W,", e.g. argument_dialogbox($W,values).
Examples of entry widget procedures are directly provided by the TEPAM package source file that specifies the standard entry widget procedures. The simplest procedure is certainly the one for the basic entry widget:
proc tepam::ad_form(entry) {W Command {Par ""}} {It is also possible to relay on an existing entry widget procedure to create a new, more specific one. The radiobox widget is used for example, to create a new entry widget that allows selecting either the option left, center or right. The original radiobox widget is called with the set_choice command immediately after the create command, to define the fixed list of selection options.
switch $Command {
"create" {pack [entry \$W.entry] -fill x \
-expand yes -pady 4 -side left}
"set" {\$W.entry insert 0 $Par}
"get" {return [\$W.entry get]}
} }
proc tepam::ad_form(rcl) {W Command {Par ""}} {Please consult the TEPAM package source file to find additional and more complex examples of entry widget procedures.
set Res [ad_form(radiobox) $W $Command $Par]
if {$Command=="create"} {
ad_form(radiobox) $W set_choice {left center right}
}
return $Res }
The argument_dialogbox is using two variables inside the ::tepam namespace:
To reuse the saved parameters not just in the actual application session but also in another one, it is sufficient to store the last_parameter variable array in a configuration file which is loaded the next time an application is launched.
tepam_introduction(n), tepam_procedure(n)
entry mask, parameter entry form
Argument entry form, mega widget
Copyright (c) 2009/2010, Andreas Drollinger
0.1.0 | tepam |