Changeset 1076
- Timestamp:
- Jul 18, 2008, 2:02:02 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/examples/zoo/boolean/tool.xml
r875 r1076 33 33 <label>Impact Ionization Model</label> 34 34 <description>Used to enable/disable the effects of impact ionization on the mobility model.</description> 35 <color>purple</color> 35 36 </about> 36 37 <default>true</default> … … 40 41 <label>Impact Ionization Model</label> 41 42 <description>Used to enable/disable the effects of impact ionization on the mobility model.</description> 43 <icon>R0lGODlhGQAZAPAAAP///wAAACH5BAAAAAAALAAAAAAZABkAAAJQhI+py+0dYnByphoZtmDn 44 9WGgxl1ieYiGhHyg+1AVBbFtl0IavtbzToJ1Zqjc6wQ0nVDC1Ian4LhUwmorMyn2bpdV0eb8 45 aa+02NAzNqvXigIAOw== 46 </icon> 42 47 </about> 43 48 <default>1</default> -
trunk/gui/scripts/booleanentry.tcl
r995 r1076 48 48 set _path $path 49 49 50 itk_component add -protected vframe { 51 frame $itk_interior.vframe 52 } 53 54 # if the control has an icon, plug it in 55 set icon [$_owner xml get $path.about.icon] 56 if {$icon != ""} { 57 itk_component add icon { 58 set icon [image create photo -data $icon] 59 set w [image width $icon] 60 set h [image height $icon] 61 canvas $itk_component(vframe).icon -height $h -width $w -borderwidth 0 -highlightthickness 0 62 } { 63 usual 64 ignore -highlightthickness -highlightbackground -highlightcolor 65 } 66 set c $itk_component(icon) 67 $c create image [expr {0.5*$w}] [expr {0.5*$h}] \ 68 -anchor center -image $icon 69 pack $itk_component(icon) -fill x -side left 70 } 71 50 72 # 51 73 # Create the widget and configure it properly based on other … … 53 75 # 54 76 itk_component add switch { 55 Rappture::Switch $itk_interior.switch 56 } 57 pack $itk_component(switch) -expand yes -fill both 58 bind $itk_component(switch) <<Value>> [itcl::code $this _newValue] 59 60 set color [$_owner xml get $path.about.color] 61 if {$color != ""} { 62 $itk_component(switch) configure -oncolor $color 77 set color [$_owner xml get $path.about.color] 78 if {$color != ""} { 79 Rappture::Switch $itk_component(vframe).switch -oncolor $color 80 } else { 81 Rappture::Switch $itk_component(vframe).switch 82 } 63 83 } 64 84 65 # if the control has an icon, plug it in 66 set str [$_owner xml get $path.about.icon] 67 if {$str != ""} { 68 $itk_component(switch) configure -onimage \ 69 [image create photo -data $str] 70 } 71 85 bind $itk_component(switch) <<Value>> [itcl::code $this _newValue] 86 pack $itk_component(switch) -fill x -side left 87 pack $itk_component(vframe) -side left -expand yes -fill both 72 88 eval itk_initialize $args 73 89 -
trunk/gui/scripts/switch.tcl
r995 r1076 2 2 # COMPONENT: switch - on/off switch 3 3 # 4 # This widget is used to control a (boolean) on/off value. It shows 5 # a little light with the state of the switch, and offers a combobox 6 # to control the values. 4 # This widget is used to control a (boolean) on/off value. 5 # It is just a wrapper around a checkbutton. 7 6 # ====================================================================== 8 7 # AUTHOR: Michael McLennan, Purdue University … … 13 12 # ====================================================================== 14 13 package require Itk 15 package require BLT16 17 option add *Switch.width 30 widgetDefault18 option add *Switch.height 20 widgetDefault19 option add *Switch.onColor red widgetDefault20 option add *Switch.offColor gray widgetDefault21 option add *Switch.valuePosition "right" widgetDefault22 option add *Switch.textBackground #cccccc widgetDefault23 14 24 15 itcl::class Rappture::Switch { 25 16 inherit itk::Widget 26 17 27 itk_option define -valueposition valuePosition ValuePosition "" 28 itk_option define -oncolor onColor Color "" 29 itk_option define -offcolor offColor Color "" 30 itk_option define -onimage onImage Image "" 31 itk_option define -offimage offImage Image "" 32 itk_option define -width width Width 0 33 itk_option define -height height Height 0 18 itk_option define -oncolor onColor Color "green" 34 19 itk_option define -state state State "normal" 35 20 36 21 constructor {args} { # defined below } 37 38 22 public method value {args} 39 40 protected method _redraw {} 41 protected method _fixState {} 42 protected method _resize {} 43 protected method _hilite {comp state} 44 protected method _presets {option} 45 46 private variable _value "no" ;# value for this widget 47 48 blt::bitmap define SwitchArrow { 49 #define arrow_width 9 50 #define arrow_height 4 51 static unsigned char arrow_bits[] = { 52 0x7f, 0x00, 0x3e, 0x00, 0x1c, 0x00, 0x08, 0x00}; 53 } 23 private variable _value 0 ;# value for this widget 54 24 } 55 25 56 26 itk::usual Switch { 57 keep -cursor -font -foreground -background 58 keep -selectbackground -selectforeground -selectborderwidth 27 keep -cursor -background 59 28 } 60 29 … … 63 32 # ---------------------------------------------------------------------- 64 33 itcl::body Rappture::Switch::constructor {args} { 65 itk_component add icon {66 canvas $itk_interior.icon -borderwidth 0 -highlightthickness 067 } {68 usual69 ignore -highlightthickness -highlightbackground -highlightcolor70 }71 pack $itk_component(icon) -side left72 bind $itk_component(icon) <Configure> [itcl::code $this _redraw]73 74 itk_component add -protected vframe {75 frame $itk_interior.vframe76 }77 34 78 35 itk_component add value { 79 label $itk_component(vframe).value -borderwidth 1 -width 7 \ 80 -textvariable [itcl::scope _value] 36 checkbutton $itk_interior.value -variable [itcl::scope _value] 81 37 } { 82 38 rename -background -textbackground textBackground Background 83 39 } 84 40 pack $itk_component(value) -side left -expand yes -fill both 85 86 bind $itk_component(value) <Enter> [itcl::code $this _hilite value on] 87 bind $itk_component(value) <Leave> [itcl::code $this _hilite value off] 88 89 itk_component add presets { 90 button $itk_component(vframe).psbtn -bitmap SwitchArrow \ 91 -borderwidth 1 -highlightthickness 0 -relief flat 92 } { 93 usual 94 ignore -borderwidth -relief -highlightthickness 95 rename -background -textbackground textBackground Background 96 } 97 98 bind $itk_component(presets) <Enter> [itcl::code $this _hilite presets on] 99 bind $itk_component(presets) <Leave> [itcl::code $this _hilite presets off] 100 101 itk_component add presetlist { 102 Rappture::Dropdownlist $itk_component(presets).plist \ 103 -postcommand [itcl::code $this _presets post] \ 104 -unpostcommand [itcl::code $this _presets unpost] \ 105 } 106 $itk_component(presetlist) insert end 1 yes 0 no 107 108 bind $itk_component(presetlist) <<DropdownlistSelect>> \ 109 [itcl::code $this _presets select] 110 111 bind $itk_component(value) <ButtonPress> \ 112 [itcl::code $this _presets dropdown] 113 $itk_component(presets) configure -command \ 114 [itcl::code $this _presets dropdown] 115 116 eval itk_initialize $args 41 eval itk_initialize $args 117 42 } 118 43 … … 139 64 error "Should be a boolean value" 140 65 } 141 set newval [expr {($newval) ? "yes" : "no"}] 142 66 set newval [expr {($newval) ? 1 : 0}] 143 67 if {$onlycheck} { 144 68 return 145 69 } 146 70 set _value $newval 147 _fixState148 71 event generate $itk_component(hull) <<Value>> 149 72 … … 151 74 error "wrong # args: should be \"value ?-check? ?newval?\"" 152 75 } 153 return $_value76 return [expr {($_value) ? "yes" : "no"}] 154 77 } 155 78 156 # ----------------------------------------------------------------------157 # USAGE: _redraw158 #159 # Used internally to redraw the gauge on the internal canvas based160 # on the current value and the size of the widget. In this simple161 # base class, the gauge is drawn as a colored block, with an optional162 # image in the middle of it.163 # ----------------------------------------------------------------------164 itcl::body Rappture::Switch::_redraw {} {165 set c $itk_component(icon)166 set w [winfo width $c]167 set h [winfo height $c]168 set s [expr {($w < $h) ? $w : $h}]169 set r [expr {0.5*$s-3}]170 set wm [expr {0.5*$w}]171 set hm [expr {0.5*$h}]172 173 $c delete all174 175 if {$itk_option(-onimage) == "" && $itk_option(-offimage) == ""} {176 $c create oval [expr {$wm-$r+2}] [expr {$hm-$r+2}] \177 [expr {$wm+$r+1}] [expr {$hm+$r+1}] -fill gray -outline ""178 $c create oval [expr {$wm-$r}] [expr {$hm-$r}] \179 [expr {$wm+$r+1}] [expr {$hm+$r+1}] -fill gray -outline ""180 $c create oval [expr {$wm-$r}] [expr {$hm-$r}] \181 [expr {$wm+$r}] [expr {$hm+$r}] -fill "" -outline black \182 -tags main183 184 $c create arc [expr {$wm-$r+2}] [expr {$hm-$r+2}] \185 [expr {$wm+$r-2}] [expr {$hm+$r-2}] -fill "" -outline "" \186 -start 90 -extent -60 -style arc -tags hilite187 188 $c create arc [expr {$wm-$r+2}] [expr {$hm-$r+2}] \189 [expr {$wm+$r-2}] [expr {$hm+$r-2}] -fill "" -outline "" \190 -start -90 -extent -60 -style arc -tags lolite191 } else {192 $c create image [expr {0.5*$w}] [expr {0.5*$h}] \193 -anchor center -image "" -tags bimage194 }195 _fixState196 }197 79 198 80 # ---------------------------------------------------------------------- 199 # USAGE: _fixState 200 # 201 # Used internally to fix the colors associated with the on/off 202 # control. This has an effect only if there is no -onimage or 203 # -offimage. 81 # CONFIGURATION OPTION: -oncolor 204 82 # ---------------------------------------------------------------------- 205 itcl::body Rappture::Switch::_fixState {} { 206 set c $itk_component(icon) 207 208 if {$_value} { 209 if {$itk_option(-onimage) != "" || $itk_option(-offimage) != ""} { 210 $c itemconfigure bimage -image $itk_option(-onimage) 211 } else { 212 set color $itk_option(-oncolor) 213 $c itemconfigure main -fill $color 214 $c itemconfigure hilite -outline \ 215 [Rappture::color::brightness $color 1.0] 216 $c itemconfigure lolite -outline \ 217 [Rappture::color::brightness $color -0.3] 218 } 219 } else { 220 if {$itk_option(-onimage) != "" || $itk_option(-offimage) != ""} { 221 $c itemconfigure bimage -image $itk_option(-offimage) 222 } else { 223 set color $itk_option(-offcolor) 224 $c itemconfigure main -fill $color 225 $c itemconfigure hilite -outline \ 226 [Rappture::color::brightness $color 1.0] 227 $c itemconfigure lolite -outline \ 228 [Rappture::color::brightness $color -0.3] 229 } 230 } 231 } 232 233 # ---------------------------------------------------------------------- 234 # USAGE: _resize 235 # 236 # Used internally to resize the internal canvas based on the -onimage 237 # or -offimage options, or the size of the text. 238 # ---------------------------------------------------------------------- 239 itcl::body Rappture::Switch::_resize {} { 240 if {$itk_option(-width) > 0} { 241 set w $itk_option(-width) 242 } else { 243 set w 0 244 foreach opt {-onimage -offimage} { 245 if {$itk_option($opt) != ""} { 246 set wi [expr {[image width $itk_option($opt)]+4}] 247 if {$wi > $w} { set w $wi } 248 } 249 } 250 if {$w <= 0} { 251 set w [winfo reqheight $itk_component(value)] 252 } 253 } 254 255 if {$itk_option(-height) > 0} { 256 set h $itk_option(-height) 257 } else { 258 set h 0 259 foreach opt {-onimage -offimage} { 260 if {$itk_option($opt) != ""} { 261 set hi [expr {[image height $itk_option($opt)]+4}] 262 if {$hi > $h} { set h $hi } 263 } 264 } 265 if {$h <= 0} { 266 set h [winfo reqheight $itk_component(value)] 267 } 268 } 269 270 $itk_component(icon) configure -width $w -height $h 271 } 272 273 # ---------------------------------------------------------------------- 274 # USAGE: _hilite <component> <state> 275 # 276 # Used internally to resize the internal canvas based on the -onimage 277 # and -offimage options or the size of the text. 278 # ---------------------------------------------------------------------- 279 itcl::body Rappture::Switch::_hilite {comp state} { 280 if {$itk_option(-state) == "disabled"} { 281 set state 0 ;# never hilite when disabled 282 } 283 if {$comp == "value"} { 284 if {$state} { 285 $itk_component(value) configure -relief solid 286 } else { 287 $itk_component(value) configure -relief flat 288 } 289 return 290 } 291 if {$state} { 292 $itk_component($comp) configure -relief solid 293 } else { 294 $itk_component($comp) configure -relief flat 295 } 296 } 297 298 # ---------------------------------------------------------------------- 299 # USAGE: _presets post 300 # USAGE: _presets unpost 301 # USAGE: _presets select 302 # 303 # Used internally to handle the list of presets for this gauge. The 304 # post/unpost options are invoked when the list is posted or unposted 305 # to manage the relief of the controlling button. The select option 306 # is invoked whenever there is a selection from the list, to assign 307 # the value back to the gauge. 308 # ---------------------------------------------------------------------- 309 itcl::body Rappture::Switch::_presets {option} { 310 if {$itk_option(-state) != "normal"} { 311 return ;# disabled? then bail out! 312 } 313 switch -- $option { 314 dropdown { 315 $itk_component(presetlist) post $itk_component(vframe) left 316 } 317 post { 318 set i [$itk_component(presetlist) index $_value] 319 if {$i >= 0} { 320 $itk_component(presetlist) select clear 0 end 321 $itk_component(presetlist) select set $i 322 } 323 after 10 [list $itk_component(presets) configure -relief sunken] 324 } 325 unpost { 326 $itk_component(presets) configure -relief flat 327 } 328 select { 329 set val [$itk_component(presetlist) current] 330 if {"" != $val} { 331 value $val 332 } 333 } 334 default { 335 error "bad option \"$option\": should be dropdown, post, unpost, select" 336 } 337 } 338 } 339 340 # ---------------------------------------------------------------------- 341 # CONFIGURATION OPTION: -onimage 342 # ---------------------------------------------------------------------- 343 itcl::configbody Rappture::Switch::onimage { 344 if {$itk_option(-onimage) != "" 345 && [catch {image width $itk_option(-onimage)}]} { 346 error "bad value \"$itk_option(-onimage)\": should be Tk image" 347 } 348 _resize 349 350 if {$_value} { 351 # if the off state? then redraw to show this change 352 _redraw 353 } 354 } 355 356 # ---------------------------------------------------------------------- 357 # CONFIGURATION OPTION: -offimage 358 # ---------------------------------------------------------------------- 359 itcl::configbody Rappture::Switch::offimage { 360 if {$itk_option(-offimage) != "" 361 && [catch {image width $itk_option(-offimage)}]} { 362 error "bad value \"$itk_option(-offimage)\": should be Tk image" 363 } 364 _resize 365 366 if {!$_value} { 367 # if the off state? then redraw to show this change 368 _redraw 369 } 83 itcl::configbody Rappture::Switch::oncolor { 84 $itk_component(value) configure -selectcolor $itk_option(-oncolor) 370 85 } 371 86 … … 379 94 } 380 95 $itk_component(value) configure -state $itk_option(-state) 381 $itk_component(presets) configure -state $itk_option(-state)382 96 } 383 384 # ----------------------------------------------------------------------385 # CONFIGURATION OPTION: -valueposition386 # ----------------------------------------------------------------------387 itcl::configbody Rappture::Switch::valueposition {388 array set side2anchor {389 left e390 right w391 top s392 bottom n393 }394 set pos $itk_option(-valueposition)395 if {![info exists side2anchor($pos)]} {396 error "bad value \"$pos\": should be [join [lsort [array names side2anchor]] {, }]"397 }398 pack $itk_component(vframe) -before $itk_component(icon) \399 -side $pos -expand yes -fill both -ipadx 2400 $itk_component(value) configure -anchor $side2anchor($pos)401 402 set s [expr {($pos == "left") ? "left" : "right"}]403 pack $itk_component(presets) -before $itk_component(value) \404 -side $s -fill y405 }
Note: See TracChangeset
for help on using the changeset viewer.