ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/getfile3.6.tcl
Revision: 2.4
Committed: Fri Oct 28 17:17:18 1994 UTC (29 years, 6 months ago) by greg
Content type: application/x-tcl
Branch: MAIN
Changes since 2.3: +9 -10 lines
Log Message:
fixed problems with size on different screens (sort of)

File Contents

# Content
1 # SCCSid "$SunId$ LBL"
2 #
3 # Usage: getfile [-win w] [-perm] [-glob pattern] [-view proc] [-send proc]
4 #
5 # Create a dialog box (in window w if given) to get file name.
6 # Normally, a single file name and return as value.
7 # If perm switch is given, keep window up for multiple file entries.
8 # If pattern is given, start with list of all the specified files,
9 # breaking the string into directory and file match parts.
10 # If a view procedure is given, a separate "View" button appears
11 # for allowing the user to preview a selected file.
12 # If a send procedure is given, a file name is sent upon
13 # each double-click, and no File entry is displayed.
14 #
15
16 proc getfile args { # get filename interactively
17 # Create necessary globals
18 global curdir curfile curpat
19 # Set defaults
20 set w .fpwin
21 set topwin 1
22 set curdir .
23 set curpat *
24 set transient 1
25 # Get options
26 while {[llength $args]} {
27 switch -glob -- [lindex $args 0] {
28 -win* {
29 set w [lindex $args 1]
30 set topwin 0
31 set args [lreplace $args 1 1]
32 }
33 -perm* {
34 set transient 0
35 }
36 -glob {
37 set curdir [file dirname [lindex $args 1]]
38 set curpat [file tail [lindex $args 1]]
39 set args [lreplace $args 1 1]
40 }
41 -vi* {
42 set viewproc [lindex $args 1]
43 set args [lreplace $args 1 1]
44 }
45 -send {
46 set sendproc [lindex $args 1]
47 set args [lreplace $args 1 1]
48 }
49 default { error "bad argument to getfile: [lindex $args 0]" }
50 }
51 set args [lreplace $args 0 0]
52 }
53 # Save initial directory
54 set startdir [pwd]
55 # Create widgets
56 catch {destroy $w}
57 if $topwin {
58 toplevel $w -geometry 400x410
59 wm title $w "File Picker"
60 wm iconname $w "Files"
61 wm minsize $w 400 300
62 } else {
63 frame $w -geometry 400x410
64 pack $w
65 }
66 label $w.dt -text Directory:
67 place $w.dt -relx .025 -rely .03125
68 helplink $w.dt file directory intro
69 button $w.ls -text List -command "update_dir $w"
70 place $w.ls -relx .025 -rely .125 -relwidth .15 -relheight .0625
71 helplink $w.ls file directory list
72 entry $w.de -textvariable curdir -relief sunken
73 place $w.de -relx .25 -rely .03125 -relwidth .6875 -relheight .0625
74 focus $w.de
75 helplink $w.de file directory intro
76 bind $w.de <Return> "update_dir $w"
77 entry $w.pw -relief sunken -textvariable curpat
78 place $w.pw -relx .25 -rely .125 -relwidth .34375 -relheight .0625
79 bind $w.pw <Return> "update_dir $w"
80 helplink $w.pw file directory match
81 frame $w.fm
82 scrollbar $w.fm.sb -relief sunken -command "$w.fm.fl yview"
83 listbox $w.fm.fl -relief sunken -yscroll "$w.fm.sb set"
84 pack $w.fm.sb -side right -fill y
85 pack $w.fm.fl -side left -expand yes -fill both
86 place $w.fm -relx .25 -rely .21875 -relwidth .6875 -relheight .625
87 tk_listboxSingleSelect $w.fm.fl
88 helplink $w.fm.fl file file intro
89 if [info exists sendproc] {
90 bind $w.fm.fl <Double-Button-1> "set_curfile $w $sendproc"
91 if {$transient} {
92 bind $w.fm.fl <Double-Button-1> \
93 "+if {\$curfile > {}} {destroy $w}"
94 }
95 } else {
96 bind $w.fm.fl <Double-Button-1> "set_curfile $w"
97 label $w.fl -text File:
98 place $w.fl -relx .10625 -rely .875
99 entry $w.fn -relief sunken -textvariable curfile
100 place $w.fn -relx .25 -rely .875 \
101 -relwidth .6875 -relheight .0625
102 focus $w.fn
103 helplink $w.fn file file entry
104 if $transient {
105 bind $w.fn <Return> "destroy $w"
106 } else {
107 bind $w.fn <Return> {}
108 }
109 }
110 if {$transient != [info exists sendproc]} {
111 button $w.ok -text OK -command "destroy $w"
112 place $w.ok -relx .025 -rely .28125 \
113 -relwidth .15 -relheight .0625
114 }
115 if {$transient || [info exists sendproc]} {
116 button $w.cancel -text Cancel \
117 -command "destroy $w; unset curdir"
118 place $w.cancel -relx .025 -rely .375 \
119 -relwidth .15 -relheight .0625
120 }
121 if [info exists viewproc] {
122 button $w.vi -text View -state disabled \
123 -command "$viewproc \[$w.fm.fl get \[$w.fm.fl curselection\]\]"
124 place $w.vi -relx .025 -rely .46875 \
125 -relwidth .15 -relheight .0625
126 bind $w.fm.fl <ButtonRelease-1> "+chk_select $w"
127 helplink $w.vi file file view
128 }
129 # Load current directory
130 update_dir $w
131 if $transient {
132 tkwait window $w
133 cd $startdir
134 if [info exists sendproc] {
135 return [info exists curdir]
136 }
137 if [info exists curdir] {
138 return $curdir/$curfile
139 }
140 return
141 } elseif {[info exists sendproc]} {
142 tkwait window $w
143 cd $startdir
144 if [info exists curdir] {
145 return 1
146 }
147 return 0
148 }
149 # Else return the dialog window
150 return $w
151 }
152
153
154 proc update_dir w { # Update working directory
155 global curdir curpat
156 if {"$curpat" == ""} {
157 set curpat *
158 }
159 if {"$curdir" == {}} {set curdir {~}}
160 if [catch {cd $curdir} curdir] {
161 set oldcol [lindex [$w.de config -foreground] 4]
162 $w.de config -foreground Red
163 update idletasks
164 after 1500
165 $w.de config -foreground $oldcol
166 }
167 set curdir [pwd]
168 $w.fm.fl delete 0 end
169 set ls ../
170 foreach f [glob *] {
171 if [file isdirectory $f] {
172 lappend ls $f/
173 }
174 }
175 foreach f [eval glob -nocomplain [split $curpat]] {
176 if [file isfile $f] {
177 lappend ls $f
178 }
179 }
180 eval $w.fm.fl insert end [lsort $ls]
181 }
182
183
184 proc set_curfile {w {sp ""}} { # change current file selection
185 global curdir curfile
186 set f [$w.fm.fl get [$w.fm.fl curselection]]
187 if [string match */ $f] {
188 set curdir [string range $f 0 [expr [string length $f]-2]]
189 update_dir $w
190 } else {
191 set curfile $f
192 if {"$sp" > ""} {
193 $sp $curdir/$curfile
194 }
195 }
196 }
197
198
199 proc chk_select w { # check if current selection is file
200 set s [$w.fm.fl curselection]
201 if {"$s" > "" && [file isfile [$w.fm.fl get $s]]} {
202 $w.vi configure -state normal
203 } else {
204 $w.vi configure -state disabled
205 }
206 }