execution of timers from other callbacks
- From: zentara <zentara1 sbcglobal net>
- To: gtk-perl-list gnome org
- Subject: execution of timers from other callbacks
- Date: Wed, 17 Dec 2008 12:00:08 -0500
Hi,
I saw something on the gtk2-c list that got me thinking. :-)
In the following code, a timer is placed in a button callback,
but without a "non-blocking-delay" or a forced-loop-update
in the for loop, the timer dosn't run until the button callback
returns......even with very large numbers in the for loop.
So is this a rule? That timeouts and idle_adds won't be scheduled
until the callback they are in finishes, or you force the
eventloop to check itself?
Where is this documented? Or is it suposed to be obvious? :-)
#! /usr/bin/perl -w
use strict;
use Gtk2 -init;
my $window = Gtk2::Window->new ('toplevel');
$window->signal_connect (delete_event => sub { Gtk2->main_quit });
my $button = Gtk2::Button->new ('Action');
$button->signal_connect (clicked => \&clicked );
$window->add ($button);
$window->show_all;
Gtk2->main;
################################################################
sub clicked {
my $timer = Glib::Timeout->add (0, sub {
print "\n\ntimer callback\n\n";
return 0;
});
# with the non-blocking delay the timer get scheduled
# before the for loop runs
# non_blocking_delay(3000);
for(1..10){
for(1..10){
print "$_ ";
}
print "\n";
# the forced loop update works too
# Gtk2->main_iteration while Gtk2->events_pending;
}
print"\n\n";
return 0;
}
sub non_blocking_delay {
my $milliseconds = shift;
my $mainloop = Glib::MainLoop->new;
Glib::Timeout->add ($milliseconds, sub { $mainloop->quit;
return 0; });
$mainloop->run;
}
__END__
Thanks,
zentara
--
I'm not really a human, but I play one on earth.
http://zentara.net/Remember_How_Lucky_You_Are.html
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]