[gtkada] Signal handler

Op de Coul, Manuel Manuel.op.de.Coul at eon.com
Tue Jun 14 15:21:50 CEST 2011


Thanks to you both. I was able to connect the signal handler, but cannot get the 
iter from the Gvalues.
The comment

> In package Gtk.Entry_Completion:
>    --  - "match_selected"
>    --    procedure Handler
>    --       (Completion : access Gtk_Entry_Completion_Record'Class;
>    --        Model      : Gtk_Tree_Model;
>    --        Iter       : Gtk_Tree_Iter);
>    --    Gets emitted when a match from the list is selected. The default
>    --    behaviour is to replace the contents of the entry with the contents of
>    --    the text column in the row pointed to by Iter.
>    --    Return value: %TRUE if the signal has been handled

is not correct, it should be a function returning Boolean.
That means also that Gtk.Handlers.Callback does not need to be instantiated, 
but GtkAda.Handlers can be used.
So the handler is (note the different Object type):

   function Fill_Entry (Object : access Glib.Object.GObject_Record'Class;
                        Params : in GValues)
     return Boolean is
      Model : Gtk_Tree_Model;
      Iter  : Gtk_Tree_Iter;
   begin
      Model := Get_Model(Gtk_Entry_Completion(Object));
      Get_Tree_Iter (Nth (Params, 1), Iter);
      Set_Text (Gtk_Entry(Get_Entry(Gtk_Entry_Completion(Object))), Get_String(Model, Iter, 1));
      --Set_Text (Gtk_Entry(Get_Entry(Gtk_Entry_Completion(Object))), "hello");
      return True;
   end Fill_Entry;

And

   Gtk_New (List, GType_Array'(1 => GType_String, 2 => GType_String));
   Gtk_New (Compl);
   Set_Model (Compl, Gtk_Tree_Model(List));
   Object_Return_Callback.Connect (Compl, "match_selected", Fill_Entry'Access);

Now setting "hello" to the entry works, but getting the string from the list model gives:

(scala.exe:5260): Gtk-CRITICAL **: gtk_list_store_get_value: assertion `VALID_ITER (iter, list_store)' failed

(scala.exe:5260): GLib-GObject-WARNING **: gtype.c:3940: type id `0' is invalid

(scala.exe:5260): GLib-GObject-WARNING **: can't peek value table for type `<invalid>' which is not currently referenced

raised PROGRAM_ERROR : EXCEPTION_ACCESS_VIOLATION

Any further help very much appreciated.

Manuel


>You instantiate Gtk.Handlers.User_Callback or Gtk.Handlers.Callback as
>usual. Then you declare handler as follows:

>procedure Entry_Completion_Handler
>          (  Object  : access Gtk_Entry_Completion_Record'Class;
>             Params  : GValues
>          );         
         
>Within the handler you access parameters as follows:

>procedure Entry_Completion_Handler
>          (  Object  : access Gtk_Entry_Completion_Record'Class;
>             Params  : GValues
>          )  is
>   Iter : Gtk_Tree_Iter;
>begin
>   Get_Tree_Iter (Nth (Params, 1), Iter);

>See Gtk.Tree_Model.Get_Tree_Iter. Getting the model is a bit more
>complicated, but models are normally accessible implicitly through other
>ways. If you still want to get it from GValue use GLib.Values.Get_Object on
>Nth (Params, 0).





More information about the gtkada mailing list