Again I end up writing about it too late. I had a rather unpleasant semester which kept me quite busy. It's over know, and I'm about to leave for a week of vacation in the snowy Alps. So, here is a quick 'n dirty note about the current state of PyGI development.
The first not-so-recent piece of news is that PyGI is now hosted on git.gnome.org, we got a bugzilla product for it, and the IRC channel where you can harrass us about it is now #pygi (yep, we definitively burried PyBank).
On the code side, we changed the way constructors get wrapped. PyGI used to wrap alternate constructors and select one for the default constructor. Unfortunately, those constructors were not suited for class inheritance, since they are only able to create instances of their base class. Thus, we changed PyGI to use Python GObject's constructor as default constructor, which takes values for properties as keyword arguments. Alternate constructors are made available as class methods for convenience, but will throw an error if they are being used in subclasses.
We also changed the way structures are created, to allow one to create instances regardless of the presence of an allocator and a freeing function. There are still a few things to fix regarding structures support, but what is to change is not clear yet.
More recently, I restored the overrides support. I put a module proxy in front of both the dynamic module and the overrides module, if there is one. When a member is accessed, it is first resolved in the overrides module. It was a bit tricky to make the dynamic module available to the overrides one, but I think the solution is rather elegant. Here is how writing an overrides module it looks like (please imagine the indentation, the blog engine stripped it; don't know why :-/ ):
from ..types import override from ..importer import modules Gdk = modules['Gdk'] class Rectangle(Gdk.Rectangle): def __init__(self, x, y, width, height): Gdk.Rectangle.__init__(self) self.x = x self.y = y self.width = width self.height = height def __new__(cls, *args, **kwargs): return Gdk.Rectangle.__new__(cls) def __repr__(self): return '<Gdk.Rectangle(x=%d, y=%d, width=%d, height=%d)>' % ( self.x, self.y, self.width, self.height) Rectangle = override(Rectangle) __all__ = [Rectangle] import sys initialized, argv = Gdk.init_check(sys.argv) if not initialized: raise RuntimeError("Gdk couldn't be initialized")
So, all you need to do in order to override a dynamically-generated wrapper is to subclass it, and register the subclass using the override decorator.
You can also do stuff at the module creation, like calling the module initialization function.
Note that in order to avoid exporting internal variables (Gdk.modules, for example), you can restrict the things to export in all.
Then put the file with the same name as the namespace in $(pyexecdir)/gtk-2.0/gi/overrides/.
I think that's it for now. Again, thanks to Tomeu and Johan for their cooperation on all this. Zach just submitted a patch for callbacks and virtual functions too. Thanks, Zach! Sorry, no time to review that now; I'll make it top-priority when I'll be back.
Oh, yeah, and:
See you and happy hacking!


















