Changeset 1923 for branches/blt4/gui/scripts/filechoiceentry.tcl
- Timestamp:
- Oct 18, 2010, 11:59:55 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/blt4/gui/scripts/filechoiceentry.tcl
r1915 r1923 22 22 23 23 constructor {owner path args} { 24 24 # defined below 25 25 } 26 26 destructor { 27 27 # defined below 28 28 } 29 29 public method value {args} … … 55 55 itcl::body Rappture::FileChoiceEntry::constructor {owner path args} { 56 56 if {[catch {$owner isa Rappture::ControlOwner} valid] != 0 || !$valid} { 57 57 error "bad object \"$owner\": should be Rappture::ControlOwner" 58 58 } 59 59 set _owner $owner … … 65 65 # 66 66 itk_component add choice { 67 67 Rappture::Combobox $itk_interior.choice -editable no 68 68 } 69 69 pack $itk_component(choice) -expand yes -fill both … … 73 73 # for each template found. 74 74 foreach cname [$_owner xml children -type pattern $_path] { 75 76 77 78 79 80 81 82 83 84 85 75 set glob [string trim [$_owner xml get $_path.$cname]] 76 # Successively replace each template with its value. 77 while { [regexp -indices {@@[^@]*@@} $glob range] } { 78 foreach {first last} $range break 79 set i1 [expr $first + 2] 80 set i2 [expr $last - 2] 81 set cpath [string range $glob $i1 $i2] 82 set value [$_owner xml get $cpath.$cname] 83 set glob [string replace $glob $first $last $value] 84 $_owner notify add $this $cpath [itcl::code $this _whenidle] 85 } 86 86 } 87 87 $_owner notify sync … … 110 110 set i [lsearch -exact $args -check] 111 111 if {$i >= 0} { 112 113 112 set onlycheck 1 113 set args [lreplace $args $i $i] 114 114 } 115 115 116 116 if {[llength $args] == 1} { 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 117 if {$onlycheck} { 118 # someday we may add validation... 119 return 120 } 121 set newval [lindex $args 0] 122 if {[info exists _str2val($newval)]} { 123 # this is a label -- use it directly 124 $itk_component(choice) value $newval 125 set newval $_str2val($newval) ;# report the actual value 126 } else { 127 # this is a value -- search for corresponding label 128 foreach str [array names _str2val] { 129 if {$_str2val($str) == $newval} { 130 $itk_component(choice) value $str 131 break 132 } 133 } 134 } 135 return $newval 136 136 137 137 } elseif {[llength $args] != 0} { 138 138 error "wrong # args: should be \"value ?-check? ?newval?\"" 139 139 } 140 140 … … 144 144 set str [$itk_component(choice) value] 145 145 if {[info exists _str2val($str)]} { 146 146 return $_str2val($str) 147 147 } 148 148 return $str … … 158 158 set label [$_owner xml get $_path.about.label] 159 159 if {"" == $label} { 160 160 set label "Choice" 161 161 } 162 162 return $label … … 196 196 set allfiles {} 197 197 foreach cname [$_owner xml children -type pattern $_path] { 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 198 set glob [string trim [$_owner xml get $_path.$cname]] 199 # Successively replace each template with its value. 200 while { [regexp -indices {@@[^@]*@@} $glob range] } { 201 foreach {first last} $range break 202 set i1 [expr $first + 2] 203 set i2 [expr $last - 2] 204 set cpath [string range $glob $i1 $i2] 205 set value [$_owner xml get $cpath.current] 206 if { $value == "" } { 207 set value [$_owner xml get $cpath.default] 208 } 209 set glob [string replace $glob $first $last $value] 210 } 211 # Replace the template with the substituted value. 212 set files [glob -nocomplain -type { r f } $glob] 213 set allfiles [concat $allfiles $files] 214 214 } 215 215 set first "" 216 216 set tail "" 217 217 foreach file $allfiles { 218 219 220 221 222 223 224 225 226 218 set tail [file tail $file] 219 if { $first == "" } { 220 set first $tail 221 } 222 set tail [file root $tail] 223 $itk_component(choice) choices insert end $file $tail 224 set _str2val($tail) $file 225 set len [string length $tail] 226 if {$len > $max} { set max $len } 227 227 } 228 228 $itk_component(choice) configure -width $max … … 254 254 set desc $path 255 255 if {$path == ""} { 256 256 set desc [$_owner xml get $_path.about.description] 257 257 } 258 258 259 259 if {[string length $str] > 0 && [string length $desc] > 0} { 260 260 append tip "\n\n$str:\n$desc" 261 261 } 262 262 return $tip … … 269 269 set valid {normal disabled} 270 270 if {[lsearch -exact $valid $itk_option(-state)] < 0} { 271 271 error "bad value \"$itk_option(-state)\": should be [join $valid {, }]" 272 272 } 273 273 $itk_component(choice) configure -state $itk_option(-state) … … 276 276 itcl::body Rappture::FileChoiceEntry::_whenidle {} { 277 277 if { !$_rebuildPending } { 278 279 280 } 281 } 278 after 10 [itcl::code $this _rebuild] 279 set _rebuildPending 1 280 } 281 }
Note: See TracChangeset
for help on using the changeset viewer.