in reply to Tk::Progressbar gives X Error

I've did a nasty hack and now it works. It doesn't crack, it doesn't hang but it ain't prety.
I had put the code here for educational purposes only :).
#!/usr/bin/perl 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(); my $val = 0; $SIG{USR1} = sub { $val = 0; $progressBar->value(0); $mw->update(); $runCalButton->configure(-state=>"normal"); $cancelCalButton->configure(-state=>"disabled"); }; $SIG{USR2} = sub { $val++; $progressBar->value($val*10); $mw->update(); }; 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 .. 10) { $progressBar->value($_); kill('USR2',$guiPid); sleep(1) ; } # send the signal to main GUI to reconfigure the button states kill('USR1',$guiPid); kill('INT',$$); }

--------------------------------------
"Quoth The Raven Nevermore"
SleepNot a.k.a TheCount

Replies are listed 'Best First'.
Re: Re: Tk::Progressbar gives X Error
by gri6507 (Deacon) on Nov 04, 2003 at 13:20 UTC
    I have tried this approach, but I still got the error (in a couple of different incarnations). If you ran yours, I wonder if maybe you didn't run it for long enough, because, based on what is written above, it is still unsafe due to asynchronous accesses.
      I've ran it longer enough and I didn't have any problems with it. The trick is to have all the Tk/X operations {mw->update and so...) in a single process. Beside of USR1 and USR2, you can try to trapp different signals.
      I know the aproach it's ugly, but for me it works just fine...

      --------------------------------------
      "Quoth The Raven Nevermore"
      SleepNot a.k.a TheCount