Ignore:
Timestamp:
Feb 24, 2013 1:11:18 PM (11 years ago)
Author:
gah
Message:

merge (by hand) with Rappture1.2 branch

File:
1 edited

Legend:

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

    r3177 r3330  
     1# -*- mode: tcl; indent-tabs-mode: nil -*-
    12
    23# ----------------------------------------------------------------------
     
    3435    private variable _icon 0
    3536
    36     # Number of milliseconds to wait before idle timeout.
    37     # If greater than 0, automatically disconnect from the visualization
    38     # server when idle timeout is reached.
     37    # Number of milliseconds to wait before idle timeout.  If greater than 0,
     38    # automatically disconnect from the visualization server when idle timeout
     39    # is reached.
    3940    private variable _idleTimeout 43200000; # 12 hours
    4041    #private variable _idleTimeout 5000;    # 5 seconds
    4142    #private variable _idleTimeout 0;       # No timeout
     43
    4244    private variable _logging 0
    4345
     
    4749    protected variable _image
    4850    protected variable _hostname
    49 
    50     constructor { hostlist args } {
     51    protected variable _errorCount 0
     52    protected variable _debugConsole 0
     53
     54    constructor { servers args } {
    5155        # defined below
    5256    }
     
    5559    }
    5660    # Used internally only.
    57     private method Shuffle { hostlist }
     61    private method Shuffle { servers }
    5862    private method ReceiveHelper {}
    5963    private method ServerDown {}
    6064    private method SendHelper {}
    6165    private method SendHelper.old {}
    62     private method CheckConnection {}
    6366    private method SplashScreen { state }
    6467
     68    protected method ToggleConsole {}
     69    private method DebugConsole {}
     70    private method BuildConsole {}
     71    private method HideConsole {}
     72    private method TraceComm { channel {data {}} }
     73    private method SendDebugCommand {}
     74
     75    protected method Color2RGB { color }
     76    protected method Connect { servers }
     77    protected method CheckConnection {}
     78    protected method Disconnect {}
     79    protected method Euler2XYZ { theta phi psi }
     80    protected method Flush {}
     81    protected method IsConnected {}
     82    protected method ReceiveBytes { nbytes }
     83    protected method ReceiveEcho { channel {data ""} }
     84    protected method ReceiveError { args }
     85    protected method SendBytes { bytes }
    6586    protected method SendEcho { channel {data ""} }
    66     protected method ReceiveEcho { channel {data ""} }
    67     protected method Connect { hostlist }
    68     protected method Disconnect {}
    69     protected method IsConnected {}
    70     protected method SendBytes { bytes }
    71     protected method ReceiveBytes { nbytes }
    72     protected method Flush {}
    73     protected method Color2RGB { color }
    74     protected method Euler2XYZ { theta phi psi }
    7587    protected method StartWaiting {}
    7688    protected method StopWaiting {}
     
    124136# CONSTRUCTOR
    125137# ----------------------------------------------------------------------
    126 itcl::body Rappture::VisViewer::constructor { hostlist args } {
     138itcl::body Rappture::VisViewer::constructor { servers args } {
    127139
    128140    Rappture::dispatcher _dispatcher
     
    134146    $_dispatcher register !waiting
    135147
    136     CheckNameList $hostlist
    137     set _hostlist $hostlist
     148    CheckNameList $servers
    138149    set _buffer(in) ""
    139150    set _buffer(out) ""
     
    152163
    153164    itk_component add main {
    154         Rappture::SidebarFrame $itk_interior.main -resizeframe 0
     165        Rappture::SidebarFrame $itk_interior.main -resizeframe 1
    155166    }
    156167    pack $itk_component(main) -expand yes -fill both
     
    226237#    Connect to the visualization server (e.g. nanovis, pymolproxy).
    227238#    Creates an event callback that is triggered when we are idle
    228 #    (no I/O with the server) for some specified time. Sends the server
    229 #    some estimate of the size of our job [soon to be deprecated].
    230 #    If it's too busy, that server may forward us to another [this
    231 #    was been turned off in nanoscale].
    232 #
    233 itcl::body Rappture::VisViewer::Connect { hostlist } {
     239#    (no I/O with the server) for some specified time.
     240#
     241itcl::body Rappture::VisViewer::Connect { servers } {
    234242    blt::busy hold $itk_component(hull) -cursor watch
    235243
    236244    puts stderr "server type is $_serverType"
    237     foreach server [Shuffle $hostlist] {
     245    foreach server [Shuffle $servers] {
    238246        puts stderr "connecting to $server..."
    239247        foreach {hostname port} [split $server ":"] break
     
    436444itcl::body Rappture::VisViewer::StartWaiting {} {
    437445    after cancel $_afterId
    438     set _afterId [after 500 [itcl::code $this SplashScreen on]]
     446    set _afterId [after 2000 [itcl::code $this SplashScreen on]]
    439447}
    440448
     
    627635    }
    628636}
     637
     638#
     639# HideConsole --
     640#
     641#    Hide the debug console by withdrawing its toplevel window.
     642#
     643itcl::body Rappture::VisViewer::HideConsole {} {
     644    set _debugConsole 0
     645    DebugConsole
     646}
     647
     648#
     649# BuildConsole --
     650#
     651#    Create and pack the widgets that make up the debug console: a text
     652#    widget to display the communication and an entry widget to type
     653#    in commands to send to the render server.
     654#
     655itcl::body Rappture::VisViewer::BuildConsole {} {
     656    toplevel .renderconsole
     657    wm protocol .renderconsole WM_DELETE_WINDOW [itcl::code $this HideConsole]
     658    set f .renderconsole
     659    frame $f.send
     660    pack $f.send -side bottom -fill x
     661    label $f.send.l -text "Send:"
     662    pack $f.send.l -side left
     663    itk_component add command {
     664        entry $f.send.e -background white
     665    } {
     666        ignore -background
     667    }
     668    pack $f.send.e -side left -expand yes -fill x
     669    bind $f.send.e <KeyPress-Return> [itcl::code $this SendDebugCommand]
     670   
     671    scrollbar $f.sb -orient vertical -command "$f.comm yview"
     672    pack $f.sb -side right -fill y
     673    itk_component add trace {
     674        text $f.comm -wrap char -yscrollcommand "$f.sb set" -background white
     675    } {
     676        ignore -background
     677    }
     678    pack $f.comm -expand yes -fill both
     679
     680    $itk_component(trace) tag configure error -foreground red \
     681        -font -*-courier-medium-o-normal-*-*-120-*
     682    $itk_component(trace) tag configure incoming -foreground blue
     683}
     684
     685#
     686# ToggleConsole --
     687#
     688#    This is used by derived classes to turn on/off debuging.  It's
     689#    up the to derived class to decide how to turn on/off debugging.
     690#
     691itcl::body Rappture::VisViewer::ToggleConsole {} {
     692    if { $_debugConsole } {
     693        set _debugConsole 0
     694    } else {
     695        set _debugConsole 1
     696    }
     697    DebugConsole
     698}
     699
     700#
     701# DebugConsole --
     702#
     703#    Based on the value of the variable _debugConsole, turns on/off
     704#    debugging. This is done by setting/unsetting a procedure that
     705#    is called whenever new characters are received or sent on the
     706#    socket to the render server.  Additionally, the debug console
     707#    is created if necessary and hidden/shown.
     708#
     709itcl::body Rappture::VisViewer::DebugConsole {} {
     710    if { ![winfo exists .renderconsole] } {
     711        BuildConsole
     712    }
     713    if { $_debugConsole } {
     714        $this configure -sendcommand [itcl::code $this TraceComm]
     715        $this configure -receivecommand [itcl::code $this TraceComm]
     716        wm deiconify .renderconsole
     717    } else {
     718        $this configure -sendcommand ""
     719        $this configure -receivecommand ""
     720        wm withdraw .renderconsole
     721    }
     722}
     723
     724# ----------------------------------------------------------------------
     725# USAGE: TraceComm <channel> <data>
     726#
     727# Invoked automatically whenever there is communication between
     728# the rendering widget and the server.  Eavesdrops on the communication
     729# and posts the commands in a text viewer.
     730# ----------------------------------------------------------------------
     731itcl::body Rappture::VisViewer::TraceComm {channel {data ""}} {
     732    $itk_component(trace) configure -state normal
     733    switch -- $channel {
     734        closed {
     735            $itk_component(trace) insert end "--CLOSED--\n" error
     736        }
     737        <<line {
     738            $itk_component(trace) insert end $data incoming "\n" incoming
     739        }
     740        >>line {
     741            $itk_component(trace) insert end $data outgoing "\n" outgoing
     742        }
     743        error {
     744            $itk_component(trace) insert end $data error "\n" error
     745        }
     746        default {
     747            $itk_component(trace) insert end "$data\n"
     748        }
     749    }
     750    $itk_component(trace) configure -state disabled
     751    $itk_component(trace) see end
     752}
     753
     754# ----------------------------------------------------------------------
     755# USAGE: SendDebugCommand
     756#
     757# Invoked automatically whenever the user enters a command and
     758# presses <Return>.  Sends the command along to the rendering
     759# widget.
     760# ----------------------------------------------------------------------
     761itcl::body Rappture::VisViewer::SendDebugCommand {} {
     762    set cmd [$itk_component(command) get]
     763    SendBytes "$cmd\n"
     764    $itk_component(command) delete 0 end
     765}
     766
     767
     768#
     769# ReceiveError -bytes <size> -type <type> -token <token>
     770#
     771itcl::body Rappture::VisViewer::ReceiveError { args } {
     772    array set info {
     773        -token "???"
     774        -bytes 0
     775        -type "???"
     776    }
     777    array set info $args
     778    set bytes [ReceiveBytes $info(-bytes)]
     779    if { $info(-type) == "error" } {
     780        set popup $itk_component(hull).error
     781        if { ![winfo exists $popup] } {
     782            Rappture::Balloon $popup \
     783                -title "Render Server Error"
     784            set inner [$popup component inner]
     785            label $inner.summary -text "" -anchor w
     786
     787            Rappture::Scroller $inner.scrl \
     788                -xscrollmode auto -yscrollmode auto
     789            text $inner.scrl.text \
     790                -font "Arial 9 " -background white -relief sunken -bd 1 \
     791                -height 5 -wrap word -width 60
     792            $inner.scrl contents $inner.scrl.text
     793            button $inner.ok -text "Dismiss" -command [list $popup deactivate] \
     794                -font "Arial 9"
     795            incr _errorCount
     796            blt::table $inner \
     797                0,0 $inner.scrl -fill both \
     798                1,0 $inner.ok
     799            $inner.scrl.text tag configure normal -font "Arial 9"
     800            $inner.scrl.text tag configure italic -font "Arial 9 italic"
     801            $inner.scrl.text tag configure bold -font "Arial 10 bold"
     802            $inner.scrl.text tag configure code -font "Courier 10 bold"
     803        } else {
     804            $popup deactivate
     805        }
     806        update
     807        set inner [$popup component inner]
     808        $inner.scrl.text delete 0.0 end
     809       
     810        $inner.scrl.text insert end "The following error was reported by the render server:\n\n" bold
     811        $inner.scrl.text insert end $bytes code
     812        update
     813        $popup activate $itk_component(hull) below
     814    }
     815   
     816}
     817
Note: See TracChangeset for help on using the changeset viewer.