[sugar] How to get pygtk to give you a GtkToolTips from a Toolbar to pass to ToolItem's set_tooltip?

Don Hopkins dhopkins at DonHopkins.com
Mon May 21 22:58:25 EDT 2007


I'm trying to set the tooltip of a tool item, which I though would be 
easy, but the ToolItem.set_tooltip takes a first parameter that's a 
mysterious GtkTooltips object.
But I can't figure out how to get a reference to the required ToolTips 
object to pass as a first argument to a ToolItem's set_tooltip(tooltips, 
tool_tip_string) ...
The obvious looking method GtkToolbar.get_tooltips() actually returns a 
boolean that tells if the toolbar is using tooltips, but does not return 
the toolbar's "GtkTooltips *tooltips" member, which is declared public 
but apparently not exposed as a property to Python.

Is there an existing way to get a reference to the GtkTooltips object? 
Or another way to set the tooltip of a ToolItem without passing in a 
GtkTooltips?

In desperation, I hacked pygtk to support a phantom 
"toolbar.get_tooltips_object()" method that returns the toolbar's actual 
GtkTooltips object.
It seems to work ok, and now I can get the tooltips object, then pass it 
to set_tooltip without giving it indigestion, so now I'm getting tooltips!
Is this a change that should be added upstream to pygtk, or is there a 
better way to do it? Would there be a better name for it?

Added to gtk-base.defs after the definition of "popup_context_menu":

(define-method get_tooltips_object
  (of-object "GtkToolbar")
  (c-name "gtk_toolbar_get_tooltips_object")
  (return-type "GtkTooltips*")
)


Added to gtk.override at the end:

%%
override gtk_toolbar_get_tooltips_object noargs
static PyObject *
_wrap_gtk_toolbar_get_tooltips_object(PyGObject *self)
{
    GtkTooltips *ret;

    ret = GTK_TOOLBAR(self->obj)->tooltips;

    /* pygobject_new handles NULL checking */
    return pygobject_new((GObject *)ret);
}


I'm kind of winging it with the pygtk-codegen stuff.
It's not very well documented, so I read the code to figure out how it 
works, and took some notes.
It would be great if somebody who's more familiar with it could 
elaborate on it and correct any mistakes, please!
I've put the notes up on the olpc wiki!

http://wiki.laptop.org/go/PyGTK-Codegen

    -Don



More information about the Sugar mailing list