non-blocking loop delay



Hi,
I'm either missing something, or I'm searching for something which dosn't
exist.  Is there a way to slow down a loop, without blocking the gui?
I know the code below, could (and probably should) be rewritten using
Glib::Timeout->add ()  instead of a for loop, but what if I wanted or needed
the for loop. How to I install a non-blocking loop delay?

In Tk, there was a form of the "after" or "repeat" statement, where you
just use $widget->after(10);  to get a 10 millisecond delay.

Anything similar in Gtk2?

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

my $count = 0;

my $window = Gtk2::Window->new('toplevel');
$window->set_title('Z');
$window ->signal_connect( 'destroy' => \&delete_event );
$window->set_border_width(10);
$window->set_size_request(300,200);

my $vbox = Gtk2::VBox->new( FALSE, 6 );
$window->add($vbox);
$vbox->set_border_width(2);

my $hbox= Gtk2::HBox->new( FALSE, 6 );
$vbox->pack_end($hbox,FALSE,FALSE,0);
$hbox->set_border_width(2);

$vbox->pack_end (Gtk2::HSeparator->new, FALSE, FALSE, 0);

my $button = Gtk2::Button->new_from_stock('gtk-quit');
$hbox->pack_end( $button, FALSE, FALSE, 0 );
$button->signal_connect( clicked => \&delete_event );

my $button1 = Gtk2::Button->new('Start');
$hbox->pack_end( $button1, FALSE, FALSE, 0 );
$button1->signal_connect( clicked => \&start_count );


$window->show_all();
Gtk2->main;
#####################################
sub delete_event {
Gtk2->main_quit;
return FALSE;
}  
########################################
sub start_count{
   
  for(1..100){
      $count++;
      print "$count\n";
     
     #looking to slow this loop down
     #in a non-blocking manner
     #something like this ?
     
     Glib::Timeout->add (100, sub{ return FALSE } );
     #of course this dosn't work  and the loop just flies thru  

   }

}
#############################################







-- 
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html



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