Thank you very much, I got the ideas. Both of them works for me. I prefer
the 'g_object_set_data(G_OBJECT(assistant), "builder", builder);' way, which
is convenient for my code.

On Thu, Jun 10, 2010 at 12:08 AM, Nicola Fontana <n...@entidi.it> wrote:

> Il giorno Wed, 9 Jun 2010 14:54:07 +0200
> Tadej Borovšak <tadeb...@gmail.com> ha scritto:
>
> > Hello.
> >
> > > Thank you, I'm sorry for that I didn't explain the problem clearer.
> What I
> > > meant is that there is no similar function of
> > > 'glade_get_widget_tree(widget)'. At the context where should call
> > > gtk_builder_get_object(), there is no 'GtkBuilder* builder' available.
> In
> > > the previous code, we can call 'glade_get_widget_tree(widget)' to get
> the
> > > GladeXml object of the given 'widget'. However, I don't know how to do
> it in
> > > GtkBuilder?
> > >
> > > If I can get the GtkBuilder object from 'assistant', then I can call
> > > gtk_builder_get_object() to get the widget by its id. If I cannot get
> it,
> > > then how to get the widget by id from the top level widget? Thanks.
> >
> > I'm afraid that there is no equivalent for that in GtkBuilder (objects
> > that are constructed by builder don't carry any information about who
> > constructed them). You'll need to pass your builder object around
> > manually (g_object_set_data() would be one option, global variable
> > second, struct that is passed to all of the functions would be third,
> > ...).
>
> I'd like to suggest another alternative, that is programmatically
> traverse the widget tree. The following untested snippet just to
> give the idea:
>
> GtkWidget *
> gtk_widget_lookup(GtkWidget *top_level, const gchar *name)
> {
>    GtkWidget *widget = NULL;
>
>    if (strcmp(name, gtk_widget_get_name(top_level) == 0) {
>        widget = top_level;
>    } else if (GTK_IS_CONTAINER(top_level)) {
>        GList *children = gtk_container_get_children(top_level);
>        while (children) {
>            if (widget == NULL)
>                widget = lookup_widget(children->data, name);
>            children = g_list_delete_link(children, children);
>        }
>    }
>
>    return widget;
> }
>
> --
> Nicola
>



-- 
Regards

Tao Wang
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to