Wize /
Inputs
Search:  

1.  Getting Inputs with Wize

Although Tk supplies dialogs for files, colors and arbitrary button options, no dialog is provided for getting arbitrary string input.

Wize defines the builtin getInputs for this purpose. It takes an Opt style list of fields as input and provides auto-layout, tooltips, and validation.

Moreover, it is usable either for standalone dialogs, or embedded into frames.

Here are some screenshots:

Code below demonstrates their use.

2.  getInputs

Gets multiple string inputs. The signature is:

    proc Tk::getInputs {args}

Options for args are:

{ -code      0     "Return code if not OK" }
{ -inputs    {}    "Inputs list each with: name init desc OPTIONS" }
{ -labelopts {}    "Options to apply to each label" }
{ -noinit    False "Do not override values in -var array from -inputs" }
{ -notips    False "Don't show balloon tips, even if using Mod" }
{ -opts      {}    "Options to apply to each entry" }
{ -parent    {}    "Parent window" }
{ -prefix    v:    "Prefix for values in -var array (ie. non-dialog)" }
{ -text      {}    "Text intro at top of inputs" }
{ -title     {}    "Window/frame title" }
{ -var       {}    "Var for results if dialog, else an array" }
{ -window    {}    "Window to use if not a dialog" }

Each element in inputs takes has up to 3 leading positional values: NAME INIT DESCRIPTION. After this may come name/value pairs using the following options:

{ -focus     0   "Inputs index to set as focus" }
{ -labelopts {}  "Options to apply to each label" }
{ -laycmd    {}  "Command for row layout" -type {cmd wl we}}
{ -opts      {}  "Options to apply to each entry" }
{ -type      {}  "Standard Wize type eg. bool int {choice x y z}" }
{ -vcmd      {}  "Command to validate" -type {cmd val}}

2.1  Types

The -type option takes the standard Wize Types. These are used to typecheck values.

All of the following types are recognized:

  • bool
  • int
  • double
  • choice c1 c2 ...
  • match
  • imatch
  • regexp
  • iregexp
  • time
  • date
  • datetime

Note1: A type of int, double, or choice will use a spinbox input. A bool will use a checkbox.

Note2: In the case of choice, a combo-box is available if used with package require Mod. This will also enable tooltips.

2.2  Completion Validation

Two forms of validation are avaliable. The first is completion validation which occurs on submit or when leaving any field which has a -type

2.3  Input Validation

A second form of validation (as the user types) is available via the -vcmd option. See Age2 in the example below.

3.  Example Code


# Dialog #1: A simple login
set inp1 {
    { Login: Admin "User ID"}  
    { Password: {} "Your pass phrase" -focus 1 -opts {-show *} }
}

puts [Tk::getInputs -opts {-bg blue} \
   -labelopts { -bd 2 -relief raised} \
   -title "Login please" -text "Do Login Below" -inputs $inp1]


# Dialog #2: A complex login with validation
set inp 2{
    { User:     ""   "User ID" }
    { Password: ""   "User password" -opts {-bg lightblue -show *}}
    { Local:    y    "Session is local" -type bool }
    { Class:    A    "Class" -type {Choice A B C}}
    { Age:      0    "Your age" -type {Int -min 0 -max 150 } }
    { Age2:     0    "Your age" -vcmd {string is integer -strict}}
    { Zip:      {}   "Zip code" -type {regex {[0-9]{5}}}}
    { Postal:   {}   "Postal code eg. V8Z3P1" -type {regexp {([a-zA-Z][0-9]){3}}} }
}
puts [Wiz::getInputs -text "Login please" -labelopts {-bd 1 -relief raised} -inputs  $inp2]


# Dialog #3: Embedding multiple inputs in frames
toplevel .x
wm title .x "Test Dialog"
Tk::getInputs -window [frame .x.f1] -title "Login please"\
   -var ::xx -prefix v1: -inputs $inp2
Tk::getInputs -window [frame .x.f2] -title "Misc" \
  -text "Fill Login Below" -var ::xx -prefix v2: -inputs $inp1
Tk::getInputs -window [frame .x.f3] -title "Misc2" \
  -text "Fill Login Below" -var ::xx -prefix v3: -inputs $inp1
button .x.b -text Results -command { console show; parray ::xx }
button .x.b2 -text Ok -command { destroy .x }

grid .x.f1 -row 0 -column 0 -rowspan 2 -sticky news
grid .x.f2 -row 0 -column 1 -sticky news
grid .x.f3 -row 1 -column 1 -sticky news
grid .x.b .x.b2 -row 2
grid columnconf .x {0 1} -weight 1
grid rowconf .x {0 1} -weight 1

4.  getInput

getInput is a simpler version of getInputs, that is used to get a single string of input. The signature is:

    proc Tk::getInput {args}

Options for args are:

{ -code      0     "Return code if not OK" }
{ -combo     False "Show as a combobox" }
{ -initial   {}    "Initial value" }
{ -lopts     {}    "Options to set in label" }
{ -parent    {}    "Parent window" }
{ -opts      {}    "Options to set in entry" }
{ -values    {}    "List of values (ie. spinbox)" }
{ -show      {}    "Value to show (eg. * for passwords)" }
{ -text      {}    "Text intro at top of input" }
{ -title     {}    "Window title" }
{ -var       {}    "Var for results" }
{ -window    {}    "Window to use as toplevel" }

© 2008 Peter MacDonald

Page last modified on April 20, 2010, at 03:48 PM