For Programmers: Free Programming Magazines  


Home > Archive > Tcl > November 2007 > Workaround Re: Tktable browsecommand question









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Workaround Re: Tktable browsecommand question
John Seal

2007-11-21, 10:15 pm

John Seal wrote:
> after 2000 set ::Done 1; tkwait variable ::Done


> I'm thinking that the way to handle that is to check at the
> very end of the browsecommand whether another cell has been activated
> and, if so, process it.


Here's an update. My demo code has a bug in the simulated lengthy
event-looping browsecommand. It turns out that browsecommands can nest,
so it has to wait for the specific cell being processed.

The updated demo shown below also shows that my proposed fix does indeed
work. If you comment out the fix, it still exhibits the behavior that I
originally questioned.

package require Tktable
set ::Format "%8s %8s %8s %8s %s"
proc log {cell {tag ""} {mark ""}} {
set act [.t tag cell active]
set sel [.t tag cell sel]
puts [format $::Format $tag $cell $act $sel $mark]
}
proc browse {cell} {
log $cell browse \\
update idletasks
# Works if you comment out everything after 2000, or change
# the table -browsecommand to {after idle browse %C}
after 2000 set ::Done($cell) 1; tkwait variable ::Done($cell)
log $cell done /
# Workaround for possibly ignoring the last click.
# Cancel and reschedule to avoid piling up checks.
set ::LastBrowsed $cell
after cancel check
after idle check
}
proc check {} {
set act [.t tag cell active]
if {$::LastBrowsed ne $act} {browse $act}
}
table .t -state disabled -selectmode extended -exportselection false \
-browsecommand {browse %C}
bind .t <1> {log [%W index @%x,%y] click}
pack .t
puts [format $::Format "" cell active select ""]
catch {console show}

The format of the output has been improved, with brackets added to make
it easy to spot browse/done pairs. When I ran this demo, then clicked on
the top left cell and the 5 below it, I got this output:

cell active select
click 0,0
browse 0,0 0,0 0,0 \
click 1,0 0,0 0,0
click 2,0 1,0 1,0
click 3,0 2,0 2,0
done 0,0 3,0 3,0 /
browse 3,0 3,0 3,0 \
click 4,0 3,0 3,0
browse 4,0 4,0 4,0 \
click 5,0 4,0 4,0
done 4,0 5,0 5,0 /
done 3,0 5,0 5,0 /
browse 5,0 5,0 5,0 \
done 5,0 5,0 5,0 /

Note that the browsecommand for cells 3,0 and 4,0 nested, and that the
last click on 5,0 was sucessfully picked up. If you comment out the
workaround and repeat the run, the last click is sometimes ignored.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com