Re: Locating child-widgets (by name) without Glade-code



On Sun, 2003-08-17 at 10:02, Gus Koppel wrote:
Owen Taylor wrote:

Is there an (official) way in GTK+ 2.2 to get a pointer to a
GtkWidget by the name of the widget, like Glade imposes it by its
lookup_widget()-function and GLADE_HOOK_OBJECT ()-lists?

gtk_widget_set_name() is *not* meant for this purpose; it's rather 
meant for the purposes of theming particular widgets; trying to search
for widget names set by gtk_widget_set_name() is going to be slow,
and GTK+ does not enforce uniqueness.

GTK+ doesn't enforce widget names at all, AFAIK. However, if you plan to
reference them by your code and not let it look too ugly you'll likely
assign the wanted ones comprehensive names.

And the speed issue? Well, suppose you have a window with <=100 widgets
where particular ones are searched only on button hits or menu entry
selections. I think no one would ever notice a maximum of some hundred
(usually less) strcmp()s when a button is hit. Other common reactions,
i.e. modifying treeview contents, opening and displaying dialog windows,
probably take hundreds to thousands of times longer, likely several
hundredths of seconds.

Of course, searching widgets by name isn't a suitable operation inside
lower level loops. In such cases I would prefer + prepare fixed
pointers indeed.

If you want to keep all your widgets in a big hash table, nobody 
is stopping you. Implementing this, including such niceties as
removing widgets from the hash when they go away, is probably
no more code than hunting the widget hierarchy for
gtk_widget_set_name().

It seems a strange way to organize a program, however. Why not
let the compiler let you catch using the wrong name?

The first thing I typically do when I create a libglade layout
(Don't use glade to generate code,
http://lists.ximian.com/archives/public/glade-devel/2003-February/000015.html) is pull out all the widgets 
I'm interested in and stick pointers
to them in a struct.

Regards,
                                                Owen





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