[Glade-users] glade_xml_signal_autoconnect and manual connection of signals
- From: giulio at hewle.com (Giulio Bai)
- Subject: [Glade-users] glade_xml_signal_autoconnect and manual connection of signals
- Date: Fri, 16 Nov 2007 18:51:34 +0100
I recently landed to the beautiful world of gtk programming and using
Glade as interface designer I learned quite a lot stuffs.
I always connected signals from my application manually, for example
the event of a button that's been pressed:
/* A bunch of data to be set and used in the callbacks */
typedef struct _AppData AppData;
struct _AppData
{
GtkAboutDialog *dialog_about;
GtkLabel *hello_label;
};
void
about_button_clicked_show_about_dialog (gpointer data)
{
AppData *widgets = (AppData *)data;
gtk_dialog_run ((GtkDialog *)widgets->dialog_about);
gtk_label_set_label ((Gtklabel *)widgets->hello_label, "Wow, it
works!"); }
void
destroy_it_all ()
{
printf ("Destroying...\n");
}
void
hook_up_callbacks (GladeXML *the_widgets)
{
GtkWidget *widget;
AppData *my_widgets = (AppData *)malloc (sizeof (AppData));
/*** Loading stuffs into data structure ***/
my_widgets->dialog_about = (GtkAboutDialog
*)glade_xml_get_widget (the_widgets, "dialog_about");
/*** Hooking generic signals ***/
widget = glade_xml_get_widget (the_widgets, "window_main");
/* delete event */
g_signal_connect (G_OBJECT (widget), "delete_event", G_CALLBACK
(gtk_main_quit), NULL); /* Have the destroy signal quits */
g_signal_connect (G_OBJECT (widget), "destroy",
G_CALLBACK
(destroy_it_all), NULL);
/*** Button pressed ***/
widget = glade_xml_get_widget (the_widgets,
"about_button"); g_signal_connect_swapped (G_OBJECT (widget),
"pressed", G_CALLBACK
(about_button_clicked_show_about_dialog), (gpointer)my_widgets);
}
int
main (int argc, char *argv[])
{
GladeXML *gxml;
gtk_init (&argc, &argv);
gxml = glade_xml_new (GLADE_FILE, NULL, NULL);
/* Connect all the signals to the appropriate callbacks */
hook_up_callbacks (gxml);
/* start the event loop */
gtk_main ();
/* Free the memory used by the widgets we're no longer using */
gtk_widget_destroy (glade_xml_get_widget (gxml, "window_main"));
return 0;
}
Well, I tried to make it using the function
glade_xml_signal_autoconnect but I can't figure out how to operate on
other widgets.
Is there any way to access all widgets (such as hello_label) properties
inside object's callback functions?
Can anyone post the same example using the automatic signal connection?
I imagine I didn't catch the most important thing...
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]