Re: Timers




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




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