gleepglop has asked for the wisdom of the Perl Monks concerning the following question:
In the Tk program I've been working on, I have a few different subroutines bound to different keyboard events. I use $widget->Busy() inside of these routines to turn the cursor into an hour glass, as these events may occasionally take a couple of seconds to run without any noticeable changes on the screen.
So my issue is I noticed that when I typed several different event bound key sequences in rapid succession, the events occurred in exactly the reverse order, every time. Though they worked perfectly fine when I keyed in the bound sequences at a slower pace.
What seems to be happening is that when the code gets to the $widget->Busy statement, it pauses until the event queue is clear. So if I type fast enough to generate these events quickly enough, each event's code pauses itself once it gets to the Busy statement until the event after it has completed. capiche? See, the last event typed is the first event to reach it's Busy statement without any other events after it already in the queue, so it actually completes first even though it was generated last.
Now I couldn't actually make this happen on my own pc running activestate perl, I assume because the events were received and executed faster than I could type them. But on a Unix server across the internets I kept having that problem with my code and I wasn't even typing all that fast.
Specifically I was working on some undo/redo routines. And if I type control-z (undo) followed rapidly by control-y (redo) or vice versa they would execute in backwards order. Probably nobody will ever type Undo and Redo as deliberately quickly as I did, and if they do they probably will hardly notice, but still this seems like a big problem to me.
Is anybody else familiar with this situation? I am aware that the cursor can be changed to 'watch' without using Busy. I think that's probably what I will do. But I thought this situation was amusing. I thought it seemed quite intuitive to use the Busy method in my code, but in reality, and due to a feature of Busy that I did not see documented in the documentation for Busy, it turned out to be all wrong.
Unless I'm misunderstanding something and someone else has some insight?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Tk::Widget's Busy method can result in LIFO event execution order?
by Anonymous Monk on Nov 17, 2007 at 11:44 UTC | |
by gleepglop (Novice) on Nov 19, 2007 at 05:26 UTC |