Ignore:
Timestamp:
Apr 15, 2009, 6:22:24 PM (16 years ago)
Author:
mmc
Message:

Fixed support ticket #5831, which produced an error message like:

can't set _cntlInfo(...): bad value "1e+18/cm3"

The problem arose when you simulated two values like 1e+18 and 1.0e+18.
The Radiodial understood that these were the same value, but it honored
only one of the string representations and rejected the other when you
tried to adjust the dials. It now keeps all recognized string values,
and maps the string onto the real value when you're manipulating the
control. Also fixed the ResultSet? to avoid creating the Radiodial when
the value is numerically the same even though strings are different.

File:
1 edited

Legend:

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

    r1395 r1400  
    6868    protected method _navigate {offset}
    6969    protected method _limits {}
     70    protected method _findLabel {str}
    7071    protected method _fixSize {}
    7172    protected method _fixValue {args}
    7273
    7374    private variable _values ""       ;# list of all values on the dial
    74     private variable _val2label       ;# maps value => label
     75    private variable _val2label       ;# maps value => string label(s)
    7576    private variable _current ""      ;# current value (where pointer is)
    7677    private variable _variable ""     ;# variable associated with -variable
     
    128129        set value [llength $_values]
    129130    }
    130     lappend _values $value
    131     set _values [lsort -real $_values]
    132     set _val2label($value) $label
     131
     132    # Add this value if we've never see it before
     133    if {[lsearch -real $_values $value] < 0} {
     134        lappend _values $value
     135        set _values [lsort -real $_values]
     136    }
     137
     138    # Keep all equivalent strings for this value.
     139    # That way, we can later select either "1e18" or "1.0e+18"
     140    lappend _val2label($value) $label
    133141
    134142    if {"" == $_current} {
     
    199207            label {
    200208                set v [lindex $_values $i]
    201                 $op rlist $_val2label($v)
     209                $op rlist [lindex $_val2label($v) 0]
    202210            }
    203211            value {
     
    214222                foreach {min max} [_limits] break
    215223                set frac [expr {double($v-$min)/($max-$min)}]
    216                 $op rlist [list $_val2label($v) $v $frac]
     224                set l [lindex $_val2label($v) 0]
     225                $op rlist [list $l $v $frac]
    217226            }
    218227            default {
     
    234243    } elseif {[llength $args] == 1} {
    235244        set newval [lindex $args 0]
    236         set found 0
    237         foreach v $_values {
    238             if {[string equal $_val2label($v) $newval]} {
    239                 set newval $v
    240                 set found 1
    241                 break
    242             }
    243         }
    244         if {!$found} {
    245             error "bad value \"$newval\": possible matches are \"[join $_values ,]\""
    246         }
     245        _findLabel $newval  ;# make sure this label is recognized
    247246        _setCurrent $newval
    248247
     
    263262# ----------------------------------------------------------------------
    264263itcl::body Rappture::Radiodial::color {value} {
    265     set found 0
    266     foreach v $_values {
    267         if {[string equal $_val2label($v) $value]} {
    268             set value $v
    269             set found 1
    270             break
    271         }
    272     }
    273     if {!$found} {
    274         error "bad value \"$value\": possible matches are \"[join $_values ,]\""
    275     }
     264    _findLabel $value  ;# make sure this label is recognized
    276265
    277266    if {"" != $_spectrum} {
     
    300289        upvar #0 $_variable var
    301290        if {[info exists _val2label($value)]} {
    302             set var $_val2label($value)
     291            set var [lindex $_val2label($value) 0]
    303292        } else {
    304293            set var $value
     
    422411    set vw $itk_option(-valuewidth)
    423412    if {$vw > 0 && "" != $_current} {
    424         set str $_val2label($_current)
     413        set str [lindex $_val2label($_current) 0]
    425414        if {[string length $str] >= $vw} {
    426415            set str "[string range $str 0 [expr {$vw-3}]]..."
     
    436425
    437426        # set up a tooltip so you can mouse over truncated values
    438         Rappture::Tooltip::text $c $_val2label($_current)
     427        Rappture::Tooltip::text $c [lindex $_val2label($_current) 0]
    439428        $c bind $id <Enter> \
    440429            [list ::Rappture::Tooltip::tooltip pending %W +$x0,$y1]
     
    550539
    551540# ----------------------------------------------------------------------
     541# USAGE: _findLabel <string>
     542#
     543# Used internally to search for the given <string> label among the
     544# known values.  Returns an index into the _values list, or throws
     545# an error if the string is not recognized.  Given the null string,
     546# it returns -1, indicating that the value is not in _values, but
     547# it is valid.
     548# ----------------------------------------------------------------------
     549itcl::body Rappture::Radiodial::_findLabel {str} {
     550    if {"" == $str} {
     551        return -1
     552    }
     553    for {set nv 0} {$nv < [llength $_values]} {incr nv} {
     554        set v [lindex $_values $nv]
     555        if {[lsearch -exact $_val2label($v) $str] >= 0} {
     556            return $nv
     557        }
     558    }
     559    error "bad value \"$str\": should be something matching the raw values \"[join $_values ,]\""
     560}
     561
     562# ----------------------------------------------------------------------
    552563# USAGE: _fixSize
    553564#
     
    615626
    616627    set newval $var
    617     set found 0
    618     foreach v $_values {
    619         if {[string equal $_val2label($v) $newval]} {
    620             set newval $v
    621             set found 1
    622             break
    623         }
    624     }
    625     if {!$found && "" != $newval} {
    626         error "bad value \"$newval\": possible matches are \"[join $_values ,]\""
    627     }
     628    set n [_findLabel $newval]
     629    set newval [expr {($n >= 0) ? [lindex $_values $n] : ""}]
    628630    set _current $newval  ;# set current directly, so we don't trigger again
    629631
Note: See TracChangeset for help on using the changeset viewer.