• GEntry with autocomplete

    From Gavin McCord@21:1/5 to All on Mon Mar 7 00:06:19 2022
    I'm looking at including a GEntry with autocomplete
    in some code of mine, and have created a simple example,
    test.adb, which I've constructed from tutorial examples
    (though from other languages, such as Python and PHP).



    with Gtk.Main;
    with Gtk.Window; use Gtk.Window;
    with Gtk.GEntry; use Gtk.Gentry;
    with Gtk.List_Store; use Gtk.List_Store;
    with Gtk.Tree_Model; use Gtk.Tree_Model;
    with Gtk.Entry_Completion; use Gtk.Entry_Completion;
    with Gtkada.Handlers; use Gtkada.Handlers;
    with Glib; use Glib;

    with test_cb; use test_cb;

    procedure Test is
    Win : Gtk_Window;
    Entry_1 : Gtk_GEntry;
    List_1 : Gtk_Tree_Model;
    Iter_1 : Gtk_Tree_Iter;
    Completion_1 : Gtk_Entry_Completion;
    type Word_Array is Array (1 .. 3) of String (1 .. 5);
    Words : Word_Array;
    begin
    Gtk.Main.Init;
    Gtk_New (Win);
    Win.Set_Title ("Window");
    Win.On_Delete_Event (main_del'Access);
    Win.On_Destroy (main_quit'Access);
    Win.Set_Border_Width (10);

    Words(1) := "Alpha";
    Words(2) := "Bravo";
    Words(3) := "Delta";

    Gtk_New (List_1, (0 => GType_String)); -- 0 - the first column
    for Count in 1 .. 3 loop
    List_1.Append (Iter_1);
    Set (List_1, Iter_1, 0, Words(Count));
    -- 0 The first column
    end loop;

    Gtk_New (Completion_1);
    Completion_1.Set_Model (List_1);
    Completion_1.Set_Text_Column(0);

    Gtk_New (Entry_1);
    Entry_1.Set_Completion(Completion_1);
    Win.Add (Entry_1);

    Win.Show_All;

    Gtk.Main.Main;
    end Test;




    Compilation fails at line 40 "Completion_1.Set_Model (List_1)"
    with the error

    test.adb:40:28: error: expected private type "Gtk_Tree_Model" defined at gtk-tree_model.ads:195
    test.adb:40:28: error: found type "Gtk_List_Store" defined at gtk-list_store.ads:139

    Presumably, I've missed something in translation.

    Thanks for any help.

    Gavin

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dmitry A. Kazakov@21:1/5 to Gavin McCord on Mon Mar 7 08:18:07 2022
    On 2022-03-07 01:06, Gavin McCord wrote:

    Compilation fails at line 40 "Completion_1.Set_Model (List_1)"
    with the error

    test.adb:40:28: error: expected private type "Gtk_Tree_Model" defined at gtk-tree_model.ads:195
    test.adb:40:28: error: found type "Gtk_List_Store" defined at gtk-list_store.ads:139

    Presumably, I've missed something in translation.

    See To_Interface function that does the conversion.

    [GTK interfaces are tagged Ada types. Since full MI is unfortunately not supported in Ada, explicit conversion are are needed]

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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Gavin McCord@21:1/5 to Dmitry A. Kazakov on Tue Mar 8 23:46:35 2022
    On Mon, 7 Mar 2022 08:18:07 +0100, Dmitry A. Kazakov wrote:

    On 2022-03-07 01:06, Gavin McCord wrote:

    Compilation fails at line 40 "Completion_1.Set_Model (List_1)"
    with the error

    test.adb:40:28: error: expected private type "Gtk_Tree_Model" defined
    at gtk-tree_model.ads:195 test.adb:40:28: error: found type
    "Gtk_List_Store" defined at gtk-list_store.ads:139

    Presumably, I've missed something in translation.

    See To_Interface function that does the conversion.

    [GTK interfaces are tagged Ada types. Since full MI is unfortunately not supported in Ada, explicit conversion are are needed]

    Yes, that did the trick. Thank you.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)