source: CPL/oasis3-mct/branches/OASIS3-MCT_2.0_branch/util/oasisgui/opentea/create_dynlist.tcl @ 4775

Last change on this file since 4775 was 4775, checked in by aclsce, 5 years ago
  • Imported oasis3-mct from Cerfacs svn server (not suppotred anymore).

The version has been extracted from https://oasis3mct.cerfacs.fr/svn/branches/OASIS3-MCT_2.0_branch/oasis3-mct@1818

File size: 10.0 KB
Line 
1#  This program is under CECILL_B licence. See footer for details.
2
3proc dynlist_create { args } {
4    set mandatory_arguments { path_father address }
5   
6    initWidget
7   
8    set title [dTree_getAttribute $XMLtree $full_address_XML "title"]
9    set widgetInfo($address-type) [dTree_getAttribute $XMLtree $full_address_XML "type"]
10    set widgetInfo($address-renaming) 0
11    set widgetInfo($address-status) 1
12    ttk::frame $win
13   
14    #title
15    ttk::label $win.title  -text $title
16
17    # listbox and scrollbar
18    ttk::frame $win.dl
19    listbox $win.dl.lb -listvariable widgetInfo($address-content) -yscrollcommand [list $win.dl.sby set] -height 5 -activestyle none
20    $win.dl.lb  selection set 0
21    # avoid tab scrolling for mousewheel
22    bind $win.dl.lb <MouseWheel> {+set tabscroll 0}
23    bind $win.dl.lb <Leave> {+set tabscroll 1}
24   
25   
26   
27   
28    ttk::scrollbar $win.dl.sby -orient vertical -command [list $win.dl.lb yview]
29    # avoid tab scrolling for mousewheel
30    bind $win.dl.sby <MouseWheel> {+set tabscroll 0}
31    bind $win.dl.sby <Leave> {+set tabscroll 1}
32   
33    grid $win.dl.lb -sticky news -column 0 -row 0
34    grid $win.dl.sby -sticky news -column 1 -row 0
35   
36    # controls
37    ttk::frame $win.controls
38    ttk::label $win.controls.add -width 1 -image icon_plus -relief raised
39    ttk::label $win.controls.rm  -width 1 -image icon_minus -relief raised
40    pack $win.controls.add $win.controls.rm  -side left -anchor nw -padx 0 -pady 0
41   
42    #status
43    ttk::label $win.status -textvariable widgetInfo($address-status_txt) -foreground  red
44   
45    #packing
46    pack $win -pady 5
47    pack $win.status -side bottom -anchor nw
48    pack $win.title -side top -anchor nw
49    pack $win.dl -anchor nw
50    pack $win.controls -anchor nw
51
52    # bindings
53   
54    # kill rename dialog if leaving widget
55    bind $win <Leave> +[subst {
56        destroy $win.dl.lb.rename
57        set widgetInfo($address-renaming) 0
58    }]
59       
60   
61    #double click
62    bind $win.dl.lb <Double-1> [subst { dynlist_rename_existing $win $address %y }]
63    #simple click
64    bind $win.dl.lb <ButtonPress> [subst {+
65        # cancel renaming if necessary
66        if { \$widgetInfo($address-renaming) != 0 } {
67            destroy $win.dl.lb.rename
68            set widgetInfo($address-renaming) 0
69        }   
70    }]
71   
72    # addition
73    bind $win.controls.add  <ButtonPress> [subst {
74        $win.controls.add configure -relief sunken
75        dynlist_add $win $address 
76    }]
77   
78    bind $win.controls.add  <ButtonRelease> [subst {$win.controls.add configure -relief raised}]
79   
80   
81    # deletion
82    bind $win.controls.rm  <ButtonPress> [subst {
83        $win.controls.rm configure -relief sunken
84        dynlist_del $win $address 
85       
86    }]
87    bind $win.controls.rm  <ButtonRelease> [subst {$win.controls.rm configure -relief raised}]
88   
89   
90    append widgetInfo($address-refresh) [subst { dynlist_refresh $win $address }]
91    append widgetInfo($address-check) [ subst { dynlist_check $win $address }]
92    finishWidget
93   
94    # clean the widget callBack on dstruction
95    bind $win <Destroy> [ subst {widget_destroy $win $address}]
96   
97    return $win
98}
99
100
101# after variable> tmpTree
102proc dynlist_check {win address} {
103    global widgetInfo
104#    set type [lindex [ split $widgetInfo($address-type) "_" ] 1 ]
105#    set test_dl 1
106#    foreach elt $widgetInfo($address-content) {
107#        set test_dl [expr {[ test_vartype $elt $type ] * $test_dl}]
108#    }
109#   
110#    if {$test_dl == 1} {
111#        set widgetInfo($address-status) 1
112#        set widgetInfo($address-status_txt) ""
113#        #set widgetInfo($address-content) [lreplace $widgetInfo($address-content) $index $index $widgetInfo($address-entry)]
114#    } else { 
115#        set widgetInfo($address-status) -1
116#        set widgetInfo($address-status_txt) $test_dl
117#    }
118   
119    set widgetInfo($address-variable) [join $widgetInfo($address-content) ";"]
120}
121
122# after DStree >variable
123proc dynlist_refresh {win address} {
124    global widgetInfo
125    set widgetInfo($address-content) [split $widgetInfo($address-variable) ";"]
126}
127
128
129
130# DYNLIST specific procedures
131
132# addition of one element to the list
133proc dynlist_add {win address} {
134    global widgetInfo tmpTree
135   
136    # cancel renaming if on
137    if { $widgetInfo($address-renaming) != 0} {
138        destroy $win.dl.lb.rename
139        set widgetInfo($address-renaming) 0
140    }   
141   
142    # get where to insert the item
143    set rank [$win.dl.lb curselection]
144    if {$rank ==""} {
145        set rank end
146    } else {
147        incr rank
148    }
149   
150   
151    # find what to insert
152    set type [lindex [ split $widgetInfo($address-type) "_" ] 1 ]
153    switch $type {
154        "double" {
155            set guess "0.0"
156            while {[lsearch "$widgetInfo($address-content)" "$guess"] != -1} {
157                set guess [expr (guess+1.0)]
158            }
159        }
160        "integer" {
161            set guess "0"
162            while {[lsearch "$widgetInfo($address-content)" "$guess"] != -1} {
163                incr guess
164            }
165        }
166        default {
167            set guess "0"
168            while {[lsearch "$widgetInfo($address-content)" "item_$guess"] != -1} {
169                incr guess
170            }
171            set guess "item_$guess"
172        }
173    }
174   
175    set widgetInfo($address-content) [linsert $widgetInfo($address-content) $rank $guess]
176   
177    #call rename dialog
178    dynlist_rename $win $address $rank
179   
180    eval $widgetInfo($address-check)
181   
182}
183
184
185# renaming an element in the list
186proc dynlist_rename_existing {win address y} {
187    global widgetInfo tmpTree
188    dynlist_rename $win $address [$win.dl.lb nearest $y] 
189    eval $widgetInfo($address-check)
190}
191
192
193# renaming dialog
194proc dynlist_rename {win address rank } {
195    global widgetInfo
196   
197    if { $widgetInfo($address-renaming) != 0 } {
198        focus $win.dl.lb.rename.entry
199        return   
200    }
201   
202    set widgetInfo($address-renaming) $rank
203   
204    $win.dl.lb see $rank
205    set bbox [$win.dl.lb bbox $rank]
206    set width [expr ([winfo width $win.dl.lb]-3)]
207   
208   
209    frame $win.dl.lb.rename -background [ThemeColor 1.]
210    place $win.dl.lb.rename -x [lindex $bbox 0] -y [lindex $bbox 1] -width $width -height [lindex $bbox 3]
211    set widgetInfo($address-entry) [$win.dl.lb get $rank]
212    ttk::entry $win.dl.lb.rename.entry -textvariable widgetInfo($address-entry) 
213    pack $win.dl.lb.rename.entry -expand 1 -fill both
214    $win.dl.lb.rename.entry selection range 0 end
215    $win.dl.lb.rename.entry icursor end 
216    focus $win.dl.lb.rename.entry
217     
218    bind $win.dl.lb.rename.entry <Return>  [ subst {
219        dynlist_setvar $win $address $rank
220        destroy $win.dl.lb.rename
221        set widgetInfo($address-renaming) 0
222    }]
223     
224    bind $win.dl.lb.rename.entry <Escape>  [ subst {
225        destroy $win.dl.lb.rename
226        set widgetInfo($address-renaming) 0
227    }]
228
229}
230
231# insertion of the new item in the list
232proc dynlist_setvar {win address index} {
233    global widgetInfo tmpTree
234    set type [lindex [ split $widgetInfo($address-type) "_" ] 1 ]
235   
236    set test_dl [ test_vartype $widgetInfo($address-entry) $type ] 
237    if {$test_dl == 1} {
238        set widgetInfo($address-status) 1
239        set widgetInfo($address-status_txt) ""       
240        set widgetInfo($address-content) [lreplace $widgetInfo($address-content) $index $index $widgetInfo($address-entry)]
241    } else { 
242        set widgetInfo($address-status) -1
243        set widgetInfo($address-status_txt) $test_dl
244    }
245    eval $widgetInfo($address-check)
246}
247
248
249proc dynlist_del {win address} {
250    global widgetInfo tmpTree
251   
252    # cancel renaming if on
253    if { $widgetInfo($address-renaming) != 0 } {
254        destroy $win.dl.lb.rename
255        $win.dl.lb selection set $widgetInfo($address-renaming)
256        set widgetInfo($address-renaming) 0
257    }   
258     # get where to delete the item
259    set rank [$win.dl.lb curselection]
260    if {$rank ==""} {return}
261   
262    # remove if it is not the last element
263    if {[llength $widgetInfo($address-content)] > 1} {
264         set widgetInfo($address-content) [lreplace $widgetInfo($address-content) $rank $rank ]
265         incr rank -1
266         focus $win.dl.lb
267         $win.dl.lb see $rank
268         $win.dl.lb selection clear 0 end         
269         $win.dl.lb selection set $rank   
270    }
271   
272    eval $widgetInfo($address-check)
273}
274
275
276proc dynlist_update_entry {win address} {
277    global widgetInfo tmpTree
278        set widgetInfo($address-entry) [  $win.dl.lb get [ $win.dl.lb curselection]]
279        eval $widgetInfo($address-check)
280}
281
282
283
284
285#  Copyright CERFACS 2014
286#   
287#  antoine.dauptain@cerfacs.fr
288#   
289#  This software is a computer program whose purpose is to ensure technology
290#  transfer between academia and industry.
291#   
292#  This software is governed by the CeCILL-B license under French law and
293#  abiding by the rules of distribution of free software.  You can  use,
294#  modify and/ or redistribute the software under the terms of the CeCILL-B
295#  license as circulated by CEA, CNRS and INRIA at the following URL
296#  "http://www.cecill.info".
297#   
298#  As a counterpart to the access to the source code and  rights to copy,
299#  modify and redistribute granted by the license, users are provided only
300#  with a limited warranty  and the software's author,  the holder of the
301#  economic rights,  and the successive licensors  have only  limited
302#  liability.
303#   
304#  In this respect, the user's attention is drawn to the risks associated
305#  with loading,  using,  modifying and/or developing or reproducing the
306#  software by the user in light of its specific status of free software,
307#  that may mean  that it is complicated to manipulate,  and  that  also
308#  therefore means  that it is reserved for developers  and  experienced
309#  professionals having in-depth computer knowledge. Users are therefore
310#  encouraged to load and test the software's suitability as regards their
311#  requirements in conditions enabling the security of their systems and/or
312#  data to be ensured and,  more generally, to use and operate it in the
313#  same conditions as regards security.
314#   
315#  The fact that you are presently reading this means that you have had
316#  knowledge of the CeCILL-B license and that you accept its terms.
Note: See TracBrowser for help on using the repository browser.