Changeset 413 for trunk/gui/scripts/radiodial.tcl
- Timestamp:
- Apr 26, 2006, 6:42:46 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/radiodial.tcl
r115 r413 29 29 itk_option define -min min Min "" 30 30 itk_option define -max max Max "" 31 itk_option define -variable variable Variable "" 32 31 33 itk_option define -thickness thickness Thickness 0 32 34 itk_option define -length length Length 0 … … 50 52 public method color {value} 51 53 54 protected method _setCurrent {val} 52 55 protected method _redraw {} 53 56 protected method _click {x y} … … 55 58 protected method _limits {} 56 59 protected method _fixSize {} 60 protected method _fixValue {args} 57 61 58 62 private variable _values "" ;# list of all values on the dial 59 63 private variable _val2label ;# maps value => label 60 64 private variable _current "" ;# current value (where pointer is) 65 private variable _variable "" ;# variable associated with -variable 61 66 62 67 private variable _spectrum "" ;# width allocated for values … … 103 108 # ---------------------------------------------------------------------- 104 109 itcl::body Rappture::Radiodial::destructor {} { 110 configure -variable "" ;# remove variable trace 105 111 after cancel [itcl::code $this _redraw] 106 112 } … … 123 129 124 130 if {"" == $_current} { 125 set _current $value131 _setCurrent $value 126 132 } 127 133 … … 137 143 itcl::body Rappture::Radiodial::clear {} { 138 144 set _values "" 139 set _current ""145 _setCurrent "" 140 146 catch {unset _val2label} 141 147 … … 168 174 set ilist "" 169 175 for {set i 0} {$i < [llength $_values]} {incr i} { 170 append ilist $i176 lappend ilist $i 171 177 } 172 178 } elseif {"current" == $index} { … … 235 241 error "bad value \"$newval\"" 236 242 } 237 set _current $newval243 _setCurrent $newval 238 244 239 245 after cancel [itcl::code $this _redraw] … … 277 283 } 278 284 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 # ---------------------------------------------------------------------- 293 itcl::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 } 279 303 } 280 304 … … 389 413 390 414 if {$vnearest != $_current} { 391 set _current $vnearest415 _setCurrent $vnearest 392 416 _redraw 393 417 … … 417 441 set newval [lindex $_values $index] 418 442 if {$newval != $_current} { 419 set _current $newval443 _setCurrent $newval 420 444 _redraw 421 445 … … 482 506 483 507 # ---------------------------------------------------------------------- 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 # ---------------------------------------------------------------------- 514 itcl::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 # ---------------------------------------------------------------------- 484 540 # CONFIGURE: -thickness 485 541 # ---------------------------------------------------------------------- … … 509 565 error "bad value \"$itk_option(-valuewidth)\": should be integer" 510 566 } 567 _fixSize 511 568 after cancel [itcl::code $this _redraw] 512 569 after idle [itcl::code $this _redraw] … … 554 611 after idle [itcl::code $this _redraw] 555 612 } 613 614 # ---------------------------------------------------------------------- 615 # CONFIGURE: -variable 616 # ---------------------------------------------------------------------- 617 itcl::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.