source: CPL/oasis3-mct/branches/OASIS3-MCT_2.0_branch/util/oasisgui/opentea/create_browser.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: 8.6 KB
Line 
1#  This program is under CECILL_B licence. See footer for details.
2
3
4
5proc browser_create { args } {
6    set mandatory_arguments { path_father address }
7    initWidget
8    global workingDir
9   
10    ttk::frame $win -height 40p
11    eval $widgetInfo(packme-$win)
12   
13    #set title "[dTree_getAttribute $XMLtree $full_address_XML "title"]"
14    set widgetInfo($address-browsertype) "[dTree_getAttribute $XMLtree $full_address_XML "type"]" 
15    set widgetInfo($address-filter) [split [dTree_tryGetAttribute $XMLtree $full_address_XML "filter" "none" ] ";"] 
16   
17   
18   
19    smartpacker_setup_label $win $address
20    smartpacker_setup_status $win $address
21
22   
23    ttk::entry $win.entry  -textvariable widgetInfo($address-variable) 
24    #pack  $win.entry -side left
25   
26    bind $win.entry <FocusOut> [subst {browser_entry_cmd $address}]
27    bind $win.entry <Return> [subst {browser_entry_cmd $address}]
28   
29    #bind $win.entry <FocusOut> [subst {$win.entry xview moveto 1.}]
30   
31    ttk::button $win.butt -image icon_folder  -compound right -command  [subst {
32        browser_bsr_cmd $win $address "$title" 
33    }]
34   
35   
36    #pack $win.butt -side left
37    place $win.entry -relx 0.5 -rely 0. -anchor nw   -relwidth [expr {0.8*$widgetInfo(guiEntryRelWidth)}]
38    place $win.butt -relx [expr {0.5 + 0.8*$widgetInfo(guiEntryRelWidth)}] -rely 0. -relwidth [expr {0.2*$widgetInfo(guiEntryRelWidth)}] -anchor nw 
39   
40    append widgetInfo($address-refreshStatus) [ subst { browser_refreshStatus $win $address}]
41    # clean the widget callBack on dstruction
42    bind $win <Destroy> [ subst {widget_destroy $win $address}]   
43    finishWidget
44   
45   
46   
47   
48   
49   
50    # setup browser starts
51    set initialdircommand ""
52    #set browsemode [getConfig "config gui paths"]
53    #switch $browsemode {
54    #    "constant" {
55    #        set constdir [getConfig "config gui paths constant workingDir"]
56    #        set initialdircommand " -initialdir $constdir"
57    #    }
58    #    "auto" {
59    #        set initialdircommand " -initialdir $workingDir"
60    #    }
61    #    "last" {
62    #        set initialdircommand ""
63    #    }
64    #   
65    #}
66   
67    # set up filters
68    set filtercommand " "
69    if {$widgetInfo($address-browsertype) in {"file" "multiple_files"} } {
70        if {$widgetInfo($address-filter) !="none"} {
71            set filterlist ""
72            foreach suffix $widgetInfo($address-filter) {
73                lappend filterlist "$suffix .$suffix"
74            }
75            set filtercommand " -filetypes \{$filterlist\}"
76           
77        } 
78    }
79   
80    if {$widgetInfo($address-browsertype) == "h5_asciiBound"} {
81        set filtercommand " -filetypes \{\{ \"mesh *.mesh.h5 + *.asciiBound\" \"*.h5\"\}\}"
82       
83    }   
84   
85   
86    # build callback
87    switch $widgetInfo($address-browsertype)  {
88        "file" {
89            set widgetInfo($address-callback) [subst { tk_getOpenFile -title \"$title\" $initialdircommand $filtercommand}]
90        }
91        "multiple_files" {
92            set widgetInfo($address-callback) [subst { tk_getOpenFile -title \"$title\" $initialdircommand $filtercommand -multiple 1}]
93        }
94        "h5_asciiBound" {
95            set widgetInfo($address-callback) [subst {tk_getOpenFile -title \"$title\" $initialdircommand $filtercommand}]
96        }
97        "folder" {
98            set widgetInfo($address-callback) [subst {tk_chooseDirectory -title \"$title\" $initialdircommand}]
99        }
100    }
101   
102   
103   
104   
105}
106
107
108# Command associated to entry
109proc browser_entry_cmd {address} {
110    global widgetInfo
111    eval $widgetInfo($address-check)
112}
113
114# Command associated to browser
115proc browser_bsr_cmd { win address title} {
116    global widgetInfo 
117   
118   
119    set last_value $widgetInfo($address-variable)
120    set widgetInfo($address-variable) [eval $widgetInfo($address-callback)]
121   
122    if {$widgetInfo($address-variable) == ""} {
123        set widgetInfo($address-variable) $last_value
124    }
125   
126    if {[llength $widgetInfo($address-variable) ] > 1} {
127        set widgetInfo($address-variable) [string map {" " ";"} $widgetInfo($address-variable)]
128    }
129   
130   
131    eval $widgetInfo($address-check)
132   
133}
134
135
136
137
138proc browser_refreshStatus {win address} {
139    global widgetInfo
140
141    if {$widgetInfo($address-variable)!=""} {
142        #set widgetInfo($address-variable) [ pathTo $widgetInfo($address-variable) [pwd]]
143    }   
144    if {$widgetInfo($address-browsertype) == "multiple_files"} {
145        set filename [lindex [split $widgetInfo($address-variable) ";"] 0]     
146    } else {
147        set filename $widgetInfo($address-variable)
148    }
149   
150   
151   
152    set widgetInfo($address-status) 1
153    set widgetInfo($address-status_txt) ""
154   
155     
156   
157   
158    if { [file exists $filename] == 0} {
159        set widgetInfo($address-status) -1
160        set widgetInfo($address-status_txt) "File not found"
161    }
162   
163    if { $widgetInfo($address-browsertype) == "h5_asciiBound" && [file exists $filename]} {
164        set asciiboundfile "[string range  $filename 0 end-8].asciiBound"
165        if {[file exists $asciiboundfile] == 0} {
166            set widgetInfo($address-status) -1
167            set widgetInfo($address-status_txt) "AsciiBound not found"
168            log "Error while loading mesh file \n $filename.\n Cannot find asciiBound file: \n $asciiboundfile \n"
169        }
170    }
171
172   
173    $win.status configure -image ""
174   
175    if { $filename == ""} {
176        set widgetInfo($address-status) -1
177        set widgetInfo($address-status_txt) "(...)"
178        $win.status configure -image icon_question
179    }
180   
181    if { $widgetInfo($address-status) == -1 &&  $widgetInfo($address-status_txt) != "(...)" } {
182        $win.status configure -image icon_flag
183    }
184   
185    smartpacker_update_visibility $win $address
186    update idletasks
187    $win.entry xview moveto 1.
188}
189
190
191
192# http://wiki.tcl.tk/15925
193# get relative path to target file from current file
194 # arguments are file names, not directory names (not checked)
195# CODE CHANGED : while {[string equal [lindex $cc 0] [lindex $tt 0]] && [llength $cc] > 1} {
196 
197 proc pathTo {target current} {
198     set cc [file split [file normalize $current]]
199     set tt [file split [file normalize $target]]
200     if {![string equal [lindex $cc 0] [lindex $tt 0]]} {
201         # not on *n*x then
202         return -code error "$target not on same volume as $current"
203     }
204     while {[string equal [lindex $cc 0] [lindex $tt 0]] && [llength $cc] >= 1} {
205         # discard matching components from the front (but don't
206         # do the last component in case the two files are the same)
207         set cc [lreplace $cc 0 0]
208         set tt [lreplace $tt 0 0]
209     }
210     set prefix ""
211     if {[llength $cc] == 1} {
212         # just the file name, so target is lower down (or in same place)
213         set prefix "."
214     }
215     # step up the tree (start from 1 to avoid counting file itself
216     for {set i 1} {$i <= [llength $cc]} {incr i} {
217         append prefix " .."
218     }
219     # stick it all together (the eval is to flatten the target list)
220     return [eval file join $prefix $tt]
221 }
222
223
224
225#  Copyright CERFACS 2014
226#   
227#  antoine.dauptain@cerfacs.fr
228#   
229#  This software is a computer program whose purpose is to ensure technology
230#  transfer between academia and industry.
231#   
232#  This software is governed by the CeCILL-B license under French law and
233#  abiding by the rules of distribution of free software.  You can  use,
234#  modify and/ or redistribute the software under the terms of the CeCILL-B
235#  license as circulated by CEA, CNRS and INRIA at the following URL
236#  "http://www.cecill.info".
237#   
238#  As a counterpart to the access to the source code and  rights to copy,
239#  modify and redistribute granted by the license, users are provided only
240#  with a limited warranty  and the software's author,  the holder of the
241#  economic rights,  and the successive licensors  have only  limited
242#  liability.
243#   
244#  In this respect, the user's attention is drawn to the risks associated
245#  with loading,  using,  modifying and/or developing or reproducing the
246#  software by the user in light of its specific status of free software,
247#  that may mean  that it is complicated to manipulate,  and  that  also
248#  therefore means  that it is reserved for developers  and  experienced
249#  professionals having in-depth computer knowledge. Users are therefore
250#  encouraged to load and test the software's suitability as regards their
251#  requirements in conditions enabling the security of their systems and/or
252#  data to be ensured and,  more generally, to use and operate it in the
253#  same conditions as regards security.
254#   
255#  The fact that you are presently reading this means that you have had
256#  knowledge of the CeCILL-B license and that you accept its terms.
Note: See TracBrowser for help on using the repository browser.