Saturday, February 20, 2010

working on gtypes

We've been moving forward on the PySoy rewrite using Genie in faith that a Python 3 binding for GObject would come about.

At PyCon this weekend I've brainstormed with Kirk McDonald, author of PyD which serves a similar role to use D types/objects in Python, and several other authors of FFIs for Python. A rough strategy is coming together to solve this in a dynamic manner.

The first part of the solution is libvala; using a small part of its functionality to parse .vapi and .gir files for existing GObject libraries such as GTK and Cairo as well as any library written in Vala or Genie. This gets us the C API for the library in all it's object oriented goodness, and with that we can dynamically generate bindings using Python's ctypes.

The second part is a GObject type in Python which supports subclassing in Python. Kirk detailed how this is done in PyD; each generated GObject type gets a subtype with all of its virtual methods all running Python methods which call the superclass's C method by default. When a Python subclass of a GObject class is made this GObject subclass is used allowing Python to override any of its methods and pass objects of the subclass back to GObject where they'll perform as expected. Not simple or easy, but its a strategy.

The end result is dynamic Python 3 bindings for GTK as well as PySoy and all the other tools we work on.

I'm organizing a sprint for this at PyCon. If anyone has ideas on this please comment, or if you'd like to help (whether at PyCon 2010 or not) get in touch with me.

3 comments:

jjardon said...

Hello, maybe you already know, but some people are working in a python hackfest to "porting PyGObject to Python 3.x and giving a push to PyGI [1](gobject-introspection bindings)"

More info here: http://live.gnome.org/Hackfests/Python2010

[1] http://live.gnome.org/PyGI

Unknown said...

Cool, then there'll be yet another way to do it.

Given that GIR doesn't support our GObject-based libraries, and given that its blocking our next release, I'm not planning to wait.

Lucian said...

I'm curious where gtypes lives these days. gtypes.org has an old repo.