Sometimes I need to call a gtk/gobject function that only exists in C, but returns an object that has a python wrapper. Previously I used a solution based on ctypes that worked well:
http://faq.pygtk.org/index.py?req=show&file=faq23.041.htp
Now that I swiched from PyGtk (“import gtk”) to GObject-introspection (“from gi.repository import Gtk”), what can I use instead?
The
_PyGObject_APIinterface has changed at some point. I needed to drop theregister_sinkfuncfunction. The following works:To get an object from a pointer:
to get a pointer from a (g)object:
I have to add, in my case this didn’t help me solve my actual problem. I was trying to interface with dconf, but dconf returns values of type GVariant, which does not inherit from GObject. It seems PyGI/GObject unfortunately does not expose the neccessary functions to turn a C (*GVariant) into a Python GLib.Variant. I guess it’s of those times when you have to throw away your initial approach and try something different.