Progress Bar question




   Hi,

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?

Thanks,

   Gergo


Code follows:

#!/usr/bin/perl -w
use Glib qw/TRUE FALSE/;
use Gtk2 '-init';

sub cb1 {
    foreach $k (1..20) {
        $fraction += 0.05;
        $fraction = 0 if $fraction > 1;
        print "+++ $k +++\n";
        system "sleep 1";
        $progress -> set_fraction ($fraction);
    }
}

sub cb2 {
    $fraction += 0.05;
    $fraction = 0 if $fraction > 1;
    $progress -> set_fraction ($fraction);
}

$window = Gtk2::Window->new('toplevel');
$window->signal_connect(delete_event => sub { Gtk2->main_quit; });
$window->set_border_width(10);

$vbox = Gtk2::VBox->new(0, 5);

$button = Gtk2::Button->new("Progress");

$button->signal_connect(clicked => \&cb1, $window);
##### Alternatively:
# $button->signal_connect(clicked => \&cb2, $window);

$vbox -> pack_start ($button, TRUE, TRUE, 0);

$progress = new Gtk2::ProgressBar;
$fraction = 0.0;
$progress -> set_fraction ($fraction);
$vbox -> pack_start ($progress, TRUE, TRUE, 0);

$window->add($vbox);
$window->show_all;
Gtk2->main;
0;




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