1 | # This program is under CECILL_B licence. See footer for details. |
---|
2 | |
---|
3 | # create a choice dialog |
---|
4 | |
---|
5 | proc choice_create { args } { |
---|
6 | |
---|
7 | set mandatory_arguments { path_father address } |
---|
8 | initWidget |
---|
9 | |
---|
10 | |
---|
11 | ttk::frame $win |
---|
12 | eval $widgetInfo(packme-$win) |
---|
13 | |
---|
14 | smartpacker_setup_label $win $address |
---|
15 | smartpacker_setup_status $win $address |
---|
16 | set widgetInfo($address-status) 1 |
---|
17 | |
---|
18 | set widgetInfo($address-mode) "standard" |
---|
19 | set widgetInfo($address-valuelist) "" |
---|
20 | set widgetInfo($address-titlelist) "" |
---|
21 | |
---|
22 | |
---|
23 | |
---|
24 | if {[dTree_attrExists $XMLtree $full_address_XML_clean "source"]} { |
---|
25 | set source "root [dTree_getAttribute $XMLtree $full_address_XML_clean "source"]" |
---|
26 | set widgetInfo($address-mode) "source" |
---|
27 | set children [dTree_getChildren_fast $XMLtree $source] |
---|
28 | if {[llength $children] > 3} { |
---|
29 | set widgetInfo($address-choicetype) "combobox" |
---|
30 | } else { |
---|
31 | set widgetInfo($address-choicetype) "radiobox" |
---|
32 | } |
---|
33 | } elseif { [dTree_attrExists $XMLtree $full_address_XML_clean "require"]} { |
---|
34 | set widgetInfo($address-mode) "require" |
---|
35 | |
---|
36 | set widgetInfo($address-valuelist) $widgetInfo($address-requiredValue) |
---|
37 | set widgetInfo($address-titlelist) $widgetInfo($address-requiredValue) |
---|
38 | set children $widgetInfo($address-valuelist) |
---|
39 | |
---|
40 | set widgetInfo($address-choicetype) "combobox" |
---|
41 | set widgetInfo($address-variable) [lindex $widgetInfo($address-valuelist) 0] |
---|
42 | |
---|
43 | } else { |
---|
44 | set children [dTree_getChildren_fast $XMLtree $full_address_XML_clean ] |
---|
45 | if {[llength $children] > 3} { |
---|
46 | set widgetInfo($address-choicetype) "combobox" |
---|
47 | } else { |
---|
48 | set widgetInfo($address-choicetype) "radiobox" |
---|
49 | } |
---|
50 | } |
---|
51 | |
---|
52 | |
---|
53 | # initialize the widget |
---|
54 | switch $widgetInfo($address-choicetype) { |
---|
55 | "combobox" { |
---|
56 | set widgetInfo($address-height) 40 |
---|
57 | ttk::combobox $win.cbbox -textvariable widgetInfo($address-choice) -width 14 -state readonly |
---|
58 | place $win.cbbox -relx 0.5 -rely 0.0 -anchor nw -relwidth $widgetInfo(guiEntryRelWidth) |
---|
59 | set widgetInfo($address-status) 1 |
---|
60 | append widgetInfo($address-check) [subst {choice_check $win $address}] |
---|
61 | append widgetInfo($address-refresh) [subst {choice_refresh $win $address}] |
---|
62 | append widgetInfo($address-refreshStatus) [ subst { choice_refreshStatus $win $address}] |
---|
63 | bind $win.cbbox <<ComboboxSelected>> [subst {eval \$widgetInfo($address-check)}] |
---|
64 | $win configure -height $widgetInfo($address-height) |
---|
65 | |
---|
66 | } |
---|
67 | "radiobox" { |
---|
68 | ttk::frame $win.butts |
---|
69 | set widgetInfo($address-height) 20 |
---|
70 | set widgetInfo($address-choiceshift) 0 |
---|
71 | place $win.butts -relx 0.5 -rely 0.0 -anchor nw -relheight 1 -relwidth 0.5 |
---|
72 | set widgetInfo($address-status) 1 |
---|
73 | append widgetInfo($address-refreshStatus) [ subst { choice_refreshStatus $win $address}] |
---|
74 | } |
---|
75 | } |
---|
76 | |
---|
77 | |
---|
78 | # in the case of a source, the create_gui will not loop acroos the children by itself |
---|
79 | # this loop s then called inside the creation of the widget |
---|
80 | if {$widgetInfo($address-mode) != "require"} { |
---|
81 | foreach child $children { |
---|
82 | choice_add -path_father $win -address "$address.$child" |
---|
83 | } |
---|
84 | |
---|
85 | } |
---|
86 | |
---|
87 | finishWidget |
---|
88 | |
---|
89 | choice_refresh $win $address |
---|
90 | |
---|
91 | # clean the widget callBack on dstruction |
---|
92 | bind $win <Destroy> [ subst {widget_destroy $win $address}] |
---|
93 | return $win |
---|
94 | } |
---|
95 | |
---|
96 | # to add a new radiobutton to radiobox |
---|
97 | proc choice_add { args } { |
---|
98 | global widgetInfo XMLtree |
---|
99 | set mandatory_arguments {path_father address} |
---|
100 | |
---|
101 | # Get the widget informations |
---|
102 | getinfoFatherWidget |
---|
103 | |
---|
104 | incr widgetInfo($address_father-nboptions) 1 |
---|
105 | |
---|
106 | |
---|
107 | if {$widgetInfo($address_father-mode) != "standard"} { |
---|
108 | set value [lindex $full_address_XML end] |
---|
109 | set full_address_XML [lrange $full_address_XML 0 end-1] |
---|
110 | set full_address_XML_clean [lrange $full_address_XML_clean 0 end-1] |
---|
111 | |
---|
112 | set title $value |
---|
113 | set name "child_$name" |
---|
114 | } else { |
---|
115 | set value [dTree_getAttribute_fast $XMLtree $full_address_XML_clean "value"] |
---|
116 | set title [string totitle [ join [ split $value "_" ] " " ] ] |
---|
117 | if {[dTree_attrExists $XMLtree $full_address_XML_clean "title"]} { |
---|
118 | set title [dTree_getAttribute_fast $XMLtree $full_address_XML_clean "title"] |
---|
119 | } |
---|
120 | } |
---|
121 | |
---|
122 | lappend widgetInfo($address_father-valuelist) $value |
---|
123 | lappend widgetInfo($address_father-titlelist) $title |
---|
124 | switch $widgetInfo($address_father-choicetype) { |
---|
125 | "radiobox" { |
---|
126 | ttk::radiobutton $win_father.butts.$name -text $title -variable widgetInfo($address_father-variable) -value $value -command [subst {eval \$widgetInfo($address_father-check)}] |
---|
127 | place $win_father.butts.$name -x 0 -y $widgetInfo($address_father-choiceshift) -relwidth 1 -anchor nw |
---|
128 | incr widgetInfo($address_father-choiceshift) 20 |
---|
129 | incr widgetInfo($address_father-height) 20 |
---|
130 | $path_father configure -height $widgetInfo($address_father-height) |
---|
131 | } |
---|
132 | "combobox" { |
---|
133 | $win_father.cbbox configure -values $widgetInfo($address_father-titlelist) |
---|
134 | } |
---|
135 | } |
---|
136 | |
---|
137 | } |
---|
138 | |
---|
139 | proc choice_check {win address} { |
---|
140 | global widgetInfo |
---|
141 | |
---|
142 | # if combobox used , sync the choice of the combobox and the variable |
---|
143 | if { $widgetInfo($address-choicetype) == "combobox"} { |
---|
144 | set widgetInfo($address-variable) [lindex $widgetInfo($address-valuelist) [$win.cbbox current]] |
---|
145 | $win.cbbox selection clear |
---|
146 | } |
---|
147 | |
---|
148 | } |
---|
149 | |
---|
150 | proc choice_refresh {win address} { |
---|
151 | global widgetInfo |
---|
152 | if { $widgetInfo($address-mode) == "require" } { |
---|
153 | set widgetInfo($address-valuelist) $widgetInfo($address-requiredValue) |
---|
154 | set widgetInfo($address-titlelist) $widgetInfo($address-requiredValue) |
---|
155 | |
---|
156 | |
---|
157 | if {$widgetInfo($address-requiredValue) == ""} { |
---|
158 | set widgetInfo($address-status_txt) "No choices available now" |
---|
159 | set widgetInfo($address-status) -1 |
---|
160 | } else { |
---|
161 | $win.cbbox configure -values $widgetInfo($address-titlelist) |
---|
162 | set widgetInfo($address-status_txt) "" |
---|
163 | set widgetInfo($address-status) 1 |
---|
164 | if {[lsearch $widgetInfo($address-titlelist) $widgetInfo($address-variable)] == -1 } { |
---|
165 | #warning "$widgetInfo($address-variable) is not in the list ( $widgetInfo($address-titlelist) )\n automatic switch to [lindex $widgetInfo($address-valuelist) 0] " |
---|
166 | set widgetInfo($address-variable) [lindex $widgetInfo($address-valuelist) 0] |
---|
167 | } |
---|
168 | } |
---|
169 | } |
---|
170 | |
---|
171 | if { $widgetInfo($address-choicetype) == "combobox"} { |
---|
172 | $win.cbbox configure -values $widgetInfo($address-titlelist) |
---|
173 | set widgetInfo($address-choice) [lindex $widgetInfo($address-titlelist) [lsearch -exact $widgetInfo($address-valuelist) $widgetInfo($address-variable)]] |
---|
174 | } |
---|
175 | |
---|
176 | } |
---|
177 | |
---|
178 | |
---|
179 | proc choice_refreshStatus {win address} { |
---|
180 | global widgetInfo |
---|
181 | |
---|
182 | if { $widgetInfo($address-status) == -1 } { |
---|
183 | $win.status configure -image icon_flag |
---|
184 | } else { |
---|
185 | $win.status configure -image "" |
---|
186 | } |
---|
187 | |
---|
188 | smartpacker_update_visibility $win $address |
---|
189 | } |
---|
190 | |
---|
191 | |
---|
192 | |
---|
193 | # Copyright CERFACS 2014 |
---|
194 | # |
---|
195 | # antoine.dauptain@cerfacs.fr |
---|
196 | # |
---|
197 | # This software is a computer program whose purpose is to ensure technology |
---|
198 | # transfer between academia and industry. |
---|
199 | # |
---|
200 | # This software is governed by the CeCILL-B license under French law and |
---|
201 | # abiding by the rules of distribution of free software. You can use, |
---|
202 | # modify and/ or redistribute the software under the terms of the CeCILL-B |
---|
203 | # license as circulated by CEA, CNRS and INRIA at the following URL |
---|
204 | # "http://www.cecill.info". |
---|
205 | # |
---|
206 | # As a counterpart to the access to the source code and rights to copy, |
---|
207 | # modify and redistribute granted by the license, users are provided only |
---|
208 | # with a limited warranty and the software's author, the holder of the |
---|
209 | # economic rights, and the successive licensors have only limited |
---|
210 | # liability. |
---|
211 | # |
---|
212 | # In this respect, the user's attention is drawn to the risks associated |
---|
213 | # with loading, using, modifying and/or developing or reproducing the |
---|
214 | # software by the user in light of its specific status of free software, |
---|
215 | # that may mean that it is complicated to manipulate, and that also |
---|
216 | # therefore means that it is reserved for developers and experienced |
---|
217 | # professionals having in-depth computer knowledge. Users are therefore |
---|
218 | # encouraged to load and test the software's suitability as regards their |
---|
219 | # requirements in conditions enabling the security of their systems and/or |
---|
220 | # data to be ensured and, more generally, to use and operate it in the |
---|
221 | # same conditions as regards security. |
---|
222 | # |
---|
223 | # The fact that you are presently reading this means that you have had |
---|
224 | # knowledge of the CeCILL-B license and that you accept its terms. |
---|