Changeset 3330 for trunk/gui/scripts/visviewer.tcl
- Timestamp:
- Feb 24, 2013 1:11:18 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/visviewer.tcl
r3177 r3330 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 1 2 2 3 # ---------------------------------------------------------------------- … … 34 35 private variable _icon 0 35 36 36 # Number of milliseconds to wait before idle timeout. 37 # If greater than 0, automatically disconnect from the visualization38 # server when idle timeoutis 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. 39 40 private variable _idleTimeout 43200000; # 12 hours 40 41 #private variable _idleTimeout 5000; # 5 seconds 41 42 #private variable _idleTimeout 0; # No timeout 43 42 44 private variable _logging 0 43 45 … … 47 49 protected variable _image 48 50 protected variable _hostname 49 50 constructor { hostlist args } { 51 protected variable _errorCount 0 52 protected variable _debugConsole 0 53 54 constructor { servers args } { 51 55 # defined below 52 56 } … … 55 59 } 56 60 # Used internally only. 57 private method Shuffle { hostlist}61 private method Shuffle { servers } 58 62 private method ReceiveHelper {} 59 63 private method ServerDown {} 60 64 private method SendHelper {} 61 65 private method SendHelper.old {} 62 private method CheckConnection {}63 66 private method SplashScreen { state } 64 67 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 } 65 86 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 }75 87 protected method StartWaiting {} 76 88 protected method StopWaiting {} … … 124 136 # CONSTRUCTOR 125 137 # ---------------------------------------------------------------------- 126 itcl::body Rappture::VisViewer::constructor { hostlistargs } {138 itcl::body Rappture::VisViewer::constructor { servers args } { 127 139 128 140 Rappture::dispatcher _dispatcher … … 134 146 $_dispatcher register !waiting 135 147 136 CheckNameList $hostlist 137 set _hostlist $hostlist 148 CheckNameList $servers 138 149 set _buffer(in) "" 139 150 set _buffer(out) "" … … 152 163 153 164 itk_component add main { 154 Rappture::SidebarFrame $itk_interior.main -resizeframe 0165 Rappture::SidebarFrame $itk_interior.main -resizeframe 1 155 166 } 156 167 pack $itk_component(main) -expand yes -fill both … … 226 237 # Connect to the visualization server (e.g. nanovis, pymolproxy). 227 238 # 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 # 241 itcl::body Rappture::VisViewer::Connect { servers } { 234 242 blt::busy hold $itk_component(hull) -cursor watch 235 243 236 244 puts stderr "server type is $_serverType" 237 foreach server [Shuffle $ hostlist] {245 foreach server [Shuffle $servers] { 238 246 puts stderr "connecting to $server..." 239 247 foreach {hostname port} [split $server ":"] break … … 436 444 itcl::body Rappture::VisViewer::StartWaiting {} { 437 445 after cancel $_afterId 438 set _afterId [after 500 [itcl::code $this SplashScreen on]]446 set _afterId [after 2000 [itcl::code $this SplashScreen on]] 439 447 } 440 448 … … 627 635 } 628 636 } 637 638 # 639 # HideConsole -- 640 # 641 # Hide the debug console by withdrawing its toplevel window. 642 # 643 itcl::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 # 655 itcl::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 # 691 itcl::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 # 709 itcl::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 # ---------------------------------------------------------------------- 731 itcl::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 # ---------------------------------------------------------------------- 761 itcl::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 # 771 itcl::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.