Tk Library Source Code

View Ticket
Login
Ticket UUID: 697022
Title: In Button, -repeatdelay command not cancelled on release
Type: Bug Version: None
Submitter: snuffy2 Created on: 2003-03-04 03:12:09
Subsystem: bwidget Assigned To: damonc
Priority: 5 Medium Severity:
Status: Closed Last Modified: 2003-10-21 06:17:26
Resolution: None Closed By: damonc
    Closed on: 2003-10-20 23:17:26
Description:
Say you have a Button that uses the -armcommand -
repeatdelay -repeatinterval commands:

Button .vol.up -image imgvolup  -borderwidth 0 -
highlightthickness 0 -repeatdelay 700 -repeatinterval 
200 -armcommand {VolUp}

(Note: VolUp just increses by 1 the volume)

If you press the .vol.up button repeatedly then hold it 
down it goes much faster than it should.  I think it is 
because the after $delay "Button::_repeat $path" delay 
command is never cancelled when the button is 
released.

I was trying to fix this and was able to do that in 
button.tcl in the Button::_release procedure. I just 
added an after cancel command and it appeared to fix 
the problem:

proc Button::_release { path } {
    variable _current
    variable _pressed

    if { $_pressed == $path } {
        set _pressed ""
        set relief [Widget::getMegawidgetOption $path -
relief]
        #####################
        after cancel "Button::_repeat $path" 
        #####################
        if { ![string compare $relief "link"] } {
            set relief raised
        }
        $path:cmd configure -relief $relief
set cmd [Widget::getMegawidgetOption 
$path -disarmcommand]
        if { $cmd != "" } {
            uplevel \#0 $cmd
        }
        if { $_current == $path &&
             [string compare [$path:cmd cget -
state] "disabled"] && \
     [set cmd [Widget::getMegawidgetOption 
$path -command]] != "" } {
            uplevel \#0 $cmd
        }
    }
}