[Glade-users] libglade, GtkDrawingArea, GdkEvents ?

oogothoo pop.mail.yahoo.fr@listsmx.ximian.com
Wed, 13 Aug 2003 00:48:30 +0200


Thanks for your help !
I modify my code, with the same file glade :

#include <gtk/gtk.h>
#include <glade/glade.h>

gboolean
motion_notify_event(GtkWidget *widget,
				   GdkEventMotion *event)
{
	g_print("%f %f.\n", event->x, event->y);
	return TRUE;
}



gboolean
button_release_event(GtkWidget *widget,
				    GdkEventButton *event)
{
	g_print("bouton =3D %d.\n", event->button);
	return TRUE;
}


int
main(int argc, char **argv)
{
	GladeXML *xml;

	gtk_init(&argc, &argv);
	glade_init();
=09
	xml =3D glade_xml_new("test.glade", NULL, NULL);

	if(!xml)
	{
		g_warning("error loading gtk.glade");
		return 1;
	} else {
		gtk_widget_add_events(glade_xml_get_widget(xml, "drawingarea"),
				      GDK_BUTTON_RELEASE_MASK
				      | GDK_POINTER_MOTION_MASK);

		glade_xml_signal_connect(xml,
					 "on_drawingarea_motion_notify_event",
					 G_CALLBACK(motion_notify_event));

		glade_xml_signal_connect(xml,
					 "on_drawingarea_button_release_event",
					 G_CALLBACK(button_release_event));
	=09
		glade_xml_signal_connect(xml,
					 "on_window_destroy",
					 G_CALLBACK(gtk_main_quit));

		gtk_main();
		return 0;
	}
}


But only the 'motion_notify_event' work.=20
'button_release_event' doesn't work but no error in log...

If i delete the call to gtk_widget_add_events, event on drawingarea events=
=20
doesn't work.

What is the problem ?





Le Mardi 12 Ao=FBt 2003 18:13, e98cuenc@free.fr a =E9crit :
> In addition of adding the callback in glade, you should also connect to t=
he
> callback on your code using glade_xml_signal_connect, or connect at the
> same time all the callbacks using glade_xml_signal_autoconnect (if you wa=
nt
> to use autoconnect, you should export the symbols of your executable.=20
> Using the - export-dynamic option of libtool should do the trick in a
> portable way).
>
> Cheers,
>
> Selon goth goth <oogothoo@yahoo.fr>:
> > Hello,
> >
> > I realise a simple application using libglade 2, Gtk
> > 2.2 : a GtkDrawingArea in a GtkWindow.
> >
> > window : signal destroy connect to gtk_main_quit
> > drawingarea : signals button_release_event and
> > motion_notify_event on two function who g_print event.
> >
> > drawingarea use the string "00000000001000000100" to
> > the GdkEvent (activate GDK_MOTION_NOTIFY_MASK and
> > GDK_BUTTON_RELEASE_MASK).
> >
> > Events are not send : no error message but no action
> > What is the problem ?
> >
> > This is the code :
> >
> > ----------------------------------
> >
> > #include <gtk/gtk.h>
> > #include <glade/glade.h>
> >
> > gboolean
> > on_drawingarea_motion_notify_event(GtkWidget *widget,
> > 				   GdkEventMotion *event)
> > {
> > 	g_print("%f %f.\n", event->x, event->y);
> > 	return TRUE;
> > }
> >
> >
> >
> > gboolean
> > on_drawingarea_button_release_event(GtkWidget *widget,
> > 				    GdkEventButton *event)
> > {
> > 	g_print("bouton =3D %d.\n", event->button);
> > 	return TRUE;
> > }
> >
> >
> > int
> > main(int argc, char **argv)
> > {
> > 	GladeXML *xml;
> >
> > 	gtk_init(&argc, &argv);
> > 	glade_init();
> >
> > 	xml =3D glade_xml_new("test.glade", NULL, NULL);
> >
> > 	if(!xml)
> > 	{
> > 		g_warning("error loading gtk.glade");
> > 		return 1;
> > 	} else {
> > 		glade_xml_signal_autoconnect(xml);
> > 		gtk_main();
> > 		return 0;
> > 	}
> > }
> >
> > -------------------------------
> >
> > This is the test.glade :
> >
> > <?xml version=3D"1.0" standalone=3D"no"?> <!--*- mode: xml
> > -*-->
> > <!DOCTYPE glade-interface SYSTEM
> > "http://glade.gnome.org/glade-2.0.dtd">
> >
> > <glade-interface>
> >
> > <widget class=3D"GtkWindow" id=3D"window">
> >   <property name=3D"visible">True</property>
> >   <property name=3D"title"
> > translatable=3D"yes">window</property>
> >   <property name=3D"type">GTK_WINDOW_TOPLEVEL</property>
> >   <property
> > name=3D"window_position">GTK_WIN_POS_NONE</property>
> >   <property name=3D"modal">False</property>
> >   <property name=3D"resizable">True</property>
> >   <property
> > name=3D"destroy_with_parent">False</property>
> >   <signal name=3D"destroy" handler=3D"gtk_main_quit"
> > last_modification_time=3D"Mon, 11 Aug 2003 22:50:33
> > GMT"/>
> >
> >   <child>
> >     <widget class=3D"GtkDrawingArea" id=3D"drawingarea">
> >       <property name=3D"visible">True</property>
> >       <property name=3D"can_default">True</property>
> >       <property name=3D"can_focus">True</property>
> >       <property name=3D"events">GDK_POINTER_MOTION_MASK
> >
> > | GDK_BUTTON_RELEASE_MASK</property>
> >
> >       <property
> > name=3D"extension_events">GDK_EXTENSION_EVENTS_CURSOR</property>
> >       <signal name=3D"motion_notify_event"
> > handler=3D"on_drawingarea_motion_notify_event"
> > last_modification_time=3D"Mon, 11 Aug 2003 22:57:56
> > GMT"/>
> >       <signal name=3D"button_release_event"
> > handler=3D"on_drawingarea_button_release_event"
> > last_modification_time=3D"Mon, 11 Aug 2003 22:58:03
> > GMT"/>
> >     </widget>
> >   </child>
> > </widget>
> >
> > </glade-interface>
> >
> >
> >
> >
> >
> > ___________________________________________________________
> > Do You Yahoo!? -- Une adresse @yahoo.fr gratuite et en fran=E7ais !
> > Yahoo! Mail : http://fr.mail.yahoo.com
> > _______________________________________________
> > Glade-users maillist  -  Glade-users@lists.ximian.com
> > http://lists.ximian.com/mailman/listinfo/glade-users