[gtkada] Addressing external data in a GUI

Rick Duley 30294025 at student.murdoch.edu.au
Mon Jun 13 03:52:10 CEST 2005


Hi Stephen

I read your posting with delight.
I thought, "Here is the answer to the maiden's prayer!"
It wasn't :(
Maybe I'm no longer a maiden :)

Here is my code:

    procedure On_Analyse60_Source_Folder_Find_Button_Clicked
      (Object : access Gtk_Button_Record'Class)
    is
       Window : constant Gtk_Window :=
         Gtk_Window(Gtk.Button.Get_Toplevel(Widget => Object));
    begin
       Window.Arguments.Source_Folder :=
          To_Unbounded_String(Source => "This is a test");
    end On_Analyse60_Source_Folder_Find_Button_Clicked;

The template for the callback was written by Glade_2.

"Source_Folder" is an Unbounded String declared in a record to which an access
("Arguments") is included in the declaration of the Gtk_Window_Record thus:

    type Analyse60_Window_Record is new Gtk_Window_Record with record

       Arguments : Analyst.Arguments_Access_Type;
       -- Storage anchor for the user-defined arguments that control the
       -- run of the Engine task.

       Analyse60_Base_Box : Gtk_Vbox;
       . . .
       Analyse60_Source_Folder_Frame : Gtk_Frame;
       Analyse60_Source_Folder_Hbox : Gtk_Hbox;
       Analyse60_Source_Folder_Entry : Gtk_Entry;
       Analyse60_Source_Folder_Find_Button : Gtk_Button;
       Analyse60_Source_Folder_Label : Gtk_Label;
       . . .
    end record;

Any attempt to compile  using GPS 2.1.0 (20041129) hosted on 
pentium-mingw32msv
with GNAT GAP 1.1.0 (20041209-323) fails with:

analyse60_window_pkg-callbacks.adb:110:13: no selector "Arguments" for type
Gtk_Window_Record'Class" defined at gtk-window.ads:63

Okay - it's all my fault (it always seems to be) but:
Q.1. Where is the fault?
Q.2. How am I wrong?
Q.3. What should I have done?


BTW: Why did you declare "Window" a constant?

Thanks
-------------------------------------------
"Professional qualitative judgement
    consists in knowing the rules
      for using (or occasionally breaking)
        the rules."
                             D. Royce Sadler
-------------------------------------------
Rick Duley
Murdoch University
School of Engineering Science
Perth, Western Australia
http://eng.murdoch.edu.au/~rick
aussie : 040 910 6049                .-_|\
o'seas : + 61 40 910 6049           /     \
                               perth *_.-._/
                                          v


Quoting Stephen Leake <stephen_leake at acm.org>:

> Rick Duley <30294025 at student.murdoch.edu.au> writes:
>
>> I don't know how GPS is involved here.
>
> GPS is the Gnat (or Gnu?) Programming System; it is an example of a
> large GUI program. Apparently it does not use global variables, so it
> is an example of what you are trying to do.
>
> It would be instructive for you to try to read the sources for GPS;
> there are lots of nice GUI ideas in there. Be warned; it's HUGE.
>
>> What I have done is include the "necessary" access type in the
>> record that defines the Window. Oh, I am _sure_ it is not the
>> _right_ technique - it's terrible Ada! That's why I am trying to
>> find out what the _right_ technique _is_!
>
> I'd need to see the code to see what you are doing, and whether it is
> "terrible Ada".
>
> The "right technique" is to have the appropriate window type contain
> the data, and then convert the widget pointer you get in a callback to
> the "right" widget pointer, using some variant of Get_Parent. For
> example, here is a fragment from one of my callbacks for a button
> click:
>
>    procedure On_Next_Week_Clicked
>        (Button : access Gtk.Button.Gtk_Button_Record'Class)
>    is
>       Window : constant Gtk_Window :=
>          Gtk_Window (Gtk.Button.Get_Toplevel (Button));
>    begin
>       VCR.Model.Data.Next_Week (Window.Data.all);
>
> Here 'Gtk_Window' is the access type for my GUI main window; it
> contains my data, and it is the top level parent for the button, which
> is nested in boxes. VCR.Model.Data.Next_Week is a procedure that
> operates on that data.
>
> This involves a run-time check of the tag of Button; that's the price
> you pay for the flexibility of Gtk.
>
> Sometimes you need to use Get_Parent (possibly several times, possibly
> in a loop) instead of Get_Toplevel, if the data you are operating on
> is owned not by the top level window, but by some intermediate window.
>
> I have not read the Gtk user's guide recently, so I don't remember if
> this is in there.
>
> Hope this helps.
>
> --
> -- Stephe
>





More information about the gtkada mailing list