- Timestamp:
- Apr 15, 2009 6:22:24 PM (15 years ago)
- Location:
- trunk/gui/scripts
- Files:
-
- 2 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 -
trunk/gui/scripts/resultset.tcl
r1399 r1400 66 66 protected method _toggleAll {{column "current"}} 67 67 protected method _getValues {column {which ""}} 68 protected method _getRawValues {column {which ""}}69 68 protected method _getTooltip {role column} 70 69 protected method _getParamDesc {which {index "current"}} … … 283 282 continue 284 283 } 285 if {[$_results column names $vpath] == ""} { 284 285 # make sure that these values really are different 286 set oldval [lindex [Rappture::LibraryObj::value $xmlobj0 $vpath] 0] 287 set newval [lindex [Rappture::LibraryObj::value $xmlobj $vpath] 0] 288 289 if {$oldval != $newval && [$_results column names $vpath] == ""} { 286 290 # no column for this quantity yet 287 291 $_results column insert end -name $vpath -default $oldval … … 653 657 654 658 $dial clear 655 foreach {label val} [_get RawValues $col all] {659 foreach {label val} [_getValues $col all] { 656 660 $dial add $label $val 657 661 } … … 1525 1529 1526 1530 # ---------------------------------------------------------------------- 1527 # USAGE: _getRawValues <column> ?<which>?1528 #1529 # Called automatically whenever the user hovers a control within1530 # this widget. Returns the tooltip associated with the control.1531 # ----------------------------------------------------------------------1532 itcl::body Rappture::ResultSet::_getRawValues {col {which ""}} {1533 if {$col == "xmlobj"} {1534 # load the Simulation # control1535 set nruns [$_results size]1536 for {set n 0} {$n < $nruns} {incr n} {1537 set v "#[expr {$n+1}]"1538 set label2val($v) $n1539 }1540 } else {1541 set vlist ""1542 foreach rec [$_results get -format [list xmlobj $col]] {1543 lappend vlist [lindex $rec 1]1544 }1545 # Don't have normalized. Sort and create nums1546 set n 01547 foreach v [lsort $vlist] {1548 incr n1549 set label2val($v) $n1550 }1551 }1552 switch -- $which {1553 current {1554 set curr $_cntlInfo($this-$col-value)1555 if {[info exists label2val($curr)]} {1556 return [list $curr $label2val($curr)]1557 }1558 return ""1559 }1560 all {1561 return [array get label2val]1562 }1563 default {1564 if {[string is integer $which]} {1565 if {$col == "xmlobj"} {1566 set val "#[expr {$which+1}]"1567 } else {1568 set val [lindex [$_results get -format $col $which] 0]1569 }1570 if {[info exists label2val($val)]} {1571 return [list $val $label2val($val)]1572 }1573 return ""1574 }1575 error "bad option \"$which\": should be all, current, or an integer index"1576 }1577 }1578 }1579 1580 # ----------------------------------------------------------------------1581 1531 # USAGE: _getTooltip <role> <column> 1582 1532 #
Note: See TracChangeset
for help on using the changeset viewer.