comp.lang.ada
 help / color / mirror / Atom feed
* Getting started with GtkAda & Glade
@ 2001-08-31 12:37 Karl Ran
  2001-09-03  7:48 ` Emmanuel Briot
  0 siblings, 1 reply; 4+ messages in thread
From: Karl Ran @ 2001-08-31 12:37 UTC (permalink / raw)


Hi there,

I'm trying to created a GUI with GtkAda and Glade(the RAD tool).
It's just one window with one horizontal scale widget (Class
GtkHScale);
Glade create this file (window1_pkg-callbacks.adb) for me:

-----------------------------------------------------------------
with System; use System;
with Glib; use Glib;
with Gdk.Event; use Gdk.Event;
with Gdk.Types; use Gdk.Types;
with Gtk.Accel_Group; use Gtk.Accel_Group;
with Gtk.Object; use Gtk.Object;
with Gtk.Enums; use Gtk.Enums;
with Gtk.Style; use Gtk.Style;
with Gtk.Widget; use Gtk.Widget;
with Ada.Text_IO;

package body Window1_Pkg.Callbacks is

   use Gtk.Arguments;

   ------------------------------------
   -- On_Hscale1_Motion_Notify_Event --
   ------------------------------------

   function On_Hscale1_Motion_Notify_Event
     (Object : access Gtk_Widget_Record'Class;
      Params : Gtk.Arguments.Gtk_Args) return Boolean
   is
      Arg1 : Gdk_Event := To_Event (Params, 1);
   begin
Ada.Text_IO.Put_Line("Well, the user moved the slider but I don't know
the position :(");
      return False; 
   end On_Hscale1_Motion_Notify_Event;

end Window1_Pkg.Callbacks;

-----------------------------------------------------------------

What I like to accomplish is to print the current value(position) of
the slider
while the user is moving it.

Anyone know what have to be placed inside the Put_Line-brackets?

Karl

PS: This is the XML Glade source...

<?xml version="1.0"?> 
<GTK-Interface>

<project>
  <name>Menu2</name>
  <program_name>menu2</program_name>
  <directory></directory>   
  <source_directory>src</source_directory>
  <pixmaps_directory>pixmaps</pixmaps_directory>
  <language>Ada 95</language>
  <gnome_support>False</gnome_support>
  <gettext_support>True</gettext_support>
</project>

<widget>
  <class>GtkWindow</class>
  <name>window1</name>
  <title>window1</title>
  <type>GTK_WINDOW_TOPLEVEL</type>
  <position>GTK_WIN_POS_NONE</position>
  <modal>False</modal>
  <allow_shrink>False</allow_shrink>
  <allow_grow>True</allow_grow>
  <auto_shrink>False</auto_shrink>

  <widget>
    <class>GtkHScale</class>
    <name>hscale1</name>
    <can_focus>True</can_focus>
    <signal>
      <name>motion_notify_event</name>
      <handler>on_hscale1_motion_notify_event</handler>
      <last_modification_time>Fri, 31 Aug 2001 12:16:08
GMT</last_modification_time>
    </signal>
    <draw_value>True</draw_value>
    <value_pos>GTK_POS_TOP</value_pos>
    <digits>1</digits>
    <policy>GTK_UPDATE_CONTINUOUS</policy>
    <value>0</value>
    <lower>1</lower>
    <upper>42</upper>
    <step>1</step>
    <page>0</page>
    <page_size>0</page_size>
  </widget>
</widget>

</GTK-Interface>



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Getting started with GtkAda & Glade
  2001-08-31 12:37 Getting started with GtkAda & Glade Karl Ran
@ 2001-09-03  7:48 ` Emmanuel Briot
  2001-09-03 18:47   ` Karl Ran
  0 siblings, 1 reply; 4+ messages in thread
From: Emmanuel Briot @ 2001-09-03  7:48 UTC (permalink / raw)


karlran1234@yahoo.com (Karl Ran) writes:

> Hi there,
> 
> I'm trying to created a GUI with GtkAda and Glade(the RAD tool).
> It's just one window with one horizontal scale widget (Class
> GtkHScale);
> Glade create this file (window1_pkg-callbacks.adb) for me:

[...]

> -----------------------------------------------------------------
> 
> What I like to accomplish is to print the current value(position) of
> the slider
> while the user is moving it.


Yes, try something like:

   declare
      Scale : Gtk_Scale := Gtk_Scale (Object);
   begin
      Put_Line ("Current_Value is "
                & Gdouble'Image (Get_Value (Scale)));
   end;

Emmanuel





^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Getting started with GtkAda & Glade
  2001-09-03  7:48 ` Emmanuel Briot
@ 2001-09-03 18:47   ` Karl Ran
  2001-09-05  8:43     ` Emmanuel Briot
  0 siblings, 1 reply; 4+ messages in thread
From: Karl Ran @ 2001-09-03 18:47 UTC (permalink / raw)


Hi Emmanuel,

>Yes, try something like:    declare
>      Scale : Gtk_Scale := Gtk_Scale (Object);
>   begin
>      Put_Line ("Current_Value is "
>                & Gdouble'Image (Get_Value (Scale)));
>   end;
   
I played a little bit with your suggestions but I haven't found a
solution for
for my problem ... due to my lack of Ada/Gtk knowledge., I guess

Ok, now the code looks like this:

-----------------------------------------------------------------------
   function On_Hscale1_Motion_Notify_Event
     (Object : access Gtk_Widget_Record'Class;
      Params : Gtk.Arguments.Gtk_Args) return Boolean
   is
      Arg1  : Gdk_Event := To_Event (Params, 1);
      Scale : Gtk_Scale := Gtk_Scale (Object);  
   begin
     Put_Line ("Current_Value is " & Gdouble'Image (Get_Value
(Scale)));
     return False;
   end On_Hscale1_Motion_Notify_Event;
------------------------------------------------------------------------
Now I get this message:

gcc -c -gnatf -I/usr/local/include/gtkada window1_pkg-callbacks.adb
window1_pkg-callbacks.adb:27:64: expected type access to
"Gtk_Adjustment_Record" defined at gtk-adjustment.ads:97
window1_pkg-callbacks.adb:27:64: found type "Gtk_Scale" defined at
gtk-scale.ads:40
window1_pkg-callbacks.adb:27:64:   ==> in call to "Get_Value" at
gtk-adjustment.ads:97
gnatmake: "window1_pkg-callbacks.adb" compilation error

Any help would be appreciated..

Karl



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Getting started with GtkAda & Glade
  2001-09-03 18:47   ` Karl Ran
@ 2001-09-05  8:43     ` Emmanuel Briot
  0 siblings, 0 replies; 4+ messages in thread
From: Emmanuel Briot @ 2001-09-05  8:43 UTC (permalink / raw)


karlran1234@yahoo.com (Karl Ran) writes:
> I played a little bit with your suggestions but I haven't found a
> solution for
> for my problem ... due to my lack of Ada/Gtk knowledge., I guess
> 
> Ok, now the code looks like this:
> 
> -----------------------------------------------------------------------
>    function On_Hscale1_Motion_Notify_Event
>      (Object : access Gtk_Widget_Record'Class;
>       Params : Gtk.Arguments.Gtk_Args) return Boolean
>    is
>       Arg1  : Gdk_Event := To_Event (Params, 1);
>       Scale : Gtk_Scale := Gtk_Scale (Object);  
>    begin
>      Put_Line ("Current_Value is " & Gdouble'Image (Get_Value
> (Scale)));
>      return False;
>    end On_Hscale1_Motion_Notify_Event;
> ------------------------------------------------------------------------


Sorry,
I now realize I had looked at the development version of gtk+/GtkAda.
Instead, you would do something like:

  Put_Line (Gdouble'Image (Get_Value (Get_Adjustment (Scale))));

It does seem complex, however this is because the set of possible values for a
lot of widgets in gtk+ are separated from the value they contain. Instead, that
value is stored in a structure called a Gtk_Adjustment (that contains the
current value, the minimum and maximum possible values and a few other
fields). The nice thing is that other widgets can ask to receive signals when
the value is changed (Pretty close to the standard Model-View-Controller model,
I believe).

The new version of gtk+/GtkAda has more direct access functions, even though
they do the same thing as above in the background.

Emmanuel




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2001-09-05  8:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-31 12:37 Getting started with GtkAda & Glade Karl Ran
2001-09-03  7:48 ` Emmanuel Briot
2001-09-03 18:47   ` Karl Ran
2001-09-05  8:43     ` Emmanuel Briot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox