Changeset 1394 for trunk/gui/scripts


Ignore:
Timestamp:
Apr 14, 2009 1:48:57 PM (15 years ago)
Author:
gah
Message:

sequenceresult.tcl:

Playing a sequence continuously and then clicking "Clear" will generate an
infinite number of automatic error 'invalid command name ""' messages.

_fixValue Check for _topmost (top most data object) to be "".

Deletes the viewer.

delete Calls pause method to stop the player.

balloon.tcl:

Bandaid to fix 'bad geometry specifier "-44x184+864+247"' errors. This has to
do with the placement of the popup menu when clicking on axes in the xyresult
widget. Added a test if the width or height is negative and clip the geometry
to +x+y.

xyresult.tcl:

Graph issues 'can't find element "elem1"' error when attempting to
to deactivate an element that doesn't exist. The highlighted element name
is stored in the variable _hilite(elem). It goes out of sync with the graph.
Test for the existence of the element in the graph explicitly.

Location:
trunk/gui/scripts
Files:
3 edited

Legend:

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

    r1342 r1394  
    212212        shape set $s -bound photo $_masks($placement)
    213213    }
    214 
    215     wm geometry $p ${pw}x${ph}+$px+$py
     214    if { $pw < 1 || $ph < 1 }  {
     215        # I really don't know why this is happenning.  I believe this occurs
     216        # when in a work space (i.e the main window is smaller than the root
     217        # window). So for now, better to place the ballon window somewhere
     218        # than to fail with a bad geometry.
     219        wm geometry $p +$px+$py
     220    } else {
     221        wm geometry $p ${pw}x${ph}+$px+$py
     222    }
    216223    wm deiconify $p
    217224    raise $p
  • trunk/gui/scripts/sequenceresult.tcl

    r1342 r1394  
    7373
    7474    itk_component add player {
    75         frame $itk_interior.player
     75        frame $itk_interior.player
    7676    }
    7777    pack $itk_component(player) -side bottom -fill x
     
    7979
    8080    itk_component add play {
    81         button $itk_component(player).play \
    82             -bitmap [Rappture::icon play] \
    83             -command [itcl::code $this play]
     81        button $itk_component(player).play \
     82            -bitmap [Rappture::icon play] \
     83            -command [itcl::code $this play]
    8484    }
    8585    grid $itk_component(play) -row 0 -rowspan 2 -column 0 \
    86         -ipadx 2 -padx {0 4} -pady 4 -sticky nsew
     86        -ipadx 2 -padx {0 4} -pady 4 -sticky nsew
    8787
    8888    itk_component add dial {
    89         Rappture::Radiodial $itk_component(player).dial \
    90             -length 10 -valuewidth 0 -valuepadding 0 -padding 6 \
    91             -linecolor "" -activelinecolor "" \
    92             -knobimage [Rappture::icon knob2] -knobposition center@middle
     89        Rappture::Radiodial $itk_component(player).dial \
     90            -length 10 -valuewidth 0 -valuepadding 0 -padding 6 \
     91            -linecolor "" -activelinecolor "" \
     92            -knobimage [Rappture::icon knob2] -knobposition center@middle
    9393    } {
    94         usual
    95         keep -dialprogresscolor
     94        usual
     95        keep -dialprogresscolor
    9696    }
    9797    grid $itk_component(dial) -row 1 -column 1 -sticky ew
     
    9999
    100100    itk_component add info {
    101         frame $itk_component(player).info
     101        frame $itk_component(player).info
    102102    }
    103103    grid $itk_component(info) -row 0 -column 1 -columnspan 2 -sticky ew
    104104
    105105    itk_component add indexLabel {
    106         label $itk_component(info).ilabel
     106        label $itk_component(info).ilabel
    107107    } {
    108         usual
    109         rename -font -boldfont boldFont Font
     108        usual
     109        rename -font -boldfont boldFont Font
    110110    }
    111111    pack $itk_component(indexLabel) -side left
    112112
    113113    itk_component add indexValue {
    114         label $itk_component(info).ivalue -padx 0
     114        label $itk_component(info).ivalue -padx 0
    115115    }
    116116    pack $itk_component(indexValue) -side left
     
    118118    # add an element.about.label stanza
    119119    itk_component add eleLabel {
    120         label $itk_component(info).elabel -padx 10
     120        label $itk_component(info).elabel -padx 10
    121121    }
    122122    pack $itk_component(eleLabel) -side left
    123123
    124124    itk_component add options {
    125         button $itk_component(player).options -text "Options..." \
    126             -padx 1 -pady 0 -relief flat -overrelief raised
     125        button $itk_component(player).options -text "Options..." \
     126            -padx 1 -pady 0 -relief flat -overrelief raised
    127127    }
    128128    grid $itk_component(options) -row 1 -column 2 -sticky sw
     
    135135
    136136    Rappture::Balloon $itk_component(hull).popup \
    137         -title "Player Settings" -padx 4 -pady 4
     137        -title "Player Settings" -padx 4 -pady 4
    138138    set inner [$itk_component(hull).popup component inner]
    139139
     
    141141    grid $inner.loopl -row 0 -column 0 -sticky e
    142142    radiobutton $inner.loopOn -text "Play once and stop" -font $fn \
    143         -variable ::Rappture::SequenceResult::_play(loop) -value 0
     143        -variable ::Rappture::SequenceResult::_play(loop) -value 0
    144144    grid $inner.loopOn -row 0 -column 1 -sticky w
    145145    radiobutton $inner.loopOff -text "Play continuously" -font $fn \
    146         -variable ::Rappture::SequenceResult::_play(loop) -value 1
     146        -variable ::Rappture::SequenceResult::_play(loop) -value 1
    147147    grid $inner.loopOff -row 1 -column 1 -sticky w
    148148    grid rowconfigure $inner 2 -minsize 8
     
    155155    pack $inner.speed.slowl -side left
    156156    ::scale $inner.speed.value -from 100 -to 1 \
    157         -showvalue 0 -orient horizontal \
    158         -variable ::Rappture::SequenceResult::_play(speed)
     157        -showvalue 0 -orient horizontal \
     158        -variable ::Rappture::SequenceResult::_play(speed)
    159159    pack $inner.speed.value -side left
    160160    label $inner.speed.fastl -text "Faster" -font $fn
     
    162162
    163163    $itk_component(options) configure -command \
    164         [list $itk_component(hull).popup activate $itk_component(options) above]
     164        [list $itk_component(hull).popup activate $itk_component(options) above]
    165165
    166166    #
     
    168168    #
    169169    itk_component add area {
    170         frame $itk_interior.area
     170        frame $itk_interior.area
    171171    }
    172172    pack $itk_component(area) -expand yes -fill both
     
    193193itcl::body Rappture::SequenceResult::add {dataobj {settings ""}} {
    194194    array set params {
    195         -color auto
    196         -brightness 0
    197         -width 1
    198         -raise 0
    199         -linestyle solid
    200         -description ""
    201         -param ""
     195        -color auto
     196        -brightness 0
     197        -width 1
     198        -raise 0
     199        -linestyle solid
     200        -description ""
     201        -param ""
    202202    }
    203203    foreach {opt val} $settings {
    204         if {![info exists params($opt)]} {
    205             error "bad setting \"$opt\": should be [join [lsort [array names params]] {, }]"
    206         }
    207         set params($opt) $val
     204        if {![info exists params($opt)]} {
     205            error "bad setting \"$opt\": should be [join [lsort [array names params]] {, }]"
     206        }
     207        set params($opt) $val
    208208    }
    209209
    210210    if {$params(-raise) && "" == $_topmost} {
    211         set _topmost $dataobj
     211        set _topmost $dataobj
    212212    }
    213213    lappend _dlist $dataobj
     
    227227    set i [lsearch $_dlist $_topmost]
    228228    if {$i >= 0} {
    229         set dlist [lreplace $dlist $i $i]
    230         set dlist [linsert $dlist 0 $_topmost]
     229        set dlist [lreplace $dlist $i $i]
     230        set dlist [linsert $dlist 0 $_topmost]
    231231    }
    232232    return $dlist
     
    241241itcl::body Rappture::SequenceResult::delete {args} {
    242242    if {[llength $args] == 0} {
    243         set args $_dlist
    244     }
     243        set args $_dlist
     244    }
     245    pause
    245246
    246247    # delete all specified curves
    247248    set changed 0
    248249    foreach dataobj $args {
    249         set pos [lsearch -exact $_dlist $dataobj]
    250         if {$pos >= 0} {
    251             set _dlist [lreplace $_dlist $pos $pos]
    252             set changed 1
    253 
    254             if {$dataobj == $_topmost} {
    255                 set _topmost ""
    256             }
    257         }
     250        set pos [lsearch -exact $_dlist $dataobj]
     251        if {$pos >= 0} {
     252            set _dlist [lreplace $_dlist $pos $pos]
     253            set changed 1
     254
     255            if {$dataobj == $_topmost} {
     256                set _topmost ""
     257            }
     258        }
    258259    }
    259260
    260261    # if anything changed, then rebuild the plot
    261262    if {$changed} {
    262         $_dispatcher event -idle !rebuild
     263        $_dispatcher event -idle !rebuild
    263264    }
    264265}
     
    292293    }
    293294    switch $option {
    294         coming {
     295        coming {
    295296            return [$itk_component(area).viewer download coming]
    296         }
    297         controls {
    298             return [eval $itk_component(area).viewer download controls $args]
    299         }
    300         now {
    301             if {0} {
    302                 # produce a movie of results
    303                 set rval ""
    304                 if {"" != $_topmost} {
    305                     set max [$_topmost size]
    306                     set all ""
    307                     for {set i 0} {$i < $max} {incr i} {
    308                         set dataobj [lindex [$_topmost value $i] 0]
    309                         if {[catch {$dataobj tkimage} imh] == 0} {
    310                             lappend all $imh
    311                         }
    312                     }
    313                     if {[llength $all] > 0} {
    314                         set delay [expr {int(ceil(pow($_play(speed)/10.0+2,2.0)*15))}]
    315                         set rval [eval Rappture::icon::gif_animate $delay $all]
    316                     }
    317                 }
    318                 if {[string length $rval] > 0} {
    319                     return [list .gif $rval]
    320                 }
    321                 return ""
    322             }
    323 
    324             # otherwise, return download of single frame
    325             return [$itk_component(area).viewer download now]
    326         }
    327         default {
    328             error "bad option \"$option\": should be coming, controls, now"
    329         }
     297        }
     298        controls {
     299            return [eval $itk_component(area).viewer download controls $args]
     300        }
     301        now {
     302            if {0} {
     303                # produce a movie of results
     304                set rval ""
     305                if {"" != $_topmost} {
     306                    set max [$_topmost size]
     307                    set all ""
     308                    for {set i 0} {$i < $max} {incr i} {
     309                        set dataobj [lindex [$_topmost value $i] 0]
     310                        if {[catch {$dataobj tkimage} imh] == 0} {
     311                            lappend all $imh
     312                        }
     313                    }
     314                    if {[llength $all] > 0} {
     315                        set delay [expr {int(ceil(pow($_play(speed)/10.0+2,2.0)*15))}]
     316                        set rval [eval Rappture::icon::gif_animate $delay $all]
     317                    }
     318                }
     319                if {[string length $rval] > 0} {
     320                    return [list .gif $rval]
     321                }
     322                return ""
     323            }
     324
     325            # otherwise, return download of single frame
     326            return [$itk_component(area).viewer download now]
     327        }
     328        default {
     329            error "bad option \"$option\": should be coming, controls, now"
     330        }
    330331    }
    331332}
     
    346347    # at the end? then restart fresh
    347348    if {$_pos >= [llength $_indices]-1} {
    348         goto 0
     349        goto 0
    349350    }
    350351
    351352    # toggle the button to "pause" mode
    352353    $itk_component(play) configure \
    353         -bitmap [Rappture::icon pause] \
    354         -command [itcl::code $this pause]
     354        -bitmap [Rappture::icon pause] \
     355        -command [itcl::code $this pause]
    355356
    356357    # schedule the first frame
     
    367368itcl::body Rappture::SequenceResult::pause {} {
    368369    if {"" != $_afterId} {
    369         catch {after cancel $_afterId}
    370         set _afterId ""
     370        catch {after cancel $_afterId}
     371        set _afterId ""
    371372    }
    372373
    373374    # toggle the button to "play" mode
    374375    $itk_component(play) configure \
    375         -bitmap [Rappture::icon play] \
    376         -command [itcl::code $this play]
     376        -bitmap [Rappture::icon play] \
     377        -command [itcl::code $this play]
    377378}
    378379
     
    386387itcl::body Rappture::SequenceResult::goto {{newval ""}} {
    387388    if {"" == $newval} {
    388         return $_pos
     389        return $_pos
    389390    }
    390391    set _pos $newval
     
    402403itcl::body Rappture::SequenceResult::_rebuild {args} {
    403404    if {"" == $_topmost && [llength $_dlist] > 0} {
    404         set _topmost [lindex $_dlist 0]
     405        set _topmost [lindex $_dlist 0]
    405406    }
    406407
     
    411412    set viewer $itk_component(area).viewer
    412413    if {[winfo exists $viewer]} {
    413         if {"" == $_topmost} {
    414             pack forget $viewer
    415             pack forget $itk_component(player)
    416             return
    417         } else {
    418             pack $viewer -expand yes -fill both
    419             pack $itk_component(player) -side bottom -fill x
    420         }
     414        if {"" == $_topmost} {
     415            pack forget $viewer
     416            pack forget $itk_component(player)
     417            return
     418        } else {
     419            pack $viewer -expand yes -fill both
     420            pack $itk_component(player) -side bottom -fill x
     421        }
    421422    } else {
    422         if {"" == $_topmost} {
    423             return
    424         }
    425 
    426         set type ""
    427         if {[$_topmost size] > 0} {
    428             set dataobj [lindex [$_topmost value 0] 0]
    429             set type [$dataobj info class]
    430         }
    431         switch -- $type {
    432             ::Rappture::Curve {
    433                 Rappture::XyResult $viewer
    434                 pack $viewer -expand yes -fill both
    435             }
    436             ::Rappture::Image {
    437                 Rappture::ImageResult $viewer
    438                 pack $viewer -expand yes -fill both
    439             }
    440             ::Rappture::Field {
    441                 set dimensions ""
    442                 set dim ""
    443                 foreach dim [$dataobj components -dimensions] {
    444                     # check to see if the dimensions are the same
    445                     # for all elements of the field. i dont think
    446                     # we can display fields of differing dimensions
    447                     # within the same field object.
    448                     if {"" != $dimensions} {
    449                         if {$dimensions != $dim} {
    450                             error "don't know how to view sequences of $type\
    451                                 with dimensions as follows:\
    452                                 [$dataobj components -dimensions]"
    453                         }
    454                     } else {
    455                         set dimensions $dim
    456                     }
    457                 }
    458                 switch -- $dimensions {
    459                     2D {
     423        if {"" == $_topmost} {
     424            return
     425        }
     426
     427        set type ""
     428        if {[$_topmost size] > 0} {
     429            set dataobj [lindex [$_topmost value 0] 0]
     430            set type [$dataobj info class]
     431        }
     432        switch -- $type {
     433            ::Rappture::Curve {
     434                Rappture::XyResult $viewer
     435                pack $viewer -expand yes -fill both
     436            }
     437            ::Rappture::Image {
     438                Rappture::ImageResult $viewer
     439                pack $viewer -expand yes -fill both
     440            }
     441            ::Rappture::Field {
     442                set dimensions ""
     443                set dim ""
     444                foreach dim [$dataobj components -dimensions] {
     445                    # check to see if the dimensions are the same
     446                    # for all elements of the field. i dont think
     447                    # we can display fields of differing dimensions
     448                    # within the same field object.
     449                    if {"" != $dimensions} {
     450                        if {$dimensions != $dim} {
     451                            error "don't know how to view sequences of $type\
     452                                with dimensions as follows:\
     453                                [$dataobj components -dimensions]"
     454                        }
     455                    } else {
     456                        set dimensions $dim
     457                    }
     458                }
     459                switch -- $dimensions {
     460                    2D {
    460461                        if { [$dataobj isunirect2d] } {
    461462                            set mode "heightmap"
     
    464465                        }
    465466                        Rappture::Field2DResult $viewer -mode $mode
    466                     }
    467                     3D {
    468                         Rappture::Field3DResult $viewer
    469                     }
    470                     default {
    471                         error "don't know how to view sequences of $type\
    472                             with $dimensions dimensions"
    473                     }
    474                 }
    475                 pack $viewer -expand yes -fill both
    476             }
    477             ::Rappture::LibraryObj {
    478                 switch -- [$dataobj element -as type] {
    479                     structure {
    480                         Rappture::DeviceResult $viewer
    481                         pack $viewer -expand yes -fill both
    482                     }
    483                     default {
    484                         error "don't know how to view sequences of [$dataobj element -as type]"
    485                     }
    486                 }
    487             }
    488             default {
    489                 puts stderr "don't know how to view sequences of type \"$type\""
     467                    }
     468                    3D {
     469                        Rappture::Field3DResult $viewer
     470                    }
     471                    default {
     472                        error "don't know how to view sequences of $type\
     473                            with $dimensions dimensions"
     474                    }
     475                }
     476                pack $viewer -expand yes -fill both
     477            }
     478            ::Rappture::LibraryObj {
     479                switch -- [$dataobj element -as type] {
     480                    structure {
     481                        Rappture::DeviceResult $viewer
     482                        pack $viewer -expand yes -fill both
     483                    }
     484                    default {
     485                        error "don't know how to view sequences of [$dataobj element -as type]"
     486                    }
     487                }
     488            }
     489            default {
     490                puts stderr "don't know how to view sequences of type \"$type\""
    490491                puts stderr "Is the sequence empty?"
    491492                return
    492             }
    493         }
     493            }
     494        }
    494495    }
    495496
     
    505506    set all ""
    506507    for {set i 0} {$i < $max} {incr i} {
    507         eval lappend all [$_topmost value $i]
     508        eval lappend all [$_topmost value $i]
    508509    }
    509510    eval $viewer scale $all
     
    511512    set _indices ""
    512513    for {set i 0} {$i < $max} {incr i} {
    513         set index [$_topmost index $i]
    514         eval $itk_component(dial) add $index
    515         lappend _indices [lindex $index 0]
     514        set index [$_topmost index $i]
     515        eval $itk_component(dial) add $index
     516        lappend _indices [lindex $index 0]
    516517    }
    517518    _fixValue
     
    530531
    531532    if {$_pos > $last} {
    532         if {$_play(loop)} {
    533             set _pos 0
    534         } else {
    535             set _pos $last
    536             pause
    537             return
    538         }
     533        if {$_play(loop)} {
     534            set _pos 0
     535        } else {
     536            set _pos $last
     537            pause
     538            return
     539        }
    539540    }
    540541    goto $_pos
     
    553554    set viewer $itk_component(area).viewer
    554555    if {![winfo exists $viewer]} {
     556        return
     557    }
     558    $viewer delete
     559    if { $_topmost == "" } {
    555560        return
    556561    }
    557 
    558     # if the indexLabel is empty, don't show indexValue
    559     if {"" != [$_topmost hints indexlabel]} {
    560         set val [$itk_component(dial) get -format label current]
    561         $itk_component(indexValue) configure -text "= $val"
    562         set _pos [lsearch -glob $_indices $val*]
    563     }
    564 
     562    if { "" != [$_topmost hints indexlabel] } {
     563        set val [$itk_component(dial) get -format label current]
     564        $itk_component(indexValue) configure -text "= $val"
     565        set _pos [lsearch -glob $_indices $val*]
     566    }
    565567    # populate the label for this element
    566568    $itk_component(eleLabel) configure -text "[$_topmost label $_pos]"
    567 
    568     $viewer delete
    569     if {"" != $_topmost} {
    570         foreach dataobj [$_topmost value $_pos] {
    571             set settings "-color autoreset -width 2"
    572             if {[catch {$dataobj hints style} style] == 0} {
    573                 eval lappend settings $style
    574             }
    575             $viewer add $dataobj $settings
    576         }
    577     }
    578 }
     569    foreach dataobj [$_topmost value $_pos] {
     570        set settings "-color autoreset -width 2"
     571        if {[catch {$dataobj hints style} style] == 0} {
     572            eval lappend settings $style
     573        }
     574        $viewer add $dataobj $settings
     575    }
     576}
  • trunk/gui/scripts/xyresult.tcl

    r1392 r1394  
    743743    }
    744744
    745     foreach xydata [get] {
     745    foreach xydata $_clist {
    746746        set xmin -Inf
    747747        set ymin -Inf
     
    983983        # - pop up tooltip about data
    984984        #
    985         if {$_hilite(elem) != "" && $_hilite(elem) != $elem} {
     985        if { [$g element exists $_hilite(elem)] && $_hilite(elem) != $elem } {
    986986            $g element deactivate $_hilite(elem)
    987987            $g crosshairs configure -hide yes
     
    10621062        # - take down tooltip
    10631063        #
    1064         if {"" != $_hilite(elem)} {
     1064        if { [$g element exists $_hilite(elem)] } {
    10651065            $g element deactivate $_hilite(elem)
    1066 
    1067             set allx [$g x2axis use]
    1068             if {[llength $allx] > 0} {
    1069                 lappend allx x  ;# fix main x-axis too
    1070                 foreach axis $allx {
    1071                     $g axis configure $axis -color $itk_option(-foreground) \
    1072                         -titlecolor $itk_option(-foreground)
    1073                 }
    1074             }
    1075 
    1076             set ally [$g y2axis use]
    1077             if {[llength $ally] > 0} {
    1078                 lappend ally y  ;# fix main y-axis too
    1079                 foreach axis $ally {
    1080                     $g axis configure $axis -color $itk_option(-foreground) \
    1081                         -titlecolor $itk_option(-foreground)
    1082                 }
     1066        }
     1067        set allx [$g x2axis use]
     1068        if {[llength $allx] > 0} {
     1069            lappend allx x  ;# fix main x-axis too
     1070            foreach axis $allx {
     1071                $g axis configure $axis -color $itk_option(-foreground) \
     1072                    -titlecolor $itk_option(-foreground)
     1073            }
     1074        }
     1075       
     1076        set ally [$g y2axis use]
     1077        if {[llength $ally] > 0} {
     1078            lappend ally y  ;# fix main y-axis too
     1079            foreach axis $ally {
     1080                $g axis configure $axis -color $itk_option(-foreground) \
     1081                    -titlecolor $itk_option(-foreground)
    10831082            }
    10841083        }
     
    10911090        }
    10921091
    1093         # there is no currently highlighted element
     1092        # There is no currently highlighted element
    10941093        set _hilite(elem) ""
    10951094    }
Note: See TracChangeset for help on using the changeset viewer.