[gtkada] How to connect a button Handler to a task entry?
Dmitry A. Kazakov
mailbox at dmitry-kazakov.de
Thu May 13 08:59:30 CEST 2010
On Thu, 13 May 2010 01:48:02 +0100, you wrote:
> I am currently learning Gtkada and Ada in general at the moment. I am been
> trying to find an example on how to connect a button event to a task entry
> but have failed so far. Could anyone please show me a simple example of
> the handler syntax declaration and the .connect?
You should wrap the entry call into a procedure. E.g.:
task type Handler is
entry Click;
end Handler;
type Handler_Ptr is access all Handler;
package Entry_Handlers is
new Gtk.Handlers.User_Callback (Gtk_Widget_Record, Handler_Ptr);
procedure Clicked
(Widget : access Gtk_Widget_Record'Class; Ptr : Handler_Ptr) is
begin
Ptr.Click;
end Clicked;
...
Listener : aliased Handler;
...
Entry_Handlers.Connect
( Button,
"clicked",
Clicked'Access,
Listener'Access
);
However I would never do this. An entry call is blocking, if the task you
call is not ready for the rendezvous. That will freeze the GUI. Then you
cannot do [at least directly] any GTK calls from the task. So it is rather
useless.
If you want to communicate with a task from a GTK event, use a protected
object instead.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
More information about the gtkada
mailing list