Changeset 1669 for trunk/gui/scripts
- Timestamp:
- Mar 22, 2010, 8:14:29 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/pushbutton.tcl
r1604 r1669 1 2 1 # ---------------------------------------------------------------------- 3 2 # COMPONENT: PushButton - widget for entering a choice of strings … … 34 33 public method select {} 35 34 public method toggle {} 35 public method disable {} 36 public method enable {} 36 37 37 38 protected method _fixValue {args} 38 39 39 40 private variable _state 0 40 public variable command ""; # Command to be invoked 41 private variable _variable ""; # Variable to be set. 42 public variable onimage ""; # Image displayed when selected 43 public variable offimage ""; # Image displayed when deselected. 44 public variable onvalue "1"; # Value set when selected. 45 public variable offvalue "0"; # Value set when deselected. 41 private variable _enabled 1 42 public variable command ""; # Command to be invoked 43 private variable _variable ""; # Variable to be set. 44 public variable onimage ""; # Image displayed when selected 45 public variable offimage ""; # Image displayed when deselected. 46 public variable disabledimage ""; # Image displayed when deselected. 47 public variable onvalue "1"; # Value set when selected. 48 public variable offvalue "0"; # Value set when deselected. 46 49 } 47 50 … … 56 59 itcl::body Rappture::PushButton::constructor {args} { 57 60 itk_component add button { 58 61 label $itk_interior.button -borderwidth 1 -relief sunken 59 62 } { 60 61 63 usual 64 ignore -padx -pady -relief -borderwidth -background 62 65 } 63 66 bind $itk_component(button) <ButtonPress> \ … … 69 72 70 73 itcl::body Rappture::PushButton::invoke {} { 74 if { !$_enabled } { 75 return 76 } 71 77 toggle 72 78 if { $command != "" } { 73 79 uplevel \#0 $command 74 80 } 75 81 } 76 82 77 83 itcl::body Rappture::PushButton::toggle {} { 84 if { !$_enabled } { 85 return 86 } 78 87 set _state [expr !$_state] 79 88 if { $_state } { 80 89 select 81 90 } else { 82 91 deselect 83 92 } 93 } 94 95 itcl::body Rappture::PushButton::disable {} { 96 set _enabled [expr !$_enabled] 97 $itk_component(button) configure -relief raise \ 98 -image $disabledimage -bg grey85 99 } 100 101 itcl::body Rappture::PushButton::enable {} { 102 set _enabled [expr !$_enabled] 103 _fixValue 84 104 } 85 105 … … 93 113 itcl::body Rappture::PushButton::_fixValue {args} { 94 114 if {"" == $itk_option(-variable)} { 95 115 return 96 116 } 97 117 upvar #0 $itk_option(-variable) var 98 118 if { $var == $onvalue } { 99 100 101 119 set _state 1 120 $itk_component(button) configure -relief sunken \ 121 -image $onimage -bg white 102 122 } elseif { $var == $offvalue } { 103 104 105 123 set _state 0 124 $itk_component(button) configure -relief raise \ 125 -image $offimage -bg grey85 106 126 } else { 107 127 puts stderr "unknown value \"$var\": should be \"$offvalue\" or \"onvalue\"" 108 128 } 109 129 } 110 130 111 131 itcl::body Rappture::PushButton::select {} { 132 if { !$_enabled } { 133 return 134 } 112 135 upvar #0 $_variable state 113 136 set state $onvalue … … 115 138 116 139 itcl::body Rappture::PushButton::deselect {} { 140 if { !$_enabled } { 141 return 142 } 117 143 upvar #0 $_variable state 118 144 set state $offvalue … … 125 151 itcl::configbody Rappture::PushButton::variable { 126 152 if {"" != $_variable} { 127 128 153 upvar #0 $_variable var 154 trace remove variable var write [itcl::code $this _fixValue] 129 155 } 130 156 set _variable $itk_option(-variable) 131 157 132 158 if {"" != $_variable} { 133 134 159 upvar #0 $_variable var 160 trace add variable var write [itcl::code $this _fixValue] 135 161 136 137 138 139 162 # sync to the current value of this variable 163 if {[info exists var]} { 164 _fixValue 165 } 140 166 } 141 167 }
Note: See TracChangeset
for help on using the changeset viewer.