Changeset 1669 for trunk/gui/scripts


Ignore:
Timestamp:
Mar 22, 2010, 8:14:29 PM (15 years ago)
Author:
dkearney
Message:

adding enable and disable to pushbutton widget so we can have a disable's pushbutton

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/scripts/pushbutton.tcl

    r1604 r1669  
    1 
    21# ----------------------------------------------------------------------
    32#  COMPONENT: PushButton - widget for entering a choice of strings
     
    3433    public method select {}
    3534    public method toggle {}
     35    public method disable {}
     36    public method enable {}
    3637
    3738    protected method _fixValue {args}
    3839
    3940    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.
    4649}
    4750
     
    5659itcl::body Rappture::PushButton::constructor {args} {
    5760    itk_component add button {
    58         label $itk_interior.button -borderwidth 1 -relief sunken
     61        label $itk_interior.button -borderwidth 1 -relief sunken
    5962    } {
    60         usual
    61         ignore -padx -pady -relief -borderwidth -background
     63        usual
     64        ignore -padx -pady -relief -borderwidth -background
    6265    }
    6366    bind $itk_component(button) <ButtonPress> \
     
    6972
    7073itcl::body Rappture::PushButton::invoke {} {
     74    if { !$_enabled } {
     75        return
     76    }
    7177    toggle
    7278    if { $command != "" } {
    73         uplevel \#0 $command
     79        uplevel \#0 $command
    7480    }
    7581}
    7682
    7783itcl::body Rappture::PushButton::toggle {} {
     84    if { !$_enabled } {
     85        return
     86    }
    7887    set _state [expr !$_state]
    7988    if { $_state } {
    80         select
     89        select
    8190    } else {
    82         deselect
     91        deselect
    8392    }
     93}
     94
     95itcl::body Rappture::PushButton::disable {} {
     96    set _enabled [expr !$_enabled]
     97    $itk_component(button) configure -relief raise \
     98        -image $disabledimage -bg grey85
     99}
     100
     101itcl::body Rappture::PushButton::enable {} {
     102    set _enabled [expr !$_enabled]
     103    _fixValue
    84104}
    85105
     
    93113itcl::body Rappture::PushButton::_fixValue {args} {
    94114    if {"" == $itk_option(-variable)} {
    95         return
     115        return
    96116    }
    97117    upvar #0 $itk_option(-variable) var
    98118    if { $var == $onvalue } {
    99         set _state 1
    100         $itk_component(button) configure -relief sunken \
    101             -image $onimage -bg white
     119        set _state 1
     120        $itk_component(button) configure -relief sunken \
     121            -image $onimage -bg white
    102122    } elseif { $var == $offvalue } {
    103         set _state 0
    104         $itk_component(button) configure -relief raise \
    105             -image $offimage -bg grey85
     123        set _state 0
     124        $itk_component(button) configure -relief raise \
     125            -image $offimage -bg grey85
    106126    } else {
    107         puts stderr "unknown value \"$var\": should be \"$offvalue\" or \"onvalue\""
     127        puts stderr "unknown value \"$var\": should be \"$offvalue\" or \"onvalue\""
    108128    }
    109129}
    110130
    111131itcl::body Rappture::PushButton::select {} {
     132    if { !$_enabled } {
     133        return
     134    }
    112135    upvar #0 $_variable state
    113136    set state $onvalue
     
    115138
    116139itcl::body Rappture::PushButton::deselect {} {
     140    if { !$_enabled } {
     141        return
     142    }
    117143    upvar #0 $_variable state
    118144    set state $offvalue
     
    125151itcl::configbody Rappture::PushButton::variable {
    126152    if {"" != $_variable} {
    127         upvar #0 $_variable var
    128         trace remove variable var write [itcl::code $this _fixValue]
     153        upvar #0 $_variable var
     154        trace remove variable var write [itcl::code $this _fixValue]
    129155    }
    130156    set _variable $itk_option(-variable)
    131157
    132158    if {"" != $_variable} {
    133         upvar #0 $_variable var
    134         trace add variable var write [itcl::code $this _fixValue]
     159        upvar #0 $_variable var
     160        trace add variable var write [itcl::code $this _fixValue]
    135161
    136         # sync to the current value of this variable
    137         if {[info exists var]} {
    138             _fixValue
    139         }
     162        # sync to the current value of this variable
     163        if {[info exists var]} {
     164            _fixValue
     165        }
    140166    }
    141167}
Note: See TracChangeset for help on using the changeset viewer.