Re: progress, statusbar, update




Mario Ospelt said:
sub details {
    my @par = @_;
    my @IDs = @{$par[1]};
    $status -> push($cont_id,"Open report...");
    Gtk2 -> main_iteration;
    foreach (@IDs){
        push (@temp_pdfs, &make_pdf);
    }
    $status -> pop($cont_id);
}

1. The make_pdf subroutine in the foreach loop creates a pdf file and
opens it in the Acrobat Reader. This process takes a while and therefore
I want to let the user know of the progress. At first I wanted to set
the comment in the statusbar. But it doesn't appear in the GUI. Is there
something wrong with using Gtk2 -> main_iteration?

Your code calls main_iteration *before* doing a whole bunch of work, and only
calls it once, so it handles at most one event.  More effective would be
flushing the event queue after each iteration of that loop, a la

     foreach (@IDs){
         push (@temp_pdfs, &make_pdf);
         Gtk2->main_iteration while Gtk2->events_pending;
     }


Even better would breaking up your make_pdf() routine to handle doing the job
in chunks so that you could have higher granularity.

Even better still would be forking a child to create the PDFs in the
background, uninterrupted and free of bizarre progress update code, and
monitor the life of that child by waiting for it to hang up on its stdout. 
This is "even better still" because it's nice and easy to cancel -- just kill
the child.

Your choice.



-- 
muppet <scott at asofyet dot org>




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