| tepam::argument_dialogbox(3tcl) | Tcl's Enhanced Procedure and Argument Manager | tepam::argument_dialogbox(3tcl) |
tepam::argument_dialogbox - TEPAM argument_dialogbox, reference manual
package require Tcl 8.3
package require Tk 8.3
package require tepam ?0.5?
tepam::argument_dialogbox item_name item_attributes ?item_name item_attributes? ?...?
tepam::argument_dialogbox {item_name item_attributes ?item_name item_attributes? ?...?}
The TEPAM argument_dialogbox is a flexible and easily usable data entry form generator that is available if Tk has been loaded. Each data 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 illustrates how the argument_dialogbox can be employed:
set DialogResult [tepam::argument_dialogbox \
-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 \ -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 attribute:
tepam::argument_dialogbox \ -<argument_name> string \ ...
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 attributes a definition list, which contains itself attribute name and value pairs:
tepam::argument_dialogbox \
...
-<argument_name> {
?-<attribute_name> <attribute_value>?
?-<attribute_name> <attribute_value>?
?...?
}
...
tepam::argument_dialogbox \
...
-frame {-label "Destination address"}
...
tepam::argument_dialogbox \
...
-frame {}
...
tepam::argument_dialogbox \
...
-sep {}
...
tepam::argument_dialogbox \
...
-comment {-text "Specify bellow the destination address"}
...
tepam::argument_dialogbox \ ... -yscroll auto ...
This item group allows specifying global custom checks to validate the entered data.
tepam::argument_dialogbox \
-entry {-label "Your comment" -variable YourCom} \
-validatecommand {IllegalWordDetector $YourCom}
The attribute -validatecommand can be repeated to declare multiple custom checks.
These items corrspond respectively to -validatecommand and -validatecommand_error_text. However, the data validation is not performed in the next upper stack level, but two stack levels higher.
Data entry widgets are created with the widget items. These items require as item attributes a definition list, which contains itself attribute name and value pairs:
tepam::argument_dialogbox \
...
-<argument_name> {
?-<attribute_name> <attribute_value>?
?-<attribute_name> <attribute_value>?
?...?
}
...
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 \
-text {-label Name -variable Text -height 5}
tepam::argument_dialogbox \
-checkbox {-label "Font sytle" -variable FontStyle \
-choices {bold italic underline} -default italic}
tepam::argument_dialogbox \
-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 \
-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 \
-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 \
-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 languages 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 data entry widgets. A paragraph of section Entry Widget Item Attributes explains the widget specific attributes that allow specifying 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 data 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 Tk 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 default 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 size.
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 the 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 \
-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>
}
}
The entry widget procedure has to support 3 mandatory and an optional command that are selected via the argument Command:
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 that is either specified with the -choices or -choicevariable attribute is provided via the Par argument to the entry widget procedure. This list can be used to initialize an available choice list.
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 the one for the basic entry widget:
proc tepam::ad_form(entry) {W Command {Par ""}} {
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 ""}} {
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 namespace ::tepam:
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 array variable contents in a configuration file which is loaded the next time an application is launched.
tepam(3tcl), tepam::procedure(3tcl)
data entry form, parameter entry form
Argument entry form, mega widget
Copyright (c) 2009-2013, Andreas Drollinger
| 0.5.0 | tcllib |