[gtkada] badly need help with Gtk.Tree_View

Preben Randhol randhol+gtkada at pvv.org
Sun Feb 27 13:08:03 CET 2005


John Stoneham <captnjameskirk at gmail.com> wrote on 22/02/2005 (16:44) :
> If I can just get this simple case to work, I can move on and actually
> do my project. Until then I'm stuck, and right now I AM STUCK! :) The

Hi. I have just used some hours on the tree_view myself. It is a bit
tricky to understand, but once you do all fall into place :-)

Have a look at this example that I found on the net. It works fine:

   Re: GtkAda and the Tree_Store Widget
   by max1@[EMAIL PROTECTED] Sep 8, 2003 at 08:56 AM

   Adam Puleo wrote:
   > I'm trying to use the Tree_Store widget in GtkAda 2.2.0 but nothing shows up

   Try this:

   with Glib;
   with Gtk.Box;
   with Gtk.Main;
   with Gtk.Enums;
   with Gtk.Widget;
   with Gtk.Window;
   with Gtk.Button;
   with Gtk.Tree_View;
   with Gtk.Tree_Store;
   with Gtk.Tree_Model;
   with Gtk.Tree_View_Column;
   with Gtk.Scrolled_Window;
   with Gtk.Cell_Renderer_Text;

   procedure Gtk_Test is

       use type Glib.Gint;

       Box    : Gtk.Box.Gtk_Box;
       Window : Gtk.Window.Gtk_Window;
       Scroll : Gtk.Scrolled_Window.Gtk_Scrolled_Window;
       Button : Gtk.Button.Gtk_Button;
       Store  : Gtk.Tree_Store.Gtk_Tree_Store;
       View   : Gtk.Tree_View.Gtk_Tree_View;
       Parent : Gtk.Tree_Model.Gtk_Tree_Iter := Gtk.Tree_Model.Null_Iter;
       Iter   : Gtk.Tree_Model.Gtk_Tree_Iter;
       Types  : Glib.GType_Array (0 .. 0);
       Column : Gtk.Tree_View_Column.Gtk_Tree_View_Column;
       Render : Gtk.Cell_Renderer_Text.Gtk_Cell_Renderer_Text;
       Ignore : Glib.Gint;
   begin
       Gtk.Main.Init;
       Gtk.Window.Gtk_New (Window);
       Gtk.Box.Gtk_New_Vbox (Box);
       Gtk.Button.Gtk_New (Button, "Hello World");
       Gtk.Box.Pack_Start (Box, Button, False, False);

       Gtk.Scrolled_Window.Gtk_New (Scroll);
       Gtk.Scrolled_Window.Set_Border_Width (Scroll, 5);
       Gtk.Scrolled_Window.Set_Policy
         (Scroll,
          Gtk.Enums.Policy_Automatic,
          Gtk.Enums.Policy_Automatic);
       Gtk.Box.Pack_Start (Box, Scroll);

       Types (0) := Glib.GType_String;
       Gtk.Tree_Store.Gtk_New (Store, Types);
       for I in 1 .. 1000 loop
          Iter := Gtk.Tree_Model.Null_Iter;
          Gtk.Tree_Store.Append (Store, Iter, Parent);
          Gtk.Tree_Store.Set (Store, Iter, 0,
             Gtk.Tree_Model.To_String (Gtk.Tree_Store.Get_Path (
               Store, Iter)));
       end loop;

       Gtk.Tree_View.Gtk_New (View, Store);
       Gtk.Cell_Renderer_Text.Gtk_New (Render);

       for I in 1 .. Glib.Gint'(18) loop
          Gtk.Tree_View_Column.Gtk_New (Column);
          Gtk.Tree_View_Column.Pack_Start (Column, Render, True);
          Gtk.Tree_View_Column.Add_Attribute (Column, Render, "text", 0);
          Ignore := Gtk.Tree_View.Append_Column (View, Column);
       end loop;

       Gtk.Scrolled_Window.Add (Scroll, View);

       Gtk.Window.Add (Window, Box);

       Gtk.Scrolled_Window.Show (Scroll);
       Gtk.Button.Show (Button);
       Gtk.Tree_View.Show (View);
       Gtk.Box.Show (Box);
       Gtk.Window.Show (Window);
       Gtk.Main.Main;
   end Gtk_Test;



More information about the gtkada mailing list