Changeset 6021 for trunk/gui/scripts/gauge.tcl
- Timestamp:
- Feb 18, 2016, 4:13:14 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
-
trunk/gui/scripts/gauge.tcl
r5659 r6021 42 42 itk_option define -sampleheight sampleHeight SampleHeight 0 43 43 itk_option define -log log Log "" 44 itk_option define -varname varname Varname "" 45 itk_option define -label label Label "" 44 46 itk_option define -validatecommand validateCommand ValidateCommand "" 47 itk_option define -uq uq Uq no 45 48 46 49 constructor {args} { # defined below } … … 57 60 protected method _layout {} 58 61 protected method _log {event args} 62 protected method _change_param_type {choice} 63 protected method _pop_uq {win} 64 protected method _pop_uq_deactivate {} 59 65 60 66 private variable _value 0 ;# value for this widget 67 private variable _mode exact ;# current mode 68 private variable _pde "" ;# ProbDistEditor 69 private variable _val "" ;# value choice combobox 70 private variable uq no 61 71 62 72 blt::bitmap define GaugeArrow { … … 77 87 # ---------------------------------------------------------------------- 78 88 itcl::body Rappture::Gauge::constructor {args} { 89 # puts "GAUGE CONS: $args" 90 array set attrs $args 91 79 92 itk_option remove hull.borderwidth hull.relief 80 93 component hull configure -borderwidth 0 … … 90 103 bind $itk_component(icon) <Configure> [itcl::code $this _redraw] 91 104 105 if {[info exists attrs(-uq)]} { 106 set uq $attrs(-uq) 107 if {[string is true $uq]} { 108 set uq 1 109 itk_component add uq { 110 button $itk_interior.uq -image [Rappture::icon UQ] \ 111 -command [itcl::code $this _pop_uq $itk_interior] 112 } 113 pack $itk_component(uq) -side right -padx 10 114 } else { 115 set uq 0 116 } 117 } else { 118 set uq 0 119 } 120 92 121 itk_component add -protected vframe { 93 122 frame $itk_interior.vframe … … 97 126 98 127 itk_component add value { 99 label $itk_component(vframe).value -width 7\128 label $itk_component(vframe).value -width 20 \ 100 129 -borderwidth 1 -relief flat -textvariable [itcl::scope _value] 101 130 } { … … 199 228 # ---------------------------------------------------------------------- 200 229 itcl::body Rappture::Gauge::value {args} { 201 set onlycheck 0 230 #puts "Gauge value: $args" 231 232 # Query. Just return the current value. 233 if {[llength $args] == 0} { 234 return $_value 235 } 236 202 237 set i [lsearch -exact $args -check] 203 238 if {$i >= 0} { 204 239 set onlycheck 1 205 240 set args [lreplace $args $i $i] 206 } 207 208 if {[llength $args] == 1} { 209 # 210 # If this gauge has -units, try to convert the incoming 211 # value to that system of units. Also, make sure that 212 # the value is bound by any min/max value constraints. 213 # 214 # Keep track of the inputted units so we can give a 215 # response about min and max values in familiar units. 216 # 217 set newval [set nv [string trim [lindex $args 0]]] 218 set units $itk_option(-units) 219 if {"" != $units} { 220 set newval [Rappture::Units::convert $newval -context $units] 221 set nvUnits [Rappture::Units::Search::for $newval] 222 if { "" == $nvUnits} { 223 set msg [Rappture::Units::description $units] 224 error "unrecognized units in value \"$newval\": should be value with units of $msg" 225 } 226 set nv [Rappture::Units::convert $nv \ 227 -context $units -to $units -units off] 228 229 # Normalize the units name 230 set newval [Rappture::Units::convert $newval -units off]$nvUnits 231 } 232 233 switch -- $itk_option(-type) { 234 integer { 235 if { [scan $nv "%g" value] != 1 || int($nv) != $value } { 236 error "bad value \"$nv\": should be an integer value" 237 } 238 } 239 real { 240 # "scan" will reject the number if the string is "NaN" or 241 # "Inf" or the empty string. It also is accepts large numbers 242 # (e.g. 111111111111111111111) that "string is double" 243 # rejects. The problem with "scan" is that it doesn't care if 244 # there are extra characters trailing the number (eg. "123a"). 245 # The extra %s substitution is used to detect this case. 246 if { [scan $nv "%g%s" dummy1 dummy2] != 1 } { 247 error "bad value \"$nv\": should be a real number" 248 } 249 } 250 } 251 252 if {"" != $itk_option(-minvalue)} { 253 set convMinVal [set minv $itk_option(-minvalue)] 254 if {"" != $units} { 255 set minv [Rappture::Units::convert $minv \ 256 -context $units -to $units -units off] 257 set convMinVal [Rappture::Units::convert \ 258 $itk_option(-minvalue) -context $units -to $nvUnits] 259 } else { 260 set newval [format "%g" $newval] 261 } 262 263 # fix for the case when the user tries to 264 # compare values like minv=-500 nv=-0600 265 set nv [format "%g" $nv] 266 set minv [format "%g" $minv] 267 268 if {$nv < $minv} { 269 error "minimum value allowed here is $convMinVal" 270 } 271 } 272 273 if {"" != $itk_option(-maxvalue)} { 274 set convMaxVal [set maxv $itk_option(-maxvalue)] 275 if {"" != $units} { 276 set maxv [Rappture::Units::convert $maxv \ 277 -context $units -to $units -units off] 278 set convMaxVal [Rappture::Units::convert \ 279 $itk_option(-maxvalue) -context $units -to $nvUnits] 280 } else { 281 set newval [format "%g" $newval] 282 } 283 284 # fix for the case when the user tries to 285 # compare values like maxv=500 nv=0600 286 set nv [format "%g" $nv] 287 set maxv [format "%g" $maxv] 288 289 if {$nv > $maxv} { 290 error "maximum value allowed here is $convMaxVal" 291 } 292 } 293 294 # 295 # If there's a -validatecommand option, then invoke the code 296 # now to check the new value. 297 # 298 if {[string length $itk_option(-validatecommand)] > 0} { 299 set cmd "uplevel #0 [list $itk_option(-validatecommand) [list $newval]]" 300 set result [eval $cmd] 301 } 302 303 if {$onlycheck} { 304 return 305 } 306 307 set _value $newval 308 309 _redraw 310 event generate $itk_component(hull) <<Value>> 311 312 } elseif {[llength $args] != 0} { 241 } else { 242 set onlycheck 0 243 } 244 245 if {[llength $args] != 1} { 313 246 error "wrong # args: should be \"value ?-check? ?newval?\"" 247 } 248 249 set newval [Rappture::Units::mcheck_range [lindex $args 0] \ 250 $itk_option(-minvalue) $itk_option(-maxvalue) $itk_option(-units)] 251 252 set newmode [lindex $newval 0] 253 switch -- $newmode { 254 uniform - 255 gaussian { 256 set _mode $newmode 257 } 258 exact - 259 default { 260 set _mode exact 261 } 262 } 263 264 switch -- $itk_option(-type) { 265 integer { 266 if { [scan $newval "%g" value] != 1 || int($newval) != $value } { 267 error "bad value \"$newval\": should be an integer value" 268 } 269 } 270 } 271 272 # 273 # If there's a -validatecommand option, then invoke the code 274 # now to check the new value. 275 # 276 if {[string length $itk_option(-validatecommand)] > 0} { 277 set cmd "uplevel #0 [list $itk_option(-validatecommand) [list $newval]]" 278 set result [eval $cmd] 279 } 280 281 if {$onlycheck} { 282 return 283 } 284 285 set _value $newval 286 $itk_component(value) configure -width [string length $_value] 287 _redraw 288 event generate $itk_component(hull) <<Value>> 289 290 if {"" != $_pde} { 291 set val [$_val translate [$_val value]] 292 $_val value $_mode 293 $_pde value $_value 294 314 295 } 315 296 return $_value … … 494 475 # ---------------------------------------------------------------------- 495 476 itcl::body Rappture::Gauge::_editor {option args} { 477 # puts "Gauge::editor option=$option args=$args" 496 478 if {$itk_option(-state) == "disabled"} { 497 479 return ;# disabled? then bail out here! … … 515 497 } 516 498 set val [lindex $args 0] 517 518 499 if {[catch {value -check $val} result]} { 519 500 if {[regexp {allowed here is (.+)} $result match newval]} { … … 597 578 } 598 579 580 if {$itk_option(-type) != "integer" && $uq} { 581 pack $itk_component(uq) -side right -padx 10 582 } 583 599 584 array set side2anchor { 600 585 left e … … 744 729 } 745 730 } 731 732 itcl::body Rappture::Gauge::_pop_uq {win} { 733 # puts "min=$itk_option(-minvalue) max=$itk_option(-maxvalue) units=$itk_option(-units)" 734 set varname $itk_option(-varname) 735 set popup .pop_uq_$varname 736 if { ![winfo exists $popup] } { 737 Rappture::Balloon $popup -title $itk_option(-label) 738 set inner [$popup component inner] 739 frame $inner.type 740 pack $inner.type -side top -fill x 741 label $inner.type.l -text "Parameter Value:" 742 pack $inner.type.l -side left 743 744 set _val [Rappture::Combobox $inner.type.val -width 20 -editable no] 745 pack $_val -side left -expand yes -fill x 746 $_val choices insert end exact "Exact Value" 747 $_val choices insert end uniform "Uniform Distribution" 748 $_val choices insert end gaussian "Gaussian Distribution" 749 bind $_val <<Value>> [itcl::code $this _change_param_type $inner] 750 751 set _pde [Rappture::ProbDistEditor $inner.entry \ 752 $itk_option(-minvalue) $itk_option(-maxvalue) $itk_option(-units) $_value] 753 $_val value $_mode 754 $_pde value $_value 755 pack $inner.entry -expand yes -fill both -pady {10 0} 756 757 $popup configure \ 758 -deactivatecommand [itcl::code $this _pop_uq_deactivate] 759 } 760 update 761 $popup activate $win right 762 } 763 764 itcl::body Rappture::Gauge::_pop_uq_deactivate {} { 765 # puts "deactivate [$_pde value]" 766 value [$_pde value] 767 } 768 769 itcl::body Rappture::Gauge::_change_param_type {inner} { 770 set val [$_val translate [$_val value]] 771 $_pde mode $val 772 }
Note: See TracChangeset
for help on using the changeset viewer.