Changeset 1923 for branches/blt4/gui/scripts/loader.tcl
- Timestamp:
- Oct 18, 2010, 11:59:55 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/blt4/gui/scripts/loader.tcl
r1424 r1923 59 59 itcl::body Rappture::Loader::constructor {owner path args} { 60 60 if {[catch {$owner isa Rappture::ControlOwner} valid] != 0 || !$valid} { 61 61 error "bad object \"$owner\": should be Rappture::ControlOwner" 62 62 } 63 63 set _owner $owner … … 65 65 66 66 itk_component add combo { 67 67 Rappture::Combobox $itk_interior.combo -editable no 68 68 } { 69 70 69 usual 70 keep -width 71 71 } 72 72 pack $itk_component(combo) -expand yes -fill both … … 77 77 # example files are stored here 78 78 if {$itk_option(-tool) != ""} { 79 79 set fdir [$itk_option(-tool) installdir] 80 80 } else { 81 81 set fdir "." 82 82 } 83 83 set defval [$_owner xml get $path.default] … … 89 89 set newfile "" 90 90 foreach comp [$_owner xml children -type new $path] { 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 91 set name [$_owner xml get $path.$comp] 92 set fname [file join $fdir examples $name] 93 94 if {[file exists $fname]} { 95 set newfile $fname 96 97 if {[catch {set obj [Rappture::library $fname]} result]} { 98 puts stderr "WARNING: can't load example file \"$fname\"" 99 puts stderr " $result" 100 } else { 101 set label "New" 102 $itk_component(combo) choices insert end $obj $label 103 104 # if this is new, add it to the label->file hash 105 if {![info exists entries($label)]} { 106 set entries($label) $obj 107 set _label2file($label) [file tail $fname] 108 } 109 110 # translate default file name => default label 111 if {[string equal $defval [file tail $fname]]} { 112 $_owner xml put $path.default "New" 113 } 114 } 115 break 116 } else { 117 puts stderr "WARNING: missing example file \"$fname\"" 118 } 119 119 } 120 120 … … 124 124 # 125 125 foreach comp [$_owner xml children -type upload $path] { 126 127 128 129 130 131 132 133 134 135 136 137 126 foreach tcomp [$_owner xml children -type to $path.$comp] { 127 set topath [$_owner xml get $path.$comp.$tcomp] 128 if { [$_owner xml element -as id $topath] == "" } { 129 puts stderr \ 130 "unknown <upload> path \"$topath\": please fix tool.xml" 131 continue 132 } 133 set label [$_owner xml get $topath.about.label] 134 set desc [$_owner xml get $topath.about.description] 135 lappend _uppath $topath $label $desc 136 } 137 break 138 138 } 139 139 if {[llength $_uppath] > 0} { 140 141 140 $itk_component(combo) choices insert end \ 141 @upload [Rappture::filexfer::label upload] 142 142 } 143 143 … … 148 148 # 149 149 Rappture::Balloon $itk_component(hull).download \ 150 150 -title "Choose what to [string tolower [Rappture::filexfer::label downloadWord]]:" 151 151 set inner [$itk_component(hull).download component inner] 152 152 153 153 set i 0 154 154 foreach comp [$_owner xml children -type download $path] { 155 156 157 158 159 160 161 162 163 164 165 166 167 155 foreach dcomp [$_owner xml children -type from $path.$comp] { 156 set frompath [$_owner xml get $path.$comp.$dcomp] 157 if {"" != $frompath} { 158 lappend _dnpaths $frompath 159 set _dnpath2state($this-$frompath) [expr {$i == 0}] 160 161 set label [$_owner xml get $frompath.about.label] 162 checkbutton $inner.cb$i -text $label \ 163 -variable ::Rappture::Loader::_dnpath2state($this-$frompath) 164 pack $inner.cb$i -anchor w 165 incr i 166 } 167 } 168 168 } 169 169 button $inner.go -text [Rappture::filexfer::label download] \ 170 170 -command [itcl::code $this _downloadValues] 171 171 pack $inner.go -side bottom -padx 50 -pady {4 2} 172 172 173 173 if {[llength $_dnpaths] > 0} { 174 175 174 $itk_component(combo) choices insert end \ 175 @download [Rappture::filexfer::label download] 176 176 } 177 177 178 178 if {[$itk_component(combo) choices size] > 0} { 179 179 $itk_component(combo) choices insert end "---" "---" 180 180 } 181 181 … … 186 186 set flist "" 187 187 foreach comp [$_owner xml children -type example $path] { 188 188 lappend flist [$_owner xml get $path.$comp] 189 189 } 190 190 191 191 # if there are no examples, then look for *.xml 192 192 if {[llength $flist] == 0} { 193 193 set flist *.xml 194 194 } 195 195 … … 197 197 set _counter 0 198 198 foreach ftail $flist { 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 199 set fpath [file join $fdir examples $ftail] 200 201 foreach fname [glob -nocomplain $fpath] { 202 if {[string equal $fname $newfile]} { 203 continue 204 } 205 if {[file exists $fname]} { 206 if {[catch {set obj [Rappture::library $fname]} result]} { 207 puts stderr "WARNING: can't load example file \"$fname\"" 208 puts stderr " $result" 209 } else { 210 set label [$obj get about.label] 211 if {$label == ""} { 212 set label "Example #[incr _counter]" 213 } 214 215 # if this is new, add it to the label->file hash 216 if {![info exists entries($label)]} { 217 set entries($label) $obj 218 set _label2file($label) [file tail $fname] 219 } 220 221 # translate default file name => default label 222 if {[string equal $defval [file tail $fname]]} { 223 $_owner xml put $path.default $label 224 } 225 } 226 } else { 227 puts stderr "WARNING: missing example file \"$fname\"" 228 } 229 } 230 230 } 231 231 foreach label [lsort -dictionary [array names entries]] { 232 232 $itk_component(combo) choices insert end $entries($label) $label 233 233 } 234 234 … … 249 249 # be sure to clean up entries for this widget's download paths 250 250 foreach path $_dnpaths { 251 251 catch {unset _dnpath2state($this-$path)} 252 252 } 253 253 } … … 266 266 set i [lsearch -exact $args -check] 267 267 if {$i >= 0} { 268 269 268 set onlycheck 1 269 set args [lreplace $args $i $i] 270 270 } 271 271 272 272 if {[llength $args] == 1} { 273 274 275 276 277 278 279 273 if {$onlycheck} { 274 # someday we may add validation... 275 return 276 } 277 set newval [lindex $args 0] 278 $itk_component(combo) value $newval 279 return $newval 280 280 281 281 } elseif {[llength $args] != 0} { 282 282 error "wrong # args: should be \"value ?-check? ?newval?\"" 283 283 } 284 284 … … 298 298 set label [$_owner xml get $_path.about.label] 299 299 if {"" == $label} { 300 300 set label "Example" 301 301 } 302 302 return $label … … 327 327 set obj [$itk_component(combo) translate $newval] 328 328 if {$obj == "@upload"} { 329 330 331 332 333 334 335 336 337 329 set tool [Rappture::Tool::resources -appname] 330 Rappture::filexfer::upload \ 331 $tool $_uppath [itcl::code $this _uploadValue] 332 333 # put the combobox back to its last value 334 $itk_component(combo) component entry configure -state normal 335 $itk_component(combo) component entry delete 0 end 336 $itk_component(combo) component entry insert end $_lastlabel 337 $itk_component(combo) component entry configure -state disabled 338 338 339 339 } elseif {$obj == "@download"} { 340 341 342 343 344 345 346 347 348 349 350 340 if {[llength $_dnpaths] == 1} { 341 _downloadValues 342 } else { 343 $itk_component(hull).download activate $itk_component(combo) below 344 } 345 346 # put the combobox back to its last value 347 $itk_component(combo) component entry configure -state normal 348 $itk_component(combo) component entry delete 0 end 349 $itk_component(combo) component entry insert end $_lastlabel 350 $itk_component(combo) component entry configure -state disabled 351 351 352 352 } elseif {$obj == "---"} { 353 354 355 356 357 353 # put the combobox back to its last value 354 $itk_component(combo) component entry configure -state normal 355 $itk_component(combo) component entry delete 0 end 356 $itk_component(combo) component entry insert end $_lastlabel 357 $itk_component(combo) component entry configure -state disabled 358 358 } elseif {$obj != "" && $itk_option(-tool) != ""} { 359 360 361 362 363 364 359 if {("" != $_copyfrom) && ("" != $_copyto)} { 360 $obj copy $_copyto from $_copyfrom 361 } 362 $_owner xml put $_path.file $_label2file($newval) 363 $itk_option(-tool) load $obj 364 set _lastlabel $newval 365 365 } 366 366 … … 382 382 set obj [$itk_component(combo) translate $newval] 383 383 if {$obj != ""} { 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 384 if {$obj == "@upload"} { 385 append str "\n\nUse this option to upload data from your desktop." 386 } else { 387 set label [$obj get about.label] 388 if {[string length $label] > 0} { 389 append str "\n\n$label" 390 } 391 392 set desc [$obj get about.description] 393 if {[string length $desc] > 0} { 394 if {[string length $label] > 0} { 395 append str ":\n" 396 } else { 397 append str "\n\n" 398 } 399 append str $desc 400 } 401 } 402 402 } 403 403 return [string trim $str] … … 415 415 416 416 if {[info exists data(error)]} { 417 417 Rappture::Tooltip::cue $itk_component(combo) $data(error) 418 418 } 419 419 420 420 if {[info exists data(path)] && [info exists data(data)]} { 421 422 423 424 425 426 427 428 421 Rappture::Tooltip::cue hide ;# take down note about the popup window 422 $itk_option(-tool) valuefor $data(path) $data(data) 423 424 $itk_component(combo) component entry configure -state normal 425 $itk_component(combo) component entry delete 0 end 426 $itk_component(combo) component entry insert end "Uploaded data" 427 $itk_component(combo) component entry configure -state disabled 428 set _lastlabel "Uploaded data" 429 429 } 430 430 } … … 443 443 set mesg "" 444 444 foreach path $_dnpaths { 445 446 447 448 449 445 if {$_dnpath2state($this-$path)} { 446 set info [$itk_option(-tool) valuefor $path] 447 set mesg [Rappture::filexfer::download $info input.txt] 448 if {"" != $mesg} { break } 449 } 450 450 } 451 451 452 452 if {"" != $mesg} { 453 453 Rappture::Tooltip::cue $itk_component(combo) $mesg 454 454 } 455 455 } … … 460 460 itcl::configbody Rappture::Loader::tool { 461 461 if {[catch {$itk_option(-tool) isa Rappture::Tool} valid] || !$valid} { 462 462 error "object \"$itk_option(-tool)\" is not a Rappture Tool" 463 463 } 464 464 } … … 470 470 set valid {normal disabled} 471 471 if {[lsearch -exact $valid $itk_option(-state)] < 0} { 472 472 error "bad value \"$itk_option(-state)\": should be [join $valid {, }]" 473 473 } 474 474 $itk_component(combo) configure -state $itk_option(-state)
Note: See TracChangeset
for help on using the changeset viewer.