[gtkada] Signal handler

Dmitry A. Kazakov mailbox at dmitry-kazakov.de
Tue Jun 14 16:26:17 CEST 2011


On Tue, 14 Jun 2011 15:21:50 +0200, you wrote:

> 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

1. GType_Array is over GUInt (starts from 0).

2. Where is a call to Set_Text_Column? Or Get_Text_Column instead of a
hand-written constant in the handler.

3. Always catch all Ada exceptions in signal handlers, log the
Exception_Information using GLib.Messages.Log, and stop the exception
propagation to prevent crash.

4. It would be helpful in order to test it. if you sent a complete
compilable program sample.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



More information about the gtkada mailing list