Changeset 1400 for trunk/gui/scripts/radiodial.tcl
- Timestamp:
- Apr 15, 2009, 6:22:24 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/radiodial.tcl
r1395 r1400 68 68 protected method _navigate {offset} 69 69 protected method _limits {} 70 protected method _findLabel {str} 70 71 protected method _fixSize {} 71 72 protected method _fixValue {args} 72 73 73 74 private variable _values "" ;# list of all values on the dial 74 private variable _val2label ;# maps value => label75 private variable _val2label ;# maps value => string label(s) 75 76 private variable _current "" ;# current value (where pointer is) 76 77 private variable _variable "" ;# variable associated with -variable … … 128 129 set value [llength $_values] 129 130 } 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 133 141 134 142 if {"" == $_current} { … … 199 207 label { 200 208 set v [lindex $_values $i] 201 $op rlist $_val2label($v)209 $op rlist [lindex $_val2label($v) 0] 202 210 } 203 211 value { … … 214 222 foreach {min max} [_limits] break 215 223 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] 217 226 } 218 227 default { … … 234 243 } elseif {[llength $args] == 1} { 235 244 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 247 246 _setCurrent $newval 248 247 … … 263 262 # ---------------------------------------------------------------------- 264 263 itcl::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 276 265 277 266 if {"" != $_spectrum} { … … 300 289 upvar #0 $_variable var 301 290 if {[info exists _val2label($value)]} { 302 set var $_val2label($value)291 set var [lindex $_val2label($value) 0] 303 292 } else { 304 293 set var $value … … 422 411 set vw $itk_option(-valuewidth) 423 412 if {$vw > 0 && "" != $_current} { 424 set str $_val2label($_current)413 set str [lindex $_val2label($_current) 0] 425 414 if {[string length $str] >= $vw} { 426 415 set str "[string range $str 0 [expr {$vw-3}]]..." … … 436 425 437 426 # 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] 439 428 $c bind $id <Enter> \ 440 429 [list ::Rappture::Tooltip::tooltip pending %W +$x0,$y1] … … 550 539 551 540 # ---------------------------------------------------------------------- 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 # ---------------------------------------------------------------------- 549 itcl::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 # ---------------------------------------------------------------------- 552 563 # USAGE: _fixSize 553 564 # … … 615 626 616 627 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] : ""}] 628 630 set _current $newval ;# set current directly, so we don't trigger again 629 631
Note: See TracChangeset
for help on using the changeset viewer.