Re: Progress Bar question

On Aug 21, 2005, at 8:48 PM, Gergely Korodi wrote:

I need a progress bar to display some status information inside a callback function, but it only reacts once the function exists. In the following code the progress bar works fine if the button's "clicked" signal is connected to cb2, but it bogs down with cb1. How is it possible to do this?
sub cb1 {
    foreach $k (1..20) {
        $fraction += 0.05;
        $fraction = 0 if $fraction > 1;
        print "+++ $k +++\n";
        system "sleep 1";
        $progress -> set_fraction ($fraction);

The call to system() blocks, so the main loop cannot run, and therefore the gui does not update or respond to input. Don't do that.

I assume you have real work happening in the place of "sleep 1"... either fork the child asynchronously, or break the job up into smaller chunks. If you fork asynchronously, you can either just let it go, or use a pipe open to read its output back.

"How do i keep my gui updating during a long file read?" GTK2_2dPerl_2fFrequentlyAskedQuestions#head-3b88c68683fd189b09455a462d5e 41669b7b1142


perldoc perlipc

"Ears! They help us -- Ears! They help us hear th-- Ea--E--E--E-- Ears!"
  -- A Sesame Street singing toy, with Yvonne gleefully pressing
    the button over and over and over and over and...

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]