Ignore:
Timestamp:
Mar 18, 2009, 2:59:21 PM (16 years ago)
Author:
gah
Message:

preliminary HQ output from molvisviewer; unexpand tabs; all jpeg generation at 100%

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/scripts/loader.tcl

    r1269 r1342  
    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             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
     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
    133133    }
    134134    if {[llength $_uppath] > 0} {
    135         $itk_component(combo) choices insert end \
    136             @upload [Rappture::filexfer::label upload]
     135        $itk_component(combo) choices insert end \
     136            @upload [Rappture::filexfer::label upload]
    137137    }
    138138
     
    143143    #
    144144    Rappture::Balloon $itk_component(hull).download \
    145         -title "Choose what to [string tolower [Rappture::filexfer::label downloadWord]]:"
     145        -title "Choose what to [string tolower [Rappture::filexfer::label downloadWord]]:"
    146146    set inner [$itk_component(hull).download component inner]
    147147
    148148    set i 0
    149149    foreach comp [$_owner xml children -type download $path] {
    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         }
     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        }
    163163    }
    164164    button $inner.go -text [Rappture::filexfer::label download] \
    165         -command [itcl::code $this _downloadValues]
     165        -command [itcl::code $this _downloadValues]
    166166    pack $inner.go -side bottom -padx 50 -pady {4 2}
    167167
    168168    if {[llength $_dnpaths] > 0} {
    169         $itk_component(combo) choices insert end \
    170             @download [Rappture::filexfer::label download]
     169        $itk_component(combo) choices insert end \
     170            @download [Rappture::filexfer::label download]
    171171    }
    172172
    173173    if {[$itk_component(combo) choices size] > 0} {
    174         $itk_component(combo) choices insert end "---" "---"
     174        $itk_component(combo) choices insert end "---" "---"
    175175    }
    176176
     
    181181    set flist ""
    182182    foreach comp [$_owner xml children -type example $path] {
    183         lappend flist [$_owner xml get $path.$comp]
     183        lappend flist [$_owner xml get $path.$comp]
    184184    }
    185185
    186186    # if there are no examples, then look for *.xml
    187187    if {[llength $flist] == 0} {
    188         set flist *.xml
     188        set flist *.xml
    189189    }
    190190
     
    192192    set _counter 0
    193193    foreach ftail $flist {
    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         }
     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        }
    225225    }
    226226    foreach label [lsort -dictionary [array names entries]] {
    227         $itk_component(combo) choices insert end $entries($label) $label
     227        $itk_component(combo) choices insert end $entries($label) $label
    228228    }
    229229
     
    244244    # be sure to clean up entries for this widget's download paths
    245245    foreach path $_dnpaths {
    246         catch {unset _dnpath2state($this-$path)}
     246        catch {unset _dnpath2state($this-$path)}
    247247    }
    248248}
     
    261261    set i [lsearch -exact $args -check]
    262262    if {$i >= 0} {
    263         set onlycheck 1
    264         set args [lreplace $args $i $i]
     263        set onlycheck 1
     264        set args [lreplace $args $i $i]
    265265    }
    266266
    267267    if {[llength $args] == 1} {
    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
     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
    275275
    276276    } elseif {[llength $args] != 0} {
    277         error "wrong # args: should be \"value ?-check? ?newval?\""
     277        error "wrong # args: should be \"value ?-check? ?newval?\""
    278278    }
    279279
     
    293293    set label [$_owner xml get $_path.about.label]
    294294    if {"" == $label} {
    295         set label "Example"
     295        set label "Example"
    296296    }
    297297    return $label
     
    322322    set obj [$itk_component(combo) translate $newval]
    323323    if {$obj == "@upload"} {
    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
     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
    333333
    334334    } elseif {$obj == "@download"} {
    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
     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
    346346
    347347    } elseif {$obj == "---"} {
    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
     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
    353353    } elseif {$obj != "" && $itk_option(-tool) != ""} {
    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
     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
    360360    }
    361361
     
    377377    set obj [$itk_component(combo) translate $newval]
    378378    if {$obj != ""} {
    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         }
     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        }
    397397    }
    398398    return [string trim $str]
     
    410410
    411411    if {[info exists data(error)]} {
    412         Rappture::Tooltip::cue $itk_component(combo) $data(error)
     412        Rappture::Tooltip::cue $itk_component(combo) $data(error)
    413413    }
    414414
    415415    if {[info exists data(path)] && [info exists data(data)]} {
    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"
     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"
    424424    }
    425425}
     
    438438    set mesg ""
    439439    foreach path $_dnpaths {
    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         }
     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        }
    445445    }
    446446
    447447    if {"" != $mesg} {
    448         Rappture::Tooltip::cue $itk_component(combo) $mesg
     448        Rappture::Tooltip::cue $itk_component(combo) $mesg
    449449    }
    450450}
     
    455455itcl::configbody Rappture::Loader::tool {
    456456    if {[catch {$itk_option(-tool) isa Rappture::Tool} valid] || !$valid} {
    457         error "object \"$itk_option(-tool)\" is not a Rappture Tool"
     457        error "object \"$itk_option(-tool)\" is not a Rappture Tool"
    458458    }
    459459}
     
    465465    set valid {normal disabled}
    466466    if {[lsearch -exact $valid $itk_option(-state)] < 0} {
    467         error "bad value \"$itk_option(-state)\": should be [join $valid {, }]"
     467        error "bad value \"$itk_option(-state)\": should be [join $valid {, }]"
    468468    }
    469469    $itk_component(combo) configure -state $itk_option(-state)
Note: See TracChangeset for help on using the changeset viewer.