Re: LibGlade query: trouble with lookup_widget.
- From: Bibek Sahu <scorpio dodds net>
- To: Archit Baweja <bighead crosswinds net>
- Cc: gnome-devel-list gnome org
- Subject: Re: LibGlade query: trouble with lookup_widget.
- Date: Tue, 10 Apr 2001 08:38:24 -0500 (CDT)
Howdy,
On Sun, 8 Apr 2001, Archit Baweja wrote:
> After asking a bit about this problem on irc, I decided to ask on the mailing
> lists. Well, in my app using libglade to develop the dialog. heres what the
> creation function looks like.
>
> void
> create_my_dialog ()
> {
> GladeXML *gui;
>
> gui = glade_xml_new ("my-glade-file.glade", "dialog1");
> glade_xml_signal_autoconnect (gui);
> gtk_object_unref (GTK_OBJECT (gui));
>
> return;
> }
>
> Hope that is ok. In dialog1, I have a GtkEntry from which I want to get the
I think it's fine so long as you don't try to use the XML again.
However, from the look of your code you want to use the XML to get widgets
by name, so I would suggest you leave the object alone. ;-)
> string typed in by the user. I have connected the callback for the Ok button
> of the dialog box and it looks like this (roughly).
>
> void
> dialog_ok_cb (GtkWidget *w, gpointer data)
> {
> GtkWidget *entry;
>
> entry = lookup_widget (GTK_WIDGET (widget), "entry1");
> ......
> .....
> }
>
> Well lookup_widget is a func which is generated by glade when you tell it to
> build the source code. So I copied it from some other project(Guys using glade
> with C source code output, will be familiar with it). Well lookup_widget is
> not able to get the pointer to the entry widget for me. What do I do.
'lookup_widget' is only for glade-produced source code; it searches
through a table of name<->widget mappings that glade creates when it writes
the source code. It will not work with libglade (unless you use the
hacked-up version I stuck in Archimedes ;-).
> If I use glade_xml_get_widget (), I will have to remove the call to
> gtk_object_unref () from the creation function and have a GladeXML* passed as
> data to the callback. Also I'll have to gtk_signal_connect_object_after (), so
> that the GladeXML* is freed after the clicked signal using gtk_object_unref.
> So how do I achieve this. Remember I'm a lazy programmer and what I'm looking
> for is for some way to specify this in the glade file itself and make
> glade_xml_signal_autoconnect () do things for me.
You're half-right: you will have to remove the call to
gtk_object_unref above. However, you will not have to pass the GladeXML* as
data to the callback -- that pointer is available from every widget created
by glade.
And below would be the hacked-up lookup_widget function I wrote for
Archimedes:
/* search for a widget given a known widget (in the same widget tree)
* using libglade.
*/
GtkWidget*
lookup_widget( GtkWidget *widget, const gchar *widget_name )
{
GladeXML *xml;
GtkWidget * wdgt;
xml = glade_get_widget_tree( widget );
wdgt = glade_xml_get_widget( xml, widget_name );
if(wdgt == NULL)
g_warning ("Widget not found: %s", widget_name);
return wdgt;
}
> Archit Baweja
Good luck.
- Bibek
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]