Changeset 1342 for trunk/gui/scripts/loader.tcl
- Timestamp:
- Mar 18, 2009, 2:59:21 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/loader.tcl
r1269 r1342 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 126 foreach tcomp [$_owner xml children -type to $path.$comp] { 127 set topath [$_owner xml get $path.$comp.$tcomp] 128 set label [$_owner xml get $topath.about.label] 129 set desc [$_owner xml get $topath.about.description] 130 lappend _uppath $topath $label $desc 131 } 132 break 133 133 } 134 134 if {[llength $_uppath] > 0} { 135 136 135 $itk_component(combo) choices insert end \ 136 @upload [Rappture::filexfer::label upload] 137 137 } 138 138 … … 143 143 # 144 144 Rappture::Balloon $itk_component(hull).download \ 145 145 -title "Choose what to [string tolower [Rappture::filexfer::label downloadWord]]:" 146 146 set inner [$itk_component(hull).download component inner] 147 147 148 148 set i 0 149 149 foreach comp [$_owner xml children -type download $path] { 150 151 152 153 154 155 156 157 158 159 160 161 162 150 foreach dcomp [$_owner xml children -type from $path.$comp] { 151 set frompath [$_owner xml get $path.$comp.$dcomp] 152 if {"" != $frompath} { 153 lappend _dnpaths $frompath 154 set _dnpath2state($this-$frompath) [expr {$i == 0}] 155 156 set label [$_owner xml get $frompath.about.label] 157 checkbutton $inner.cb$i -text $label \ 158 -variable ::Rappture::Loader::_dnpath2state($this-$frompath) 159 pack $inner.cb$i -anchor w 160 incr i 161 } 162 } 163 163 } 164 164 button $inner.go -text [Rappture::filexfer::label download] \ 165 165 -command [itcl::code $this _downloadValues] 166 166 pack $inner.go -side bottom -padx 50 -pady {4 2} 167 167 168 168 if {[llength $_dnpaths] > 0} { 169 170 169 $itk_component(combo) choices insert end \ 170 @download [Rappture::filexfer::label download] 171 171 } 172 172 173 173 if {[$itk_component(combo) choices size] > 0} { 174 174 $itk_component(combo) choices insert end "---" "---" 175 175 } 176 176 … … 181 181 set flist "" 182 182 foreach comp [$_owner xml children -type example $path] { 183 183 lappend flist [$_owner xml get $path.$comp] 184 184 } 185 185 186 186 # if there are no examples, then look for *.xml 187 187 if {[llength $flist] == 0} { 188 188 set flist *.xml 189 189 } 190 190 … … 192 192 set _counter 0 193 193 foreach ftail $flist { 194 195 196 197 198 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 194 set fpath [file join $fdir examples $ftail] 195 196 foreach fname [glob -nocomplain $fpath] { 197 if {[string equal $fname $newfile]} { 198 continue 199 } 200 if {[file exists $fname]} { 201 if {[catch {set obj [Rappture::library $fname]} result]} { 202 puts stderr "WARNING: can't load example file \"$fname\"" 203 puts stderr " $result" 204 } else { 205 set label [$obj get about.label] 206 if {$label == ""} { 207 set label "Example #[incr _counter]" 208 } 209 210 # if this is new, add it to the label->file hash 211 if {![info exists entries($label)]} { 212 set entries($label) $obj 213 set _label2file($label) [file tail $fname] 214 } 215 216 # translate default file name => default label 217 if {[string equal $defval [file tail $fname]]} { 218 $_owner xml put $path.default $label 219 } 220 } 221 } else { 222 puts stderr "WARNING: missing example file \"$fname\"" 223 } 224 } 225 225 } 226 226 foreach label [lsort -dictionary [array names entries]] { 227 227 $itk_component(combo) choices insert end $entries($label) $label 228 228 } 229 229 … … 244 244 # be sure to clean up entries for this widget's download paths 245 245 foreach path $_dnpaths { 246 246 catch {unset _dnpath2state($this-$path)} 247 247 } 248 248 } … … 261 261 set i [lsearch -exact $args -check] 262 262 if {$i >= 0} { 263 264 263 set onlycheck 1 264 set args [lreplace $args $i $i] 265 265 } 266 266 267 267 if {[llength $args] == 1} { 268 269 270 271 272 273 274 268 if {$onlycheck} { 269 # someday we may add validation... 270 return 271 } 272 set newval [lindex $args 0] 273 $itk_component(combo) value $newval 274 return $newval 275 275 276 276 } elseif {[llength $args] != 0} { 277 277 error "wrong # args: should be \"value ?-check? ?newval?\"" 278 278 } 279 279 … … 293 293 set label [$_owner xml get $_path.about.label] 294 294 if {"" == $label} { 295 295 set label "Example" 296 296 } 297 297 return $label … … 322 322 set obj [$itk_component(combo) translate $newval] 323 323 if {$obj == "@upload"} { 324 325 326 327 328 329 330 331 332 324 set tool [Rappture::Tool::resources -appname] 325 Rappture::filexfer::upload \ 326 $tool $_uppath [itcl::code $this _uploadValue] 327 328 # put the combobox back to its last value 329 $itk_component(combo) component entry configure -state normal 330 $itk_component(combo) component entry delete 0 end 331 $itk_component(combo) component entry insert end $_lastlabel 332 $itk_component(combo) component entry configure -state disabled 333 333 334 334 } elseif {$obj == "@download"} { 335 336 337 338 339 340 341 342 343 344 345 335 if {[llength $_dnpaths] == 1} { 336 _downloadValues 337 } else { 338 $itk_component(hull).download activate $itk_component(combo) below 339 } 340 341 # put the combobox back to its last value 342 $itk_component(combo) component entry configure -state normal 343 $itk_component(combo) component entry delete 0 end 344 $itk_component(combo) component entry insert end $_lastlabel 345 $itk_component(combo) component entry configure -state disabled 346 346 347 347 } elseif {$obj == "---"} { 348 349 350 351 352 348 # put the combobox back to its last value 349 $itk_component(combo) component entry configure -state normal 350 $itk_component(combo) component entry delete 0 end 351 $itk_component(combo) component entry insert end $_lastlabel 352 $itk_component(combo) component entry configure -state disabled 353 353 } elseif {$obj != "" && $itk_option(-tool) != ""} { 354 355 356 357 358 359 354 if {("" != $_copyfrom) && ("" != $_copyto)} { 355 $obj copy $_copyto from $_copyfrom 356 } 357 $_owner xml put $_path.file $_label2file($newval) 358 $itk_option(-tool) load $obj 359 set _lastlabel $newval 360 360 } 361 361 … … 377 377 set obj [$itk_component(combo) translate $newval] 378 378 if {$obj != ""} { 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 379 if {$obj == "@upload"} { 380 append str "\n\nUse this option to upload data from your desktop." 381 } else { 382 set label [$obj get about.label] 383 if {[string length $label] > 0} { 384 append str "\n\n$label" 385 } 386 387 set desc [$obj get about.description] 388 if {[string length $desc] > 0} { 389 if {[string length $label] > 0} { 390 append str ":\n" 391 } else { 392 append str "\n\n" 393 } 394 append str $desc 395 } 396 } 397 397 } 398 398 return [string trim $str] … … 410 410 411 411 if {[info exists data(error)]} { 412 412 Rappture::Tooltip::cue $itk_component(combo) $data(error) 413 413 } 414 414 415 415 if {[info exists data(path)] && [info exists data(data)]} { 416 417 418 419 420 421 422 423 416 Rappture::Tooltip::cue hide ;# take down note about the popup window 417 $itk_option(-tool) valuefor $data(path) $data(data) 418 419 $itk_component(combo) component entry configure -state normal 420 $itk_component(combo) component entry delete 0 end 421 $itk_component(combo) component entry insert end "Uploaded data" 422 $itk_component(combo) component entry configure -state disabled 423 set _lastlabel "Uploaded data" 424 424 } 425 425 } … … 438 438 set mesg "" 439 439 foreach path $_dnpaths { 440 441 442 443 444 440 if {$_dnpath2state($this-$path)} { 441 set info [$itk_option(-tool) valuefor $path] 442 set mesg [Rappture::filexfer::download $info input.txt] 443 if {"" != $mesg} { break } 444 } 445 445 } 446 446 447 447 if {"" != $mesg} { 448 448 Rappture::Tooltip::cue $itk_component(combo) $mesg 449 449 } 450 450 } … … 455 455 itcl::configbody Rappture::Loader::tool { 456 456 if {[catch {$itk_option(-tool) isa Rappture::Tool} valid] || !$valid} { 457 457 error "object \"$itk_option(-tool)\" is not a Rappture Tool" 458 458 } 459 459 } … … 465 465 set valid {normal disabled} 466 466 if {[lsearch -exact $valid $itk_option(-state)] < 0} { 467 467 error "bad value \"$itk_option(-state)\": should be [join $valid {, }]" 468 468 } 469 469 $itk_component(combo) configure -state $itk_option(-state)
Note: See TracChangeset
for help on using the changeset viewer.