Ignore:
Timestamp:
Apr 26, 2006, 6:42:46 PM (18 years ago)
Author:
mmc
Message:
  • Added <description> capability to output objects, including axes.
  • Fixed the ResultSet? so that it is more compact and supports the simulation number as a parameter. This is useful when there are datasets with wildly varying parameters.
File:
1 edited

Legend:

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

    r115 r413  
    2929    itk_option define -min min Min ""
    3030    itk_option define -max max Max ""
     31    itk_option define -variable variable Variable ""
     32
    3133    itk_option define -thickness thickness Thickness 0
    3234    itk_option define -length length Length 0
     
    5052    public method color {value}
    5153                                                                               
     54    protected method _setCurrent {val}
    5255    protected method _redraw {}
    5356    protected method _click {x y}
     
    5558    protected method _limits {}
    5659    protected method _fixSize {}
     60    protected method _fixValue {args}
    5761
    5862    private variable _values ""       ;# list of all values on the dial
    5963    private variable _val2label       ;# maps value => label
    6064    private variable _current ""      ;# current value (where pointer is)
     65    private variable _variable ""     ;# variable associated with -variable
    6166
    6267    private variable _spectrum ""     ;# width allocated for values
     
    103108# ----------------------------------------------------------------------
    104109itcl::body Rappture::Radiodial::destructor {} {
     110    configure -variable ""  ;# remove variable trace
    105111    after cancel [itcl::code $this _redraw]
    106112}
     
    123129
    124130    if {"" == $_current} {
    125         set _current $value
     131        _setCurrent $value
    126132    }
    127133
     
    137143itcl::body Rappture::Radiodial::clear {} {
    138144    set _values ""
    139     set _current ""
     145    _setCurrent ""
    140146    catch {unset _val2label}
    141147
     
    168174        set ilist ""
    169175        for {set i 0} {$i < [llength $_values]} {incr i} {
    170             append ilist $i
     176            lappend ilist $i
    171177        }
    172178    } elseif {"current" == $index} {
     
    235241            error "bad value \"$newval\""
    236242        }
    237         set _current $newval
     243        _setCurrent $newval
    238244
    239245        after cancel [itcl::code $this _redraw]
     
    277283    }
    278284    return $color
     285}
     286
     287# ----------------------------------------------------------------------
     288# USAGE: _setCurrent <value>
     289#
     290# Called automatically whenever the widget changes size to redraw
     291# all elements within it.
     292# ----------------------------------------------------------------------
     293itcl::body Rappture::Radiodial::_setCurrent {value} {
     294    set _current $value
     295    if {"" != $_variable} {
     296        upvar #0 $_variable var
     297        if {[info exists _val2label($value)]} {
     298            set var $_val2label($value)
     299        } else {
     300            set var $value
     301        }
     302    }
    279303}
    280304
     
    389413
    390414        if {$vnearest != $_current} {
    391             set _current $vnearest
     415            _setCurrent $vnearest
    392416            _redraw
    393417
     
    417441        set newval [lindex $_values $index]
    418442        if {$newval != $_current} {
    419             set _current $newval
     443            _setCurrent $newval
    420444            _redraw
    421445
     
    482506
    483507# ----------------------------------------------------------------------
     508# USAGE: _fixValue ?<name1> <name2> <op>?
     509#
     510# Invoked automatically whenever the -variable associated with this
     511# widget is modified.  Copies the value to the current settings for
     512# the widget.
     513# ----------------------------------------------------------------------
     514itcl::body Rappture::Radiodial::_fixValue {args} {
     515    if {"" == $itk_option(-variable)} {
     516        return
     517    }
     518    upvar #0 $itk_option(-variable) var
     519
     520    set newval $var
     521    set found 0
     522    foreach v $_values {
     523        if {[string equal $_val2label($v) $newval]} {
     524            set newval $v
     525            set found 1
     526            break
     527        }
     528    }
     529    if {!$found && "" != $newval} {
     530        error "bad value \"$newval\""
     531    }
     532    set _current $newval  ;# set current directly, so we don't trigger again
     533
     534    after cancel [itcl::code $this _redraw]
     535    after idle [itcl::code $this _redraw]
     536    event generate $itk_component(hull) <<Value>>
     537}
     538
     539# ----------------------------------------------------------------------
    484540# CONFIGURE: -thickness
    485541# ----------------------------------------------------------------------
     
    509565        error "bad value \"$itk_option(-valuewidth)\": should be integer"
    510566    }
     567    _fixSize
    511568    after cancel [itcl::code $this _redraw]
    512569    after idle [itcl::code $this _redraw]
     
    554611    after idle [itcl::code $this _redraw]
    555612}
     613
     614# ----------------------------------------------------------------------
     615# CONFIGURE: -variable
     616# ----------------------------------------------------------------------
     617itcl::configbody Rappture::Radiodial::variable {
     618    if {"" != $_variable} {
     619        upvar #0 $_variable var
     620        trace remove variable var write [itcl::code $this _fixValue]
     621    }
     622
     623    set _variable $itk_option(-variable)
     624
     625    if {"" != $_variable} {
     626        upvar #0 $_variable var
     627        trace add variable var write [itcl::code $this _fixValue]
     628
     629        # sync to the current value of this variable
     630        if {[info exists var]} {
     631            _fixValue
     632        }
     633    }
     634}
Note: See TracChangeset for help on using the changeset viewer.