Getting killed by idle tasks or something else?
- From: bravos_1@xxxxxxxxx
- Date: Wed, 17 Sep 2008 14:31:11 -0700 (PDT)
I have a Tk app that has a large listbox (typically 75-300 items).
When a user selects an item in the list it drives various image and
text objects to be drawn to a canvas. The app also interacts w/ a cgi
script on a non-local server.
I have bindings for <button-1> and the arrow keys to perform the
necessary tasks for the selected listbox item but the tasks depending
on what was clicked may take a few seconds to complete.
Wat I noticed is that I could really bork up the app my clicking
several listbox items before the tasks were complete. I put in a
$listbox->grab before doing anything and releasing the grab when
complete as this seemed the best way to combat against this. Now the
grab works, but takes ~.5 seconds before it is actually "grabs" and I
can still do multi clicks. I wrote a small script to verify that it
should work as I expected and in fact it does (the grab is basically
immediate after the list item is clicked).
I am running idletasks pretty regularly, but assumed that it was not
enough, but I see the behavior immediately in my app. I even tried
$mw->idletasks and $mw->update immediately before calling MainLoop
(redundant, I know), but even my first click in the listbox has a
delay before the grab happens. Below is the sample script I used to
verify, and of course it works as expected but illustrates exactly how
I am using it.
use strict;
use warnings;
use Tk;
my $mw = new MainWindow;
my $listbox = $mw->Scrolled('Listbox',
-scrollbars => "e",
-width => 15,
)->pack();
$listbox->insert('end', $_) for (1 .. 100);
$listbox->bind("<Button-1>", [\&list_click]);
MainLoop;
sub list_click {
my ($widget) = @_;
$widget->grab;
$widget->configure(-cursor => 'watch');
sleep 3;
$mw->messageBox(-title => 'Click Event',
-message => $listbox->get($listbox->curselection),
-type => 'OK');
$widget->configure(-cursor => 'arrow');
$widget->grabRelease;
}
Anyone have a thought or two?
Also, since I'm on the topic of idletasks, how often should I be
calling it (ie after which types of tasks?). Right now I am calling
it after dealing with Tk::Photo images and in places where I feel
there has been a longish time since the last idletask/update call.
Thanks,
Eric
.
- Follow-Ups:
- Re: Getting killed by idle tasks or something else?
- From: Petr Vileta \(fidokomik\)
- Re: Getting killed by idle tasks or something else?
- From: bravos_1
- Re: Getting killed by idle tasks or something else?
- From: bravos_1
- Re: Getting killed by idle tasks or something else?
- Prev by Date: Re: Tk::Entry and unicode/UTF8 file name problems
- Next by Date: Re: Getting killed by idle tasks or something else?
- Previous by thread: dialogs on dual displays
- Next by thread: Re: Getting killed by idle tasks or something else?
- Index(es):
Loading