[Glade-users] glade_xml_signal_autoconnect, user data and libglade



Dear Glade users,

I'm putting together a gtk application. I'm using Glade for UI design
and am taking the advice to newbies to use libglade. I'm excited that
this enables me to make cosmetic changes to my UI without recompiling my
program. 

I'd like to ask some advice about glade_xml_signal_autoconnect() and the
passing of user data to callback functions.

I understand that you can't pass user data to your callback functions if
you use glade_xml_signal_autoconnect().

I learned this by reading a thread on the glade-devel list. The thread
starts with a posting by Todd Fisher:

http://www.mail-archive.com/glade-devel lists ximian com/msg00243.html

In which he posts a patch to add a function to libglade called
glade_xml_signal_autoconnect_with_data().

If there are any members of the glade-devel list reading, has his
function been added to libglade, or are there plans to add it?

I have a function I need to use, and one way I can see of achieving my
aim is to pass, as user data, a pointer to the GladeXML object which
defines all of my widgets.

The function will get called on a signal when the user presses a "Next"
button, and will look at the state of a radio button on the same window
as the "Next" button.

Here's a function which would do this:

void
on_next_button_clicked (GtkWidget * widget, gpointer data) 
{
  GladeXML * xml = data;
  GtkWidget * radio_button;
  
  radio_button = glade_xml_get_widget(xml, "radio_button1");

  if (gtk_toggle_button_get_active(radio_button)) {
    g_print ("The radio button is selected!\n");
  } else {
    g_print ("The radio button is NOT selected.\n");
  }
}

Is there a better way to refer to the radio button which would remove
the need to pass the GladeXML object in as user data? Perhaps I can use
the GtkWidget * widget argument somehow? This callback is created as a
signal from the "Next" button, so presumably the passed in widget
pointer points to the "Next" button widget?

If I do need to pass GladeXML * xml in as user data, should I manually
connect my signals, or use a glade_xml_signal_autoconnect_with_data()
function if it's now a part of libglade?

Do people here generally avoid the use of user_data in callbacks and
consequent manual connection of signals where possible, when building
apps that use libglade?

Thanks for reading,

Seb James
-- 
Business Systems, Hypercube Systems Ltd
Providing Free Software IT solutions.
Tel: 0845 458 0277 Web: www.hypercubesystems.co.uk
Mob: 07900 958964  Email: seb hypercubesystems co uk





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]