[gtkada] Addressing external data in a GUI

Rick Duley 30294025 at student.murdoch.edu.au
Tue Jun 14 03:28:15 CEST 2005


Hi Stephe

  You wrote:
>
> which Gtk_Window is visible here? It must be yours.
>
and, further
>
> You are converting to type Gtk.Window.Gtk_Window, instead of to your
> window type.
>

I get the idea, but I am not sure how to address 'my' window.  I'll have a bit
of a hack and get back to you if I can't figure it out.

You wrote:
>
> Part of the fault here lies with Glade; it put in a 'use' clause for
> Gtk.Window. Lesson learned; delete _all_ of the "use" clauses that
> Glade adds for you; they just confuse things. Add them back only in
> the procedures that need them, and/or get used to using full names
>

That makes sense.  I'm doing that when I add dialog etc. packages to the main
window package.

However, there was another posting at the same time which poses a similar
question, to whit: "How do you get the Toplevel Window for Gtk_Entry?"

Perhaps you'll be good enough to have a shot at this one.  Here's a re-write:
--==========
I have a Gtk_Entry within a Box, within a Frame, within a Box, within a 
Toplevel
Window thus:

+---------- Window ------------+
| +--------- VBox -----------+ |
| | +---- Frame&Label -----+ | |
| | | +----- HBox -------+ | | |
| | | | +--------------+ | | | |
| | | | |    Entry     | | | | |
| | | | +--------------+ | | | |
| | | +------------------+ | | |
| | +----------------------+ | |
| +--------------------------+ |
+------------------------------+

Here is a code segment:

    procedure On_Analyse60_Source_Folder_Entry_Changed
      (Object : access Gtk_Entry_Record'Class)
    is
       Main_Window : Gtk_Window := Get_Parent_Window(Widget => Object);
    begin
       . . .

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

analyse60_window_pkg-callbacks.adb:69:29: expected type "Gtk_Window" 
defined at
gtk-window.ads:64
analyse60_window_pkg-callbacks.adb:69:29: found type "Gdk_Drawable" defined at
gdk.ads:46


*Q.1. Why would Get_Parent_Window return a Gdk_Drawable in this case?*


The only thing I can get to work is:

    procedure On_Analyse60_Source_Folder_Entry_Changed
      (Object : access Gtk_Entry_Record'Class)
    is
       Main_Window : constant Gtk_Widget := Get_Toplevel(Widget => Object);
    begin
       -- debug
       Put_Line("Widget is "
                & Get_Name(Widget => Main_Window));
       Put_Line("Entry contains "
                & Get_Text(The_Entry => Object));
       -- debug
    end On_Analyse60_Source_Folder_Entry_Changed;

This prints the name I set in the Gtk_Window_Record and the text I type 
into the
entry.  My problem is that, when the content of the Entry is changed, I 
wish to
save the text in the Entry into an Unbounded String identified as
"Source_Folder" contained in a record called "Arguments" to which I have an
access in the Gtk_Window_Record (now represented by Main_Window).  This access
is allocated memory in the Initialize procedure.

Given the code:

    procedure On_Analyse60_Source_Folder_Entry_Changed
      (Object : access Gtk_Entry_Record'Class)
    is
       Main_Window : constant Gtk_Widget := Get_Toplevel(Widget => Object);
    begin
       Main_Window.Arguments.Source_Folder :=
         To_Unbounded_String(Get_Text(The_Entry => Object));

       -- debug
       Put_Line(To_String(Main_Window.Arguments.Source_Folder));
       -- debug
    end On_Analyse60_Source_Folder_Entry_Changed;

I get the error messages:

analyse60_window_pkg-callbacks.adb:79:18: no selector "Arguments" for type
"Gtk_Widget_Record'Class" defined at gtk-widget.ads:74
analyse60_window_pkg-callbacks.adb:83:37: no selector "Arguments" for type
"Gtk_Widget_Record'Class" defined at gtk-widget.ads:74

That's fair enough.  Main_Window _is_ declared as a Gtk_Widget.  It has 
to be -
Get_Toplevel returns a Gtk_Widget - but this particular Widget is a 
Gtk_Window.
  Not only that, it's a Window I know as a named Gtk_Window_Record which has
something named "Arguments" in it!  Here it is:

    type Analyse60_Window_Record is new Gtk_Window_Record with record

       Arguments : Analyst.Arguments_Access_Type;
       -- Storage access for the user-defined arguments.

       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_Label : Gtk_Label;
       . . .
    end record;

According to my way of thinking the procedure
On_Analyse60_Source_Folder_Entry_Changed above should, when the content of
Object is changed, store the text in Object in the Unbounded String in the
record within the window_record.  Then the debug line should read that
Unbounded String and print it.  But it don't!


*Q.2.  What have I done wrong?*
--==========

This whole process of getting data into and out of a GUI is shrouded in 
secrecy.
  I have found no documentation which deals with it.  I find it extremely
difficult to get straight answers about it.  Yet, it must be the central focus
of the exercise.  After all, the most attractive GUI in the world is only
ornamental unless it serves as an HCI.  The application must be able to
communicate (or it doesn't need an interface).

For the record, I am now reasonably happy with the interface I have 
been able to
create.  I just cannot get it to do anything useful.

Hoping you can help
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:
>
>>     procedure On_Analyse60_Source_Folder_Find_Button_Clicked
>>       (Object : access Gtk_Button_Record'Class)
>>     is
>>        Window : constant Gtk_Window :=
>
> which Gtk_Window is visible here? It must be yours.
>
>>          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.
>
> I don't use Glade_2, but that shouldn't matter.
>
>> 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?
>
> You are converting to type Gtk.Window.Gtk_Window, instead of to your
> window type.
>
> Part of the fault here lies with Glade; it put in a 'use' clause for
> Gtk.Window. Lesson learned; delete _all_ of the "use" clauses that
> Glade adds for you; they just confuse things. Add them back only in
> the procedures that need them, and/or get used to using full names, at
> least until you understand what's going on better. That's one of the
> reasons I don't use Glade. And I still use full names most of the
> time, for GtkAda code.
>
> --
> -- Stephe
>
> _______________________________________________
> gtkada mailing list
> gtkada at lists.adacore.com
> http://lists.adacore.com/mailman/listinfo/gtkada
>





More information about the gtkada mailing list