gri6507 has asked for the wisdom of the Perl Monks concerning the following question:
I am writing a GUI in Tk. The basic idea is that "work" is selected via the GUI and, once the Run button is clicked, this "work" is executed line by line. Of course, if the user wants to cancel the execution, then simply need to click on the Cancel button. As work is executed, a progress bar displays how much "work" has already been done. The relevant code sections are (pardon the lack of detail, but I didn't want to bore everyone - oh, and I do use strict in the code)
use Tk; use strict; require Tk::ProgressBar; require Tk::Button; my ( $mw, $progressBar, $cancelCalButton, $runCalButton, ); my $guiPid = $$; $mw = MainWindow->new(); $cancelCalButton = $mw->Button(-text=>"cancel")->pack(); $runCalButton = $mw->Button(-text=>"run",-command=>\&doit)->pack(); $progressBar = $mw->ProgressBar()->pack(); $SIG{USR1} = sub { $progressBar->value(0); $mw->update(); $runCalButton->configure(-state=>"normal"); $cancelCalButton->configure(-state=>"disabled"); }; MainLoop; sub doit { my $calPid; $runCalButton->configure(-state=>"disabled"); $cancelCalButton->configure(-state=>"normal"); $mw->update; print "Failed to fork" if (!defined($calPid = fork())); return if ($calPid); for (1 .. 6) { $progressBar->value($_); $mw->update(); sleep(1) } # send the signal to main GUI to reconfigure the button states kill('USR1',$guiPid); kill('INT',$$); }
The Run/Cancel button operation works. Even the progress bar updating works. But, after 2 or 3 updates of the bar, the GUI hangs, and I get the following error message
X Error of failed request: BadIDChoice (invalid resource ID chosen fo +r this connection) Major opcode of failed request: 53 (X_CreatePixmap) Resource id in failed request: 0x1e00077 Serial number of failed request: 1374 Current serial number in output stream: 1300
I am lost on this. Please help. Thank you.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Tk::Progressbar gives X Error
by jdporter (Paladin) on Nov 03, 2003 at 22:20 UTC | |
|
Re: Tk::Progressbar gives X Error
by pg (Canon) on Nov 04, 2003 at 01:52 UTC | |
|
Re: Tk::Progressbar gives X Error
by SleepNot (Pilgrim) on Nov 04, 2003 at 02:34 UTC | |
by gri6507 (Deacon) on Nov 04, 2003 at 13:20 UTC | |
by SleepNot (Pilgrim) on Nov 04, 2003 at 15:02 UTC | |
|
Re: Tk::Progressbar gives X Error
by gri6507 (Deacon) on Nov 04, 2003 at 15:37 UTC |