Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re^2: Perl::Gtk2, Looking for a Widget Similar to HourGlass

by mmartin (Monk)
on Jul 22, 2013 at 20:09 UTC ( #1045714=note: print w/replies, xml ) Need Help??

in reply to Re: Perl::Gtk2, Looking for a Widget Similar to HourGlass
in thread Perl::Gtk2, Looking for a Widget Similar to HourGlass

Hey Monks, finally got a solution to work.

I decided to go with using the GIF image instead of the ProgressBar and running the Background Job using
the "Proc::Background" Module.

The code below is what will happen when you press the "Submit" button in my program. Basically you click
submit then the function/sub below gets executed. Inside this Function my Pop-Up window gets ran, which contains
the GIF image I mentioned before. Then the Background Job gets started, and I use a while loop to continuously check
if the Job is still "alive". Inside that while loop is another while loop that causes Gtk2 to continue processing
while there are still events to be ran, so that causes the GIF image to continue "spinning". Otherwise, without the
INNER while loop the GIF image inside the popup would pause/stop completely until the OUTER while loop had finished
executing because of the "sleep" or "usleep" commands which cause Gtk2 to pause.
sub submit_function() { print "YOU CLICKED SUBMIT...\n"; print "Run Background Job... And Open 'Loading...' Pop-Up Window\n"; $popup_window->show_all(); my $command = "/path/to/command/"; ### Start running the Background Job: my $proc = Proc::Background->new($command, "5"); my $PID = $proc->pid; my $start_time = $proc->start_time; my $alive = $proc->alive; ### While $alive is NOT '0', then keep checking till it is... # *When $alive is '0', it has finished executing. while($alive ne 0) { $alive = $proc->alive; # This while loop will cause Gtk2 to conti processing events, if # there are events pending... *which there are... while (Gtk2->events_pending) { Gtk2->main_iteration; } Gtk2::Gdk->flush; usleep(1000); } my $end_time = $proc->end_time; print "*Command Completed at $end_time, with PID = $PID\n\n"; # Since the while loop has exited, the BG job has finished running: # so close the pop-up window... $popup_window->hide; # Get the RETCODE from the Background Job using the 'wait' method my $retcode = $proc->wait; $retcode /= 256; print "\t*RETCODE == $retcode\n\n"; ### Check if the RETCODE returned with an Error: if ($retcode ne 0) { print "Error: The Background Job returned with an Error...!\n"; } else { print "Success: The Background Job Completed Successfully...!\n"; } }

So anyway... Thanks guys for all your help with this... Much Appreciated!

I forgot to mention, the reason I use the usleep() command instead of just "sleep 1;" or something like that is because there would
be a slight pause in the GIF image on every loop inside the while loop. So by using the usleep command it loops so quickly that you
cannot notice that it is pausing or not...

Thanks Again,

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1045714]
and the shadows deepen...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2017-03-23 20:23 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (294 votes). Check out past polls.