Changeset 50 for trunk/gui


Ignore:
Timestamp:
Aug 28, 2005, 9:09:01 PM (19 years ago)
Author:
mmc
Message:

Added support for file transfer with the desktop. Each Rappture
application acts like an http server, configured to listen on
a particular port according to the parameters found in the file
~/data/sessions/$SESSION/resources. When the server is active,
the GUI has a "Download..." button in the results area. A Java
client (in the filexfer directory) connects to the server and
listens for download requests. When the user clicks on "Download...",
the desired result is spooled to a file, and a Java client pops up
a web page requesting the file. This downloads the result to the
user's desktop.

Note that if the $SESSION environment variable is not set, these
changes do nothing.

Location:
trunk/gui
Files:
8 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/apps/driver

    r44 r50  
    7575
    7676set tool [Rappture::Tool ::#auto $xmlobj $installdir]
     77
     78# ----------------------------------------------------------------------
     79# INITIALIZE THE DESKTOP CONNECTION
     80#
     81# If there's a SESSION ID, then this must be running within the
     82# nanoHUB.  Try to initialize the server handling the desktop
     83# connection.
     84# ----------------------------------------------------------------------
     85Rappture::filexfer::init
    7786
    7887# ----------------------------------------------------------------------
  • trunk/gui/scripts/analyzer.tcl

    r43 r50  
    4949    public method load {file}
    5050    public method clear {}
     51    public method download {}
    5152
    5253    protected method _plot {args}
     
    191192    bind $itk_component(resultselector) <<Value>> [itcl::code $this _fixResult]
    192193
     194    if {[Rappture::filexfer::enabled]} {
     195        itk_component add download {
     196            button $w.top.dl -text "Download..." \
     197                -command [itcl::code $this download]
     198        }
     199        pack $itk_component(download) -side right -padx {4 0}
     200        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."
     201    }
     202
    193203    itk_component add results {
    194204        Rappture::Panes $w.pane
     
    450460    }
    451461
    452     # if there is only one result page, take down the selector
    453     set w [$itk_component(notebook) page analyze]
    454     if {[$itk_component(resultselector) choices size] <= 1} {
    455         pack forget $w.top
    456     } else {
    457         pack $w.top -before $itk_component(results) -side top -fill x
    458     }
    459 
    460462    # show the first page by default
    461463    set first [$itk_component(resultselector) choices get -label 0]
     
    502504    _fixSimControl
    503505    reset
     506}
     507
     508# ----------------------------------------------------------------------
     509# USAGE: download
     510#
     511# Spools the current result so the user can download it.
     512# ----------------------------------------------------------------------
     513itcl::body Rappture::Analyzer::download {} {
     514    if {[Rappture::filexfer::enabled]} {
     515        set title [$itk_component(resultselector) value]
     516        set page [$itk_component(resultselector) translate $title]
     517        if {$page != ""} {
     518            set ext ""
     519            set f [$itk_component(resultpages) page $page]
     520            foreach {ext data} [$f.rviewer download] break
     521            if {"" == $ext} {
     522                Rappture::Tooltip::cue $itk_component(download) \
     523                    "Can't download this result."
     524                return
     525            }
     526            regsub -all {[\ -\/\:-\@\{-\~]} $title {} title
     527            set file "$title$ext"
     528        } else {
     529            # this shouldn't happen
     530            set file error.html
     531            set data "<h1>Not Found</h1>There is no result selected."
     532        }
     533
     534        if {[catch {Rappture::filexfer::spool $data $file} result]} {
     535            if {"no clients" == $result} {
     536                Rappture::Tooltip::cue $itk_component(download) \
     537                    "Can't download this result.  Looks like you might be having trouble with the version of Java installed for your browser."
     538            } else {
     539                error $result "    (while spooling result \"$title\")"
     540            }
     541        }
     542    }
    504543}
    505544
  • trunk/gui/scripts/contourresult.tcl

    r17 r50  
    8484    public method delete {args}
    8585    public method scale {args}
     86    public method download {}
    8687
    8788    protected method _rebuild {}
     
    403404
    404405# ----------------------------------------------------------------------
     406# USAGE: download
     407#
     408# Clients use this method to create a downloadable representation
     409# of the plot.  Returns a list of the form {ext string}, where
     410# "ext" is the file extension (indicating the type of data) and
     411# "string" is the data itself.
     412# ----------------------------------------------------------------------
     413itcl::body Rappture::ContourResult::download {} {
     414    return ""
     415}
     416
     417# ----------------------------------------------------------------------
    405418# USAGE: _rebuild
    406419#
  • trunk/gui/scripts/deviceresult.tcl

    r22 r50  
    2626    public method delete {args}
    2727    public method scale {args}
     28    public method download {}
    2829
    2930    set _dataobj ""  ;# data object currently being displayed
     
    111112    # nothing to do for structures
    112113}
     114
     115# ----------------------------------------------------------------------
     116# USAGE: download
     117#
     118# Clients use this method to create a downloadable representation
     119# of the plot.  Returns a list of the form {ext string}, where
     120# "ext" is the file extension (indicating the type of data) and
     121# "string" is the data itself.
     122# ----------------------------------------------------------------------
     123itcl::body Rappture::DeviceResult::download {} {
     124    return ""
     125}
  • trunk/gui/scripts/getopts.tcl

    r11 r50  
    9797        }
    9898        if {![info exists params($first)]} {
    99             error "bad option \"$first\": should be [join [lsort $opts]] {, }]"
     99            error "bad option \"$first\": should be [join [lsort $opts] {, }]"
    100100        }
    101101        switch -- [lindex $flags($first) 0] {
  • trunk/gui/scripts/loader.tcl

    r25 r50  
    8686    foreach ftail $flist {
    8787        set fpath [file join $fdir examples $ftail]
    88         foreach fname [lsort [glob -nocomplain $fpath]] {
     88
     89        catch {unset entries}
     90        foreach fname [glob -nocomplain $fpath] {
    8991            if {[file exists $fname]} {
    9092                if {[catch {set obj [Rappture::library $fname]} result]} {
     
    98100
    99101                    # if this is new, add it
    100                     set i [$itk_component(combo) choices index -label $label]
    101                     if {$i < 0} {
    102                         $itk_component(combo) choices insert end $obj $label
    103 
    104                         if {[string equal $defval [file tail $fname]]} {
    105                             $_owner xml put $path.default $label
    106                         }
     102                    if {![info exists entries($label)]} {
     103                        set entries($label) $obj
     104                    }
     105
     106                    # translate default file name => default label
     107                    if {[string equal $defval [file tail $fname]]} {
     108                        $_owner xml put $path.default $label
    107109                    }
    108110                }
     
    110112                puts stderr "WARNING: missing example file \"$fname\""
    111113            }
     114        }
     115
     116        foreach label [lsort -dictionary [array names entries]] {
     117            $itk_component(combo) choices insert end $entries($label) $label
    112118        }
    113119    }
  • trunk/gui/scripts/meshresult.tcl

    r15 r50  
    4242    public method delete {args}
    4343    public method scale {args}
     44    public method download {}
    4445
    4546    protected method _rebuild {}
     
    260261
    261262# ----------------------------------------------------------------------
     263# USAGE: download
     264#
     265# Clients use this method to create a downloadable representation
     266# of the plot.  Returns a list of the form {ext string}, where
     267# "ext" is the file extension (indicating the type of data) and
     268# "string" is the data itself.
     269# ----------------------------------------------------------------------
     270itcl::body Rappture::MeshResult::download {} {
     271    set psdata [$itk_component(plot) postscript output -maxpect 1]
     272
     273    set cmds {
     274        set fout "mesh[pid].pdf"
     275        exec ps2pdf - $fout << $psdata
     276
     277        set fid [open $fout r]
     278        fconfigure $fid -translation binary -encoding binary
     279        set pdfdata [read $fid]
     280        close $fid
     281
     282        file delete -force $fout
     283    }
     284    if {[catch $cmds result] == 0} {
     285        return [list .pdf $pdfdata]
     286    }
     287    return [list .ps $psdata]
     288}
     289
     290# ----------------------------------------------------------------------
    262291# USAGE: _rebuild
    263292#
  • trunk/gui/scripts/resultviewer.tcl

    r22 r50  
    3030
    3131    public method plot {option args}
     32    public method download {}
    3233
    3334    protected method _plotAdd {xmlobj {settings ""}}
     
    319320
    320321# ----------------------------------------------------------------------
     322# USAGE: download
     323#
     324# Clients use this method to create a downloadable representation
     325# of the plot.  Returns a list of the form {ext string}, where
     326# "ext" is the file extension (indicating the type of data) and
     327# "string" is the data itself.
     328# ----------------------------------------------------------------------
     329itcl::body Rappture::ResultViewer::download {} {
     330    if {"" == $_mode} {
     331        return ""
     332    }
     333    return [$_mode2widget($_mode) download]
     334}
     335
     336# ----------------------------------------------------------------------
    321337# USAGE: _xml2data <xmlobj> <path>
    322338#
  • trunk/gui/scripts/textresult.tcl

    r46 r50  
    2929    public method delete {args}
    3030    public method scale {args}
     31    public method download {}
    3132
    3233    public method select {option args}
     
    241242
    242243# ----------------------------------------------------------------------
     244# USAGE: download
     245#
     246# Clients use this method to create a downloadable representation
     247# of the plot.  Returns a list of the form {ext string}, where
     248# "ext" is the file extension (indicating the type of data) and
     249# "string" is the data itself.
     250# ----------------------------------------------------------------------
     251itcl::body Rappture::TextResult::download {} {
     252    return [list .txt [$itk_component(text) get 1.0 end]]
     253}
     254
     255# ----------------------------------------------------------------------
    243256# USAGE: select all
    244257#
  • trunk/gui/scripts/valueresult.tcl

    r22 r50  
    2626    public method delete {args}
    2727    public method scale {args}
     28    public method download {}
    2829
    2930    set _dataobj ""  ;# data object currently being displayed
     
    137138    # nothing to do for values
    138139}
     140
     141# ----------------------------------------------------------------------
     142# USAGE: download
     143#
     144# Clients use this method to create a downloadable representation
     145# of the plot.  Returns a list of the form {ext string}, where
     146# "ext" is the file extension (indicating the type of data) and
     147# "string" is the data itself.
     148# ----------------------------------------------------------------------
     149itcl::body Rappture::ValueResult::download {} {
     150    return ""
     151}
  • trunk/gui/scripts/xyresult.tcl

    r46 r50  
    5353    public method delete {args}
    5454    public method scale {args}
     55    public method download {}
    5556
    5657    protected method _rebuild {}
     
    352353
    353354# ----------------------------------------------------------------------
     355# USAGE: download
     356#
     357# Clients use this method to create a downloadable representation
     358# of the plot.  Returns a list of the form {ext string}, where
     359# "ext" is the file extension (indicating the type of data) and
     360# "string" is the data itself.
     361# ----------------------------------------------------------------------
     362itcl::body Rappture::XyResult::download {} {
     363    set psdata [$itk_component(plot) postscript output -maxpect 1]
     364
     365    set cmds {
     366        set fout "xy[pid].pdf"
     367        exec ps2pdf - $fout << $psdata
     368
     369        set fid [open $fout r]
     370        fconfigure $fid -translation binary -encoding binary
     371        set pdfdata [read $fid]
     372        close $fid
     373
     374        file delete -force $fout
     375    }
     376    if {[catch $cmds result] == 0} {
     377        return [list .pdf $pdfdata]
     378    }
     379    return [list .ps $psdata]
     380}
     381
     382# ----------------------------------------------------------------------
    354383# USAGE: _rebuild
    355384#
     
    453482            }
    454483            if {[info exists hints(yscale)] && $hints(yscale) == "log"} {
    455                 _axis scale x log
     484                _axis scale y log
    456485            }
    457486
Note: See TracChangeset for help on using the changeset viewer.