Changeset 1077 for trunk/gui


Ignore:
Timestamp:
Jul 23, 2008, 8:00:21 PM (16 years ago)
Author:
mmc
Message:

Fixed the Rappture::filexfer facility so that if importfile/exportfile
commands are not available, it reverts to local Load/Save? operations.
This is important for applications that are not deployed in a hub, but
used instead in a standard desktop environment.

Location:
trunk/gui/scripts
Files:
9 edited

Legend:

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

    r1003 r1077  
    203203        "@[itcl::code $this _resultTooltip]"
    204204
     205    $itk_component(resultselector) choices insert end \
     206        --- "---"
     207
     208    itk_component add download {
     209        button $w.top.dl -image [Rappture::icon download] -anchor e \
     210            -borderwidth 1 -relief flat -overrelief raised \
     211            -command [itcl::code $this download start $w.top.dl]
     212    }
     213    pack $itk_component(download) -side right -padx {4 0}
     214    bind $itk_component(download) <Enter> \
     215        [itcl::code $this download coming]
     216
     217    $itk_component(resultselector) choices insert end \
     218        @download [Rappture::filexfer::label download]
     219
    205220    if {[Rappture::filexfer::enabled]} {
    206         $itk_component(resultselector) choices insert end \
    207             --- "---"
    208         $itk_component(resultselector) choices insert end \
    209             @download "Download..."
    210 
    211         itk_component add download {
    212             button $w.top.dl -image [Rappture::icon download] -anchor e \
    213                 -borderwidth 1 -relief flat -overrelief raised \
    214                 -command [itcl::code $this download start $w.top.dl]
    215         }
    216         pack $itk_component(download) -side right -padx {4 0}
    217221        Rappture::Tooltip::for $itk_component(download) "Downloads the current result to a new web browser window on your desktop.  From there, you can easily print or save results.
    218222
    219223NOTE:  Your web browser must allow pop-ups from this site.  If your output does not appear, look for a 'pop-up blocked' message and enable pop-ups."
    220 
    221         bind $itk_component(download) <Enter> \
    222             [itcl::code $this download coming]
     224    } else {
     225        Rappture::Tooltip::for $itk_component(download) "Saves the current result to a file on your desktop."
    223226    }
    224227
     
    550553    set _plotlist ""
    551554
    552     if {[Rappture::filexfer::enabled]} {
    553         $itk_component(resultselector) choices insert end \
    554             --- "---"
    555         $itk_component(resultselector) choices insert end \
    556             @download "Download..."
    557     }
     555    $itk_component(resultselector) choices insert end --- "---"
     556    $itk_component(resultselector) choices insert end \
     557        @download [Rappture::filexfer::label download]
    558558    set _lastlabel ""
    559559
     
    581581# ----------------------------------------------------------------------
    582582itcl::body Rappture::Analyzer::download {option args} {
    583     if {[Rappture::filexfer::enabled]} {
    584         set title [$itk_component(resultselector) value]
    585         set page [$itk_component(resultselector) translate $title]
    586 
    587         switch -- $option {
    588             coming {
    589                 #
    590                 # Warn result that a download is coming, in case
    591                 # it needs to take a screen snap.
    592                 #
    593                 if {![regexp {^(|@download|---)$} $page]} {
    594                     set f [$itk_component(resultpages) page $page]
    595                     $f.rviewer download coming
     583    set title [$itk_component(resultselector) value]
     584    set page [$itk_component(resultselector) translate $title]
     585
     586    switch -- $option {
     587        coming {
     588            #
     589            # Warn result that a download is coming, in case
     590            # it needs to take a screen snap.
     591            #
     592            if {![regexp {^(|@download|---)$} $page]} {
     593                set f [$itk_component(resultpages) page $page]
     594                $f.rviewer download coming
     595            }
     596        }
     597        controls {
     598            # no controls for this download yet
     599            return ""
     600        }
     601        start {
     602            set widget $itk_component(download)
     603            if {[llength $args] > 0} {
     604                set widget [lindex $args 0]
     605                if {[catch {winfo class $widget}]} {
     606                    set widget $itk_component(download)
    596607                }
    597608            }
    598             controls {
    599                 # no controls for this download yet
    600                 return ""
    601             }
    602             start {
    603                 set widget $itk_component(download)
    604                 if {[llength $args] > 0} {
    605                     set widget [lindex $args 0]
    606                     if {[catch {winfo class $widget}]} {
    607                         set widget $itk_component(download)
     609            #
     610            # See if this download has any controls.  If so, then
     611            # post them now and let the user continue the download
     612            # after selecting a file format.
     613            #
     614            if {$page != ""} {
     615                set ext ""
     616                set f [$itk_component(resultpages) page $page]
     617                set popup [$f.rviewer download controls \
     618                    [itcl::code $this download now $widget]]
     619
     620                if {"" != $popup} {
     621                    $popup activate $widget below
     622                } else {
     623                    download now $widget
     624                }
     625            } else {
     626                # this shouldn't happen
     627                set file error.html
     628                set data "<h1>Not Found</h1>There is no result selected."
     629            }
     630        }
     631        now {
     632            set widget $itk_component(download)
     633            if {[llength $args] > 0} {
     634                set widget [lindex $args 0]
     635                if {[catch {winfo class $widget}]} {
     636                    set widget $itk_component(download)
     637                }
     638            }
     639            #
     640            # Perform the actual download.
     641            #
     642            if {$page != ""} {
     643                set ext ""
     644                set f [$itk_component(resultpages) page $page]
     645                foreach {ext data} [$f.rviewer download now] break
     646                if {"" == $ext} {
     647                    if {"" != $widget} {
     648                        Rappture::Tooltip::cue $widget \
     649                            "Can't download this result."
    608650                    }
     651                    return
    609652                }
    610                 #
    611                 # See if this download has any controls.  If so, then
    612                 # post them now and let the user continue the download
    613                 # after selecting a file format.
    614                 #
    615                 if {$page != ""} {
    616                     set ext ""
    617                     set f [$itk_component(resultpages) page $page]
    618                     set popup [$f.rviewer download controls \
    619                         [itcl::code $this download now $widget]]
    620 
    621                     if {"" != $popup} {
    622                         $popup activate $widget below
    623                     } else {
    624                         download now $widget
    625                     }
    626                 } else {
    627                     # this shouldn't happen
    628                     set file error.html
    629                     set data "<h1>Not Found</h1>There is no result selected."
    630                 }
    631             }
    632             now {
    633                 set widget $itk_component(download)
    634                 if {[llength $args] > 0} {
    635                     set widget [lindex $args 0]
    636                     if {[catch {winfo class $widget}]} {
    637                         set widget $itk_component(download)
    638                     }
    639                 }
    640                 #
    641                 # Perform the actual download.
    642                 #
    643                 if {$page != ""} {
    644                     set ext ""
    645                     set f [$itk_component(resultpages) page $page]
    646                     foreach {ext data} [$f.rviewer download now] break
    647                     if {"" == $ext} {
    648                         if {"" != $widget} {
    649                             Rappture::Tooltip::cue $widget \
    650                                 "Can't download this result."
    651                         }
    652                         return
    653                     }
    654                     regsub -all {[\ -\/\:-\@\{-\~]} $title {} title
    655                     set file "$title$ext"
    656                 } else {
    657                     # this shouldn't happen
    658                     set file error.html
    659                     set data "<h1>Not Found</h1>There is no result selected."
    660                 }
    661 
    662                 set mesg [Rappture::filexfer::download $data $file]
    663                 if {[string length $mesg] > 0} {
    664                     Rappture::Tooltip::cue $widget $mesg
    665                 }
    666             }
    667             default {
    668                 error "bad option \"$option\": should be coming, controls, now, start"
    669             }
     653                regsub -all {[\ -\/\:-\@\{-\~]} $title {} title
     654                set file "$title$ext"
     655            } else {
     656                # this shouldn't happen
     657                set file error.html
     658                set data "<h1>Not Found</h1>There is no result selected."
     659            }
     660
     661            set mesg [Rappture::filexfer::download $data $file]
     662            if {[string length $mesg] > 0} {
     663                Rappture::Tooltip::cue $widget $mesg
     664            }
     665        }
     666        default {
     667            error "bad option \"$option\": should be coming, controls, now, start"
    670668        }
    671669    }
  • trunk/gui/scripts/bugreport.tcl

    r743 r1077  
    8383    }
    8484
    85     if {[Rappture::filexfer::enabled]} {
    86         .bugreport.details.cntls.dload configure -state normal
    87     } else {
    88         .bugreport.details.cntls.dload configure -state disabled
    89     }
    90 
    9185    set w [winfo reqwidth .bugreport]
    9286    set h [winfo reqheight .bugreport]
     
    180174# ----------------------------------------------------------------------
    181175proc Rappture::bugreport::download {} {
    182     if {[Rappture::filexfer::enabled]} {
    183         set info [.bugreport.details.info.text get 1.0 end]
    184         Rappture::filexfer::download $info bugreport.txt
    185     }
     176    set info [.bugreport.details.info.text get 1.0 end]
     177    Rappture::filexfer::download $info bugreport.txt
    186178}
    187179
  • trunk/gui/scripts/energyLevels.tcl

    r766 r1077  
    423423            if {![winfo exists .energyresultdownload]} {
    424424                # if we haven't created the popup yet, do it now
    425                 Rappture::Balloon $popup -title "Download as..."
     425                Rappture::Balloon $popup \
     426                    -title "[Rappture::filexfer::label downloadWord] as..."
    426427                set inner [$popup component inner]
    427428                label $inner.summary -text "" -anchor w
     
    435436                    -value pdf
    436437                pack $inner.pdf -anchor w
    437                 button $inner.go -text "Download Now" \
     438                button $inner.go -text [Rappture::filexfer::label download] \
    438439                    -command [lindex $args 0]
    439440                pack $inner.go -pady 4
     
    443444            set num [llength [get]]
    444445            set num [expr {($num == 1) ? "1 result" : "$num results"}]
    445             $inner.summary configure -text "Download $num in the following format:"
     446            $inner.summary configure -text "[Rappture::filexfer::label downloadWord] $num in the following format:"
    446447            update idletasks ;# fix initial sizes
    447448            return $popup
  • trunk/gui/scripts/filexfer.tcl

    r683 r1077  
    6666# If so, then the GUI will provide "Download..." and other filexfer
    6767# options.  If not, then Rappture must be running within an
    68 # environment that doesn't support it.
     68# environment that doesn't support it.  As a backup, Rappture provides
     69# file load/save operations instead.
    6970# ----------------------------------------------------------------------
    7071proc Rappture::filexfer::enabled {} {
     
    7273    return $enabled
    7374}
     75
     76# ----------------------------------------------------------------------
     77# USAGE: Rappture::filexfer::label upload|download
     78#
     79# Clients use this to query the proper label for an "upload" or
     80# "download" opertion.  These are usually "Upload..." and "Download",
     81# but could change to "Load File..." and "Save As..." for applications
     82# in desktop mode.
     83# ----------------------------------------------------------------------
     84proc Rappture::filexfer::label {operation} {
     85    switch -- $operation {
     86        upload {
     87            if {[Rappture::filexfer::enabled]} {
     88                return "Upload..."
     89            } else {
     90                return "Load File..."
     91            }
     92        }
     93        download {
     94            if {[Rappture::filexfer::enabled]} {
     95                return "Download"
     96            } else {
     97                return "Save As..."
     98            }
     99        }
     100        downloadWord {
     101            if {[Rappture::filexfer::enabled]} {
     102                return "Download"
     103            } else {
     104                return "Save"
     105            }
     106        }
     107        default {
     108            error "bad option \"$operation\": should be upload, download, or downloadWord"
     109        }
     110    }
     111}
     112
    74113
    75114# ----------------------------------------------------------------------
     
    153192            uplevel #0 [list $callback error $job(error)]
    154193        }
     194    } else {
     195        #
     196        # Filexfer via importfile is disabled.  This tool must be
     197        # running in a desktop environment.  Instead of uploading,
     198        # perform a "Load File..." operation with a standard file
     199        # selection dialog.
     200        #
     201        set i 0
     202        foreach {path label desc} $controlList {
     203            set file [tk_getOpenFile -title "Load File: $label"]
     204            if {"" != $file} {
     205                set cmds {
     206                    # try to read first as binary
     207                    set fid [open $file r]
     208                    fconfigure $fid -encoding binary -translation binary
     209                    set info [read $fid]
     210                    close $fid
     211                    if {![Rappture::encoding::is binary $info]} {
     212                        # not binary? then re-read and translate CR/LF
     213                        set fid [open $file r]
     214                        set info [read $fid]
     215                        close $fid
     216                    }
     217                }
     218                if {[catch $cmds err]} {
     219                    uplevel #0 [list $callback error "Error loading file [file tail $file]: $err"]
     220                } else {
     221                    uplevel #0 [list $callback path $path data $info]
     222                }
     223            }
     224        }
    155225    }
    156226}
     
    224294            return $Rappture::filexfer::job(error)
    225295        }
     296    } else {
     297        #
     298        # Filexfer via exportfile is disabled.  This tool must be
     299        # running in a desktop environment.  Instead of downloading,
     300        # perform a "Save As..." operation with a standard file
     301        # selection dialog.
     302        #
     303        set file [tk_getSaveFile -title "Save As..." -initialfile $filename]
     304        if {"" != $file} {
     305            if {[catch {
     306                set fid [open $file w]
     307                if {[Rappture::encoding::is binary $string]} {
     308                    fconfigure $fid -encoding binary -translation binary
     309                    puts -nonewline $fid $string
     310                } else {
     311                    puts $fid $string
     312                }
     313                close $fid
     314            } result]} {
     315                return $result
     316            }
     317        }
    226318    }
    227319    return ""
  • trunk/gui/scripts/historesult.tcl

    r878 r1077  
    429429            if {![winfo exists .histogram_result_download]} {
    430430                # if we haven't created the popup yet, do it now
    431                 Rappture::Balloon $popup -title "Download as..."
     431                Rappture::Balloon $popup -title "[Rappture::filexfer::label downloadWord] as..."
    432432                set inner [$popup component inner]
    433433                label $inner.summary -text "" -anchor w
     
    441441                    -value pdf
    442442                pack $inner.pdf -anchor w
    443                 button $inner.go -text "Download Now" \
     443                button $inner.go -text [Rappture::filexfer::label download] \
    444444                    -command [lindex $args 0]
    445445                pack $inner.go -pady 4
     
    449449            set num [llength [get]]
    450450            set num [expr {($num == 1) ? "1 result" : "$num results"}]
    451             $inner.summary configure -text "Download $num in the following format:"
     451            $inner.summary configure -text "[Rappture::filexfer::label downloadWord] $num in the following format:"
    452452            update idletasks ;# fix initial sizes
    453453            return $popup
  • trunk/gui/scripts/loader.tcl

    r746 r1077  
    121121    }
    122122    if {[llength $_uppath] > 0} {
    123         $itk_component(combo) choices insert end @upload "Upload..."
     123        $itk_component(combo) choices insert end \
     124            @upload [Rappture::filexfer::label upload]
    124125    }
    125126
     
    130131    #
    131132    Rappture::Balloon $itk_component(hull).download \
    132         -title "Choose what to download:"
     133        -title "Choose what to [string tolower [Rappture::filexfer::label downloadWord]]:"
    133134    set inner [$itk_component(hull).download component inner]
    134135
     
    149150        }
    150151    }
    151     button $inner.go -text "Download" \
     152    button $inner.go -text [Rappture::filexfer::label download] \
    152153        -command [itcl::code $this _downloadValues]
    153154    pack $inner.go -side bottom -padx 50 -pady {4 2}
    154155
    155156    if {[llength $_dnpaths] > 0} {
    156         $itk_component(combo) choices insert end @download "Download..."
     157        $itk_component(combo) choices insert end \
     158            @download [Rappture::filexfer::label download]
    157159    }
    158160
     
    304306    set obj [$itk_component(combo) translate $newval]
    305307    if {$obj == "@upload"} {
    306         if {[Rappture::filexfer::enabled]} {
    307             set tool [Rappture::Tool::resources -appname]
    308             Rappture::filexfer::upload \
    309                 $tool $_uppath [itcl::code $this _uploadValue]
    310         }
     308        set tool [Rappture::Tool::resources -appname]
     309        Rappture::filexfer::upload \
     310            $tool $_uppath [itcl::code $this _uploadValue]
    311311
    312312        # put the combobox back to its last value
     
    417417
    418418    set mesg ""
    419     if {[Rappture::filexfer::enabled]} {
    420         foreach path $_dnpaths {
    421             if {$_dnpath2state($this-$path)} {
    422                 set info [$itk_option(-tool) valuefor $path]
    423                 set mesg [Rappture::filexfer::download $info input.txt]
    424                 if {"" != $mesg} { break }
    425             }
     419    foreach path $_dnpaths {
     420        if {$_dnpath2state($this-$path)} {
     421            set info [$itk_option(-tool) valuefor $path]
     422            set mesg [Rappture::filexfer::download $info input.txt]
     423            if {"" != $mesg} { break }
    426424        }
    427425    }
  • trunk/gui/scripts/numberresult.tcl

    r768 r1077  
    489489            if {![winfo exists .xyresultdownload]} {
    490490                # if we haven't created the popup yet, do it now
    491                 Rappture::Balloon $popup -title "Download as..."
     491                Rappture::Balloon $popup -title "[Rappture::filexfer::label downloadWord] as..."
    492492                set inner [$popup component inner]
    493493                label $inner.summary -text "" -anchor w
     
    501501                    -value pdf
    502502                pack $inner.pdf -anchor w
    503                 button $inner.go -text "Download Now" \
     503                button $inner.go -text [Rappture::filexfer::label download] \
    504504                    -command [lindex $args 0]
    505505                pack $inner.go -pady 4
     
    509509            set num [llength [get]]
    510510            set num [expr {($num == 1) ? "1 result" : "$num results"}]
    511             $inner.summary configure -text "Download $num in the following format:"
     511            $inner.summary configure -text "[Rappture::filexfer::label downloadWord] $num in the following format:"
    512512            update idletasks ;# fix initial sizes
    513513            return $popup
  • trunk/gui/scripts/textentry.tcl

    r724 r1077  
    311311            $itk_component(tmenu) add command -label "Select All" -accelerator "^A" -command [list $itk_component(text) tag add sel 1.0 end]
    312312            $itk_component(tmenu) add separator
    313             $itk_component(tmenu) add command -label "Upload..." \
     313
     314            $itk_component(tmenu) add command \
     315                -label [Rappture::filexfer::label upload] \
    314316                -command [itcl::code $this _uploadValue -start]
    315             $itk_component(tmenu) add command -label "Download" \
     317            $itk_component(tmenu) add command \
     318                -label [Rappture::filexfer::label download] \
    316319                -command [itcl::code $this _downloadValue]
     320
    317321            bind $itk_component(text) <<PopupMenu>> \
    318322                [itcl::code $this _edit menu tmenu %X %Y]
  • trunk/gui/scripts/xyresult.tcl

    r1040 r1077  
    430430            if {![winfo exists .xyresultdownload]} {
    431431                # if we haven't created the popup yet, do it now
    432                 Rappture::Balloon $popup -title "Download as..."
     432                Rappture::Balloon $popup -title "[Rappture::filexfer::label downloadWord] as..."
    433433                set inner [$popup component inner]
    434434                label $inner.summary -text "" -anchor w
     
    442442                    -value pdf
    443443                pack $inner.pdf -anchor w
    444                 button $inner.go -text "Download Now" \
     444                button $inner.go -text [Rappture::filexfer::label download] \
    445445                    -command [lindex $args 0]
    446446                pack $inner.go -pady 4
     
    450450            set num [llength [get]]
    451451            set num [expr {($num == 1) ? "1 result" : "$num results"}]
    452             $inner.summary configure -text "Download $num in the following format:"
     452            $inner.summary configure -text "[Rappture::filexfer::label downloadWord] $num in the following format:"
    453453            update idletasks ;# fix initial sizes
    454454            return $popup
Note: See TracChangeset for help on using the changeset viewer.