1##########################################################################
2# TEPAM - Tcl's Enhanced Procedure and Argument Manager
3##########################################################################
4#
5# 2_argument_dialogbox_introduction.demo: This file is part of the TEPAM demo
6#
7# Copyright (C) 2009, 2010 Andreas Drollinger
8# 
9# RCS: @(#) $Id: 2_argument_dialogbox_introduction.demo,v 1.1 2010/02/11 21:54:38 droll Exp $
10##########################################################################
11# See the file "license.terms" for information on usage and redistribution
12# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
13##########################################################################
14
15#### Initialization ####
16
17DemoControl(Initialization) 1
18DemoControl(IsExecutable) {0}
19
20# TEPAM provides the flexible entry form generator argument_dialogbox. A first 
21# example of this demo shows the simplicity of building composed entry forms with
22# argument_dialogbox. A second example provides an overview of the entry types, 
23# features and options that are available with argument_dialogbox.
24
25   package require Tk
26   package require tepam
27   namespace import -force tepam::*; # Import tepam::procedure and tepam::argument_dialogbox
28
29#### Argument dialogbox - Simple example ####
30
31DemoControl(IsExecutable) {1}
32
33# This first example illustrates the simplicity to create complex data entry 
34# forms. It creates an input mask that allows specifying a file to copy, a 
35# destination folder as well as a checkbox that allows specifying if an 
36# eventual existing file can be overwritten. Comfortable browsers can be used 
37# to select files and directories. And finally, the form offers also the 
38# possibility to accept and decline the selection.
39
40# The argument_dialogbox returns 0 when the entered data are validated and 1 
41# when the data entry is canceled. After the validation of the entered data, the 
42# argument_dialogbox defines all the specified variables with the entered data 
43# inside the calling context.
44
45# A pair of arguments has to be provided to argument_dialogbox for each variable 
46# that has to be specified by this last one. The first argument defines the entry 
47# widget type to use to select the variable's data and the second one is a lists 
48# of attributes related to the variable and the entry widget.
49
50   set Result [tepam::argument_dialogbox \
51      -existingfile {-label "Source file" -variable SourceFile} \
52      -existingdirectory {-label "Destination folder" -variable DestDir} \
53      -checkbutton {-label "Overwrite existing file" -variable Overwrite}]
54
55   if {$Result=="ok"} {
56      puts "Copy $SourceFile to $DestDir"
57      if {$Overwrite} {
58         puts "Overwrite an eventual existing file"
59      }
60   } else {
61      puts "Canceled"
62   }
63
64#### Argument dialogbox - Comprehensive example ####
65
66DemoControl(IsExecutable) {1}
67
68# Many entry widget types are available: Beside the simple generic entries, 
69# there are different kinds of list and combo boxes available, browsers for 
70# existing and new files and directories, check and radio boxes and buttons, as 
71# well as color and font pickers. If necessary, additional entry widget types 
72# can be defined.
73
74# The attribute list contains pairs of attribute names and attribute data. The 
75# primary attribute is -variable used to specify the variable in the calling 
76# context into which the entered data has to be stored. Another often used 
77# attribute is -label that allows adding a label to the data entry widget. Other 
78# attributes are available that allows specifying default values, the expected 
79# data types, valid data ranges, etc.
80
81# The next example of a more complex argument dialog box provides a good overview 
82# about the different available entry widget types and parameter attributes. The 
83# example contains also some formatting instructions like -frame and -sep which 
84# allows organizing the different entry widgets in frames and sections:
85
86   set ChoiceList {"Choice 1" "Choice 2" "Choice 3" "Choice 4" "Choice 5" "Choice 6"}
87 
88   set Result [tepam::argument_dialogbox \
89      -title "System configuration" \
90      -context test_1 \
91      -frame {-label "Entries"} \
92         -entry {-label Entry1 -variable Entry1} \
93         -entry {-label Entry2 -variable Entry2 -default "my default"} \
94      -frame {-label "Listbox & combobox"} \
95         -listbox {-label "Listbox, single selection" -variable Listbox1 \
96                   -choices {1 2 3 4 5 6 7 8} -default 1 -height 3} \
97         -listbox {-label "Listbox, multiple selection" -variable Listbox2 
98                   -choicevariable ChoiceList -default {"Choice 2" "Choice 3"} 
99                   -multiple_selection 1 -height 3} \
100         -disjointlistbox {-label "Disjoined listbox" -variable DisJntListbox 
101                           -choicevariable ChoiceList \
102                           -default {"Choice 3" "Choice 5"} -height 3} \
103         -combobox {-label "Combobox" -variable Combobox \
104                    -choices {1 2 3 4 5 6 7 8} -default 3} \
105      -frame {-label "Checkbox, radiobox and checkbutton"} \
106         -checkbox {-label Checkbox -variable Checkbox 
107                    -choices {bold italic underline} -choicelabels {Bold Italic Underline} \
108                    -default italic} \
109         -radiobox {-label Radiobox -variable Radiobox 
110                    -choices {bold italic underline} -choicelabels {Bold Italic Underline} \
111                    -default underline} \
112         -checkbutton {-label CheckButton -variable Checkbutton -default 1} \
113      -frame {-label "Files & directories"} \
114         -existingfile {-label "Input file" -variable InputFile} \
115         -file {-label "Output file" -variable OutputFile} \
116         -sep {} \
117         -existingdirectory {-label "Input directory" -variable InputDirectory} \
118         -directory {-label "Output irectory" -variable OutputDirectory} \
119      -frame {-label "Colors and fonts"} \
120         -color {-label "Background color" -variable Color -default red} \
121         -sep {} \
122         -font {-label "Font" -variable Font -default {Courier 12 italic}}]
123 
124   if {$Result=="ok"} {
125      puts "Arguments: "
126      foreach Var {
127         Entry1 Entry2
128         Listbox1 Listbox2 Listbox3 
129         Combobox1 Checkbox Radiobox Checkbutton
130         InputFile OutputFile InputDirectory OutputDirectory
131         Color Font
132      } {
133         puts "  $Var: '[set $Var]'"
134      }
135   } else {
136      puts "Canceled"
137   }
138
139##########################################################################
140# $RCSfile: 2_argument_dialogbox_introduction.demo,v $ - ($Name:  $)
141# $Id: 2_argument_dialogbox_introduction.demo,v 1.1 2010/02/11 21:54:38 droll Exp $
142# Modifications:
143# $Log: 2_argument_dialogbox_introduction.demo,v $
144# Revision 1.1  2010/02/11 21:54:38  droll
145# TEPAM module checkin
146#
147##########################################################################
148