in reply to Showing pop-up window after x-seconds processing
The basic problem is that while your program is busy importing the data, it cannot tell Tk to do updates to its windows.
The easiest solution if you can manage that is to spawn off a separate program to do the actual data import. That way, you can even create a way to do fully unattended data imports without a GUI.
Another way would be to spawn a thread which does the importing, but using Tk with threads is likely to cause you no end of fancy problems because the resources allocated to Tk in the main thread will (or will not) get shared or recreated in the spawned thread. The same likely holds true when forking a child process.
Another thing you could do is to modify your data import loop to look like this:
my $start_time = time(); # remember when we started my $progress; while (<$input_file>) { ... if (time - $start_time > 2) { # 2 seconds have passed $progress = create_progress_dialog(); Tk->update(); # I don't know if there is such a thing or wheth +er Tk needs it }; }; undef $progress; # hide progress dialog if we have one
Alternatively, you can try to use the Tk facilities like Tk->after():
use Time::HiRes qw(time); my $progress; my $popup = Tk->after( 2, sub { $progress = create_progress_dialog } ) +; my $last_poll = time(); while (<$input_file>) { # let Tk process its events every 0.1 seconds: if (time - $last_poll > 0.1) { Tk->process_one_event(); }; ... }; if ($progress) { undef $progress; }; undef $popup; # cancel our Tk->after() timeout
That way, Tk can also respond when the user clicks on a window or tries to minimize/move it.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Showing pop-up window after x-seconds processing
by fanticla (Scribe) on Aug 07, 2010 at 09:51 UTC | |
by Corion (Patriarch) on Aug 08, 2010 at 08:26 UTC |