comp.lang.ada
 help / color / mirror / Atom feed
From: "Bobby D. Bryant" <bdbryant@mail.utexas.edu>
Subject: Re: Timers and GTK
Date: 2000/01/11
Date: 2000-01-11T18:29:33+00:00	[thread overview]
Message-ID: <387B76A9.B73A35F1@mail.utexas.edu> (raw)
In-Reply-To: 387A4644.5992EF02@ensica.fr

GUILLOU Jacques wrote:

> Can anyone help me using GTK timer functions ? (callback function that
> is called every 100 ms for example) ?
> thanx

By chance I just worked that out a couple of days ago.  The following
example uses the GtkAda bindings; I'm picking out lines that are widely
separated among my files, so here's hoping I haven't forgotten anything.

-----
Instantiate the "Timeout" package:

   -- Package for handling timeout callbacks:
   package Timeout_Callback is
      new Gtk.Main.Timeout( Data_Type => Integer );

[Use whatever data type you happen to need in your callback function.]

-----
Declare a variable to recieve the timeout's identifier:

      Timeout_Handle : Glib.Guint;

and a variable to define the interval (or just use a constant):

   Migration_Interval    : Glib.Guint := 1000; -- ms.

-----
Declare a function to be invoked by the timer:

   function Migrate( Number_To_Move : in Integer )
      return Boolean;

   function Migrate( Number_To_Move : in Integer ) return Boolean is
...
   begin
...
      return True; -- "false" will disable further timeouts on this.
   end Migrate;

[Notice that the integer argument matches the data type in the package I
instantiated above.]

-----
Set up the callback:

      Timeout_Handle
        := Timeout_Callback.Add( Interval => Migration_Interval,
                                           Func     => Migrate'Access,
                                           D        => 1000 ); -- # to
move.

[ The "D" value is passed to Migrate whenever it is invoked.]

-----
Works like a charm.  Good luck!

Bobby Bryant
Austin, Texas





      reply	other threads:[~2000-01-11  0:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-01-10  0:00 Timers and GTK GUILLOU Jacques
2000-01-11  0:00 ` Bobby D. Bryant [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox