| FAQ Index - Search - Recent Changes - Everything - Add entry |
5.1. I want to understand this "data" object that is used in the set_*_data() and get_*_data() calls.
The GObject methods set_data() and get_data() allow you to attach an arbitrary reference to a GObject (or any derived class) instance keyed by a string. In other words, you can attach any number of references to any GObject and retrieve them with the strings you set() them with. This is a very helpful but often overlooked feature of GTK+, and it can come in handy.
For example, you can attach to a GtkLabel the instance it represents and a list of of versions using the following code:
l = gtk.Label()
l.set_data("object-name", some_object)
and then retrieve the data using:
>>> some_object = l.get_data("object-name")
There are also related methods associated with the CList/CTree, set/get_row_data(), and GnomeIconList's set/get_icon_data(). These methods don't index on string, but instead on position in their internal arrays.
