Timers

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Timers

Juan José 'Peco' San Martín
Hello all.

I'm using the timers:

my $pointer->{timer}=Glib::Timeout->add(1000,\&progress_timeout,$label);

All seems to be ok. Each time the "progress_timeout" function is called,
I'm able to change the value of $label with $pointer->set_text("123");

My issue is that I would like to attach the same timer but to other
widgets, in order to update many of them at the same time. Surely that
it's possible but I didn't find the way :-/

Thanks for any help.

Peco



_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: Timers

muppet-6

On Jun 30, 2005, at 12:37 PM, Juan José 'Peco' San Martín wrote:

> Hello all.
>
> I'm using the timers:
>
> my $pointer->{timer}=Glib::Timeout->add(1000,\&progress_timeout,
> $label);
>
> All seems to be ok. Each time the "progress_timeout" function is  
> called,
> I'm able to change the value of $label with $pointer->set_text("123");
>
> My issue is that I would like to attach the same timer but to other
> widgets, in order to update many of them at the same time. Surely that
> it's possible but I didn't find the way :-/

The possibilities are endless.  Here are two off the top of my head.

- create a new timer for each widget you want to update.  you have  
the capacity for full customization of each handler for each widget,  
but the timeouts will fire at different times.  this is nicely  
independent -- no widget has to know about the other widgets.

- use a separate "heartbeat" object, and make its timeout handler  
iterate over a list of widgets.  this setup with update all connected  
objects at (pretty much) the same time.  if you set things up  
correctly, you can still have good isolation and extensibility, e.g.  
by "registering" update callbacks with your heartbeat handler.

    my $heartbeat = Heartbeat->new ($interval_milliseconds);
    $heartbeat->add ( \&update_label1, $label1);
    $heartbeat->add (\&update_label2, $label2);
    $heartbeat->remove (\&update_label1, $label1);
    $heartbeat->stop;  # stop firing the heartbeat
    $heartbeat->start;

etc, etc

--
Without treatment, a common cold will last about seven days.
With treatment, it will last about a week.
   -- conventional wisdom

_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: Timers

Aristotle Pagaltzis
In reply to this post by Juan José 'Peco' San Martín
* Juan José 'Peco' San Martín <[hidden email]> [2005-07-01 01:35]:
> My issue is that I would like to attach the same timer but to
> other widgets, in order to update many of them at the same
> time. Surely that it's possible but I didn't find the way :-/

That’s nothing to do with Gtk2. You just need to know Perl.
muppet’s suggestion of a Heartbeat object is nice, particularly
if you need to do this kind of thing more than in one place. For
a simple one-off where extensibility is not a concern, you can
just use a closure:

    my $timer = Glib::Timeout->add( 1000, sub {
        progress_timeout( $label );
        do_something_else( $progbar );
        spin( $my_beanie );
        etc( etc( etc() ) );
    } );

Regards,
--
#Aristotle
*AUTOLOAD=*_=sub{s/(.*)::(.*)/print$2,(",$\/"," ")[defined wantarray]/e;$1};
&Just->another->Perl->hacker;
_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Reply | Threaded
Open this post in threaded view
|

Re: Timers

Juan José 'Peco' San Martín
Right.

Thanks!
Peco

PS: I was thinking on a TimeOut trick to resolve it.


On Fri, 2005-07-01 at 10:13 +0200, A. Pagaltzis wrote:

> * Juan José 'Peco' San Martín <[hidden email]> [2005-07-01 01:35]:
> > My issue is that I would like to attach the same timer but to
> > other widgets, in order to update many of them at the same
> > time. Surely that it's possible but I didn't find the way :-/
>
> That’s nothing to do with Gtk2. You just need to know Perl.
> muppet’s suggestion of a Heartbeat object is nice, particularly
> if you need to do this kind of thing more than in one place. For
> a simple one-off where extensibility is not a concern, you can
> just use a closure:
>
>     my $timer = Glib::Timeout->add( 1000, sub {
>         progress_timeout( $label );
>         do_something_else( $progbar );
>         spin( $my_beanie );
>         etc( etc( etc() ) );
>     } );
>
> Regards,

_______________________________________________
gtk-perl-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list