Ignore:
Timestamp:
Oct 18, 2010, 11:59:55 AM (14 years ago)
Author:
gah
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/blt4/gui/scripts/loader.tcl

    r1424 r1923  
    5959itcl::body Rappture::Loader::constructor {owner path args} {
    6060    if {[catch {$owner isa Rappture::ControlOwner} valid] != 0 || !$valid} {
    61         error "bad object \"$owner\": should be Rappture::ControlOwner"
     61        error "bad object \"$owner\": should be Rappture::ControlOwner"
    6262    }
    6363    set _owner $owner
     
    6565
    6666    itk_component add combo {
    67         Rappture::Combobox $itk_interior.combo -editable no
     67        Rappture::Combobox $itk_interior.combo -editable no
    6868    } {
    69         usual
    70         keep -width
     69        usual
     70        keep -width
    7171    }
    7272    pack $itk_component(combo) -expand yes -fill both
     
    7777    # example files are stored here
    7878    if {$itk_option(-tool) != ""} {
    79         set fdir [$itk_option(-tool) installdir]
     79        set fdir [$itk_option(-tool) installdir]
    8080    } else {
    81         set fdir "."
     81        set fdir "."
    8282    }
    8383    set defval [$_owner xml get $path.default]
     
    8989    set newfile ""
    9090    foreach comp [$_owner xml children -type new $path] {
    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         }
     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        }
    119119    }
    120120
     
    124124    #
    125125    foreach comp [$_owner xml children -type upload $path] {
    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
     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
    138138    }
    139139    if {[llength $_uppath] > 0} {
    140         $itk_component(combo) choices insert end \
    141             @upload [Rappture::filexfer::label upload]
     140        $itk_component(combo) choices insert end \
     141            @upload [Rappture::filexfer::label upload]
    142142    }
    143143
     
    148148    #
    149149    Rappture::Balloon $itk_component(hull).download \
    150         -title "Choose what to [string tolower [Rappture::filexfer::label downloadWord]]:"
     150        -title "Choose what to [string tolower [Rappture::filexfer::label downloadWord]]:"
    151151    set inner [$itk_component(hull).download component inner]
    152152
    153153    set i 0
    154154    foreach comp [$_owner xml children -type download $path] {
    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         }
     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        }
    168168    }
    169169    button $inner.go -text [Rappture::filexfer::label download] \
    170         -command [itcl::code $this _downloadValues]
     170        -command [itcl::code $this _downloadValues]
    171171    pack $inner.go -side bottom -padx 50 -pady {4 2}
    172172
    173173    if {[llength $_dnpaths] > 0} {
    174         $itk_component(combo) choices insert end \
    175             @download [Rappture::filexfer::label download]
     174        $itk_component(combo) choices insert end \
     175            @download [Rappture::filexfer::label download]
    176176    }
    177177
    178178    if {[$itk_component(combo) choices size] > 0} {
    179         $itk_component(combo) choices insert end "---" "---"
     179        $itk_component(combo) choices insert end "---" "---"
    180180    }
    181181
     
    186186    set flist ""
    187187    foreach comp [$_owner xml children -type example $path] {
    188         lappend flist [$_owner xml get $path.$comp]
     188        lappend flist [$_owner xml get $path.$comp]
    189189    }
    190190
    191191    # if there are no examples, then look for *.xml
    192192    if {[llength $flist] == 0} {
    193         set flist *.xml
     193        set flist *.xml
    194194    }
    195195
     
    197197    set _counter 0
    198198    foreach ftail $flist {
    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         }
     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        }
    230230    }
    231231    foreach label [lsort -dictionary [array names entries]] {
    232         $itk_component(combo) choices insert end $entries($label) $label
     232        $itk_component(combo) choices insert end $entries($label) $label
    233233    }
    234234
     
    249249    # be sure to clean up entries for this widget's download paths
    250250    foreach path $_dnpaths {
    251         catch {unset _dnpath2state($this-$path)}
     251        catch {unset _dnpath2state($this-$path)}
    252252    }
    253253}
     
    266266    set i [lsearch -exact $args -check]
    267267    if {$i >= 0} {
    268         set onlycheck 1
    269         set args [lreplace $args $i $i]
     268        set onlycheck 1
     269        set args [lreplace $args $i $i]
    270270    }
    271271
    272272    if {[llength $args] == 1} {
    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
     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
    280280
    281281    } elseif {[llength $args] != 0} {
    282         error "wrong # args: should be \"value ?-check? ?newval?\""
     282        error "wrong # args: should be \"value ?-check? ?newval?\""
    283283    }
    284284
     
    298298    set label [$_owner xml get $_path.about.label]
    299299    if {"" == $label} {
    300         set label "Example"
     300        set label "Example"
    301301    }
    302302    return $label
     
    327327    set obj [$itk_component(combo) translate $newval]
    328328    if {$obj == "@upload"} {
    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
     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
    338338
    339339    } elseif {$obj == "@download"} {
    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
     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
    351351
    352352    } elseif {$obj == "---"} {
    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
     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
    358358    } elseif {$obj != "" && $itk_option(-tool) != ""} {
    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
     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
    365365    }
    366366
     
    382382    set obj [$itk_component(combo) translate $newval]
    383383    if {$obj != ""} {
    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         }
     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        }
    402402    }
    403403    return [string trim $str]
     
    415415
    416416    if {[info exists data(error)]} {
    417         Rappture::Tooltip::cue $itk_component(combo) $data(error)
     417        Rappture::Tooltip::cue $itk_component(combo) $data(error)
    418418    }
    419419
    420420    if {[info exists data(path)] && [info exists data(data)]} {
    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"
     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"
    429429    }
    430430}
     
    443443    set mesg ""
    444444    foreach path $_dnpaths {
    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         }
     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        }
    450450    }
    451451
    452452    if {"" != $mesg} {
    453         Rappture::Tooltip::cue $itk_component(combo) $mesg
     453        Rappture::Tooltip::cue $itk_component(combo) $mesg
    454454    }
    455455}
     
    460460itcl::configbody Rappture::Loader::tool {
    461461    if {[catch {$itk_option(-tool) isa Rappture::Tool} valid] || !$valid} {
    462         error "object \"$itk_option(-tool)\" is not a Rappture Tool"
     462        error "object \"$itk_option(-tool)\" is not a Rappture Tool"
    463463    }
    464464}
     
    470470    set valid {normal disabled}
    471471    if {[lsearch -exact $valid $itk_option(-state)] < 0} {
    472         error "bad value \"$itk_option(-state)\": should be [join $valid {, }]"
     472        error "bad value \"$itk_option(-state)\": should be [join $valid {, }]"
    473473    }
    474474    $itk_component(combo) configure -state $itk_option(-state)
Note: See TracChangeset for help on using the changeset viewer.