Re: The Main Loop and My Own Actions



/---  On Mon,  Apr 09,  2001  at 04:45:28PM  +0200, Stefan  Kamphausen
wrote:
| I've been  searching the  archive for  an answer  to this  but found
| only
| half the truth.
|
| The problem  is that  I want  to call some  actions during  the main
| event
| loop such  as updating a time-showing  label and watching a  file if
| it
| has been changed since my last visit.
|
|   $time_label->set($time);
|   # Guess what...
|   check_log_file_and_update();
|   #  FIXME: how  to  watch files  and  update  time without  causing
|   100%CPU??
|   sleep(1);
| }
|
| Obviously it  has to be  a major issue so  I think I'm  just missing
| some
| point. In  that case  please forgive my  humble question  and please
| point
| me to the appropriate documentation.
|
\---

Think differently.  Read the new  Gtk::cookbook which can be  found in
the latest  gnome-perl distribution. You can  define timeout functions
and idle functions in  the Gtk event loop, and you  don't need to have
your own event loop:

my $id;

my $timesub=sub {
  .... $time_label->set ...
  $id=Gtk->timeout_add(1000, sub { $time_label->set .... });
  return 0;
};
&$timesub;
...
Gtk->timeout_remove ( $id );

The same with idle_add and idle_remove.

dLux
--
:wq




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