Changeset 1355 for trunk/gui


Ignore:
Timestamp:
Mar 20, 2009, 8:30:35 PM (16 years ago)
Author:
gah
Message:

my first cut at flowvisviewer client based on work by dsk

File:
1 edited

Legend:

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

    r1354 r1355  
    9898    protected method Pause {}
    9999    public method flow {option}
    100     public method record {option}
    101100
    102101    protected method State {comp}
     
    114113    private method BuildCameraDrawer {}
    115114    private method PanCamera {}
     115    private method GetMovie { widget width height }
     116    private method WaitIcon { option widget }
    116117
    117118    private variable outbuf_       ;# buffer for outgoing commands
     
    176177    set flow_(state) "stopped"
    177178    array set downloadPopup_ {
    178         format jpg
     179        format draft
    179180    }
    180181    array set play_ {
     
    666667        }
    667668        controls {
    668             # no controls for this download yet
    669             return ""
    670         }
     669            set popup .flowvisviewerdownload
     670            if {![winfo exists .flowvisviewerdownload]} {
     671                # if we haven't created the popup yet, do it now
     672                Rappture::Balloon $popup \
     673                    -title "[Rappture::filexfer::label downloadWord] as..."
     674                set inner [$popup component inner]
     675                label $inner.summary -text "" -anchor w
     676                pack $inner.summary -side top
     677                set img $_image(plot)
     678                set res "[image width $img]x[image height $img]"
     679                radiobutton $inner.draft -text "Image (draft $res)" \
     680                    -variable Rappture::MolvisViewer::_downloadPopup(format) \
     681                    -value draft
     682                pack $inner.draft -anchor w
     683
     684                set res "640x480"
     685                radiobutton $inner.medium -text "Movie (standard $res)" \
     686                    -variable Rappture::MolvisViewer::_downloadPopup(format) \
     687                    -value $res
     688                pack $inner.medium -anchor w
     689
     690                set res "1024x768"
     691                radiobutton $inner.high -text "Movie (high quality $res)" \
     692                    -variable Rappture::MolvisViewer::_downloadPopup(format) \
     693                    -value $res
     694                pack $inner.high -anchor w
     695
     696            } else {
     697                set inner [$popup component inner]
     698            }
     699            set num [llength [get]]
     700            set num [expr {($num == 1) ? "1 result" : "$num results"}]
     701            $inner.summary configure -text "[Rappture::filexfer::label downloadWord] $num in the following format:"
     702            update idletasks ;# fix initial sizes
     703            return $popup
     704        }
    671705        now {
    672             # Doing an image base64 encode/decode has to be better than
    673             # writing the image to a file and reading it back in.
    674             set data [$_image(plot) data -format jpeg]
    675             set data [Rappture::encoding::decode -as b64 $data]
    676             return [list .jpg $data]
    677         }
     706            set popup .molvisviewerdownload
     707            if {[winfo exists .molvisviewerdownload]} {
     708                $popup deactivate
     709            }
     710            switch -- $_downloadPopup(format) {
     711                draft {
     712                    # Get the image data (as base64) and decode it back to
     713                    # binary.  This is better than writing to temporary
     714                    # files.  When we switch to the BLT picture image it
     715                    # won't be necessary to decode the image data.
     716                    set bytes [$_image(plot) data -format "jpeg -quality 100"]
     717                    set data [Rappture::encoding::decode -as b64 $data]
     718                    return [list .jpg $data]
     719                }
     720                "640x480" {
     721                    return [$this GetMovie [lindex $args 0] 640 480]
     722                }
     723                "1024x768" {
     724                    return [$this GetMovie [lindex $args 0] 1024 768]
     725                }
     726            }
     727        }
    678728        default {
    679729            error "bad option \"$option\": should be coming, controls, now"
     
    20202070#
    20212071itcl::body Rappture::FlowvisViewer::record {option} {
    2022     switch -- $option {
    2023         movie {
    2024             if {[llength $args] < 1 || [llength $args] > 2} {
    2025                 error "wrong # args: should be \"Flow movie record|stop|play ?on|off|toggle?\""
    2026             }
    2027             set action [lindex $args 0]
    2028             set op [lindex $args 1]
    2029             if {$op == ""} { set op "on" }
    2030 
    2031             set current [State $action]
    2032             if {$op == "toggle"} {
    2033                 if {$current == "on"} {
    2034                     set op "off"
    2035                 } else {
    2036                     set op "on"
    2037                 }
    2038             }
    2039             set cmds ""
    2040             switch -- $action {
    2041                 record {
    2042                     if { [$itk_component(rewind) cget -relief] != "sunken" } {
    2043                         $itk_component(rewind) configure -relief sunken
    2044                         $itk_component(stop) configure -relief raised
    2045                         $itk_component(play) configure -relief raised
    2046                         set inner $itk_component(settingsFrame)
    2047                         set frames [$inner.framecnt value]
    2048                         set cmds "flow capture $frames"
    2049                         _send $cmds
    2050                     }
    2051                 }
    2052                 stop {
    2053                     if { [$itk_component(stop) cget -relief] != "sunken" } {
    2054                         $itk_component(rewind) configure -relief raised
    2055                         $itk_component(stop) configure -relief sunken
    2056                         $itk_component(play) configure -relief raised
    2057                         _pause
    2058                         set cmds "flow reset"
    2059                         _send $cmds
    2060                     }
    2061                 }
    2062                 play {
    2063                     if { [$itk_component(play) cget -relief] != "sunken" } {
    2064                         $itk_component(rewind) configure -relief raised
    2065                         $itk_component(stop) configure -relief raised
    2066                         $itk_component(play) configure \
    2067                             -image [Rappture::icon playback-pause] \
    2068                             -relief sunken
    2069                         bind $itk_component(play) <ButtonPress> \
    2070                             [itcl::code $this _pause]
    2071                         Play
    2072                     }
    2073                 }
    2074                 default {
    2075                     error "bad option \"$option\": should be one of record|stop|play"
    2076                 }
    2077 
    2078             }
    2079         }
    2080         default {
    2081             error "bad option \"$option\": should be movie"
    2082         }
    2083     }
     2072
    20842073}
    20852074
     
    25282517    }
    25292518}
     2519
     2520itcl::body Rappture::FlowvisViewer::WaitIcon  { option widget } {
     2521    switch -- $option {
     2522        "start" {
     2523            $_dispatcher dispatch $this !waiticon \
     2524                "[itcl::code $this WaitIcon "next" $widget] ; list"
     2525            set icon_ 0
     2526            $widget configure -image [Rappture::icon bigroller${icon_}]
     2527            $_dispatcher event -after 100 !waiticon
     2528        }
     2529        "next" {
     2530            incr icon_
     2531            if { $icon_ >= 8 } {
     2532                set icon_ 0
     2533            }
     2534            $widget configure -image [Rappture::icon bigroller${icon_}]
     2535            $_dispatcher event -after 100 !waiticon
     2536        }
     2537        "stop" {
     2538            $_dispatcher cancel !waiticon
     2539        }
     2540    }
     2541}
     2542
     2543itcl::body Rappture::FlowvisViewer::GetMovie { widget width height } {
     2544    set token "movie[incr nextToken_]"
     2545    set var ::Rappture::MolvisViewer::hardcopy_($this-$token)
     2546    set $var ""
     2547
     2548    # Setup an automatic timeout procedure.
     2549    $_dispatcher dispatch $this !movietimeout "set $var {} ; list"
     2550
     2551    set popup [Rappture::Balloon .movie -title "Generating video..."]
     2552    set inner [$popup component inner]
     2553    label $inner.title -text "Generating Hardcopy" -font "Arial 10 bold"
     2554    label $inner.please -text "This may take a few minutes." -font "Arial 10"
     2555    label $inner.icon -image [Rappture::icon bigroller0]
     2556    button $inner.cancel -text "Cancel" -font "Arial 10 bold" \
     2557        -command [list set $var ""]
     2558    $_dispatcher event -after 60000 !movietimeout
     2559    WaitIcon start $inner.icon
     2560    bind $inner.cancel <KeyPress-Return> [list $inner.cancel invoke]
     2561   
     2562    blt::table $inner \
     2563        0,0 $inner.title -columnspan 2 \
     2564        1,0 $inner.please -anchor w \
     2565        1,1 $inner.icon -anchor e  \
     2566        2,0 $inner.cancel -columnspan 2
     2567    blt::table configure $inner r0 -pady 4
     2568    blt::table configure $inner r2 -pady 4
     2569    grab set -local $inner
     2570    focus $inner.cancel
     2571
     2572    SendCmd "flow video $width $height $settings_(numframes) 2.0 1000"
     2573   
     2574    $popup activate $widget below
     2575    update
     2576    # We wait here for either
     2577    #  1) the png to be delivered or
     2578    #  2) timeout or 
     2579    #  3) user cancels the operation.
     2580    tkwait variable $var
     2581
     2582    # Clean up.
     2583    $_dispatcher cancel !pngtimeout
     2584    WaitIcon stop $inner.icon
     2585    grab release $inner
     2586    $popup deactivate
     2587    destroy $popup
     2588    update
     2589
     2590    if { $hardcopy_($this-$token) != "" } {
     2591        return [list .png $hardcopy_($this-$token)]
     2592    }
     2593    return ""
     2594}
Note: See TracChangeset for help on using the changeset viewer.