My kingdom for a pango.Matrix

Why oh why does PyGTK define a pango.Matrix class to wrap a PangoMatrix struct, and provide a set of methods for manipulating them, but no way to create the blasted things in the first place?


>>> import pango
>>> m = pango.Matrix()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
NotImplementedError: pango.Matrix is an abstract widget

Abstract widget? Abstract widget!? What’s abstract about a plain old C struct?

typedef struct _PangoMatrix    PangoMatrix;
struct _PangoMatrix
  double xx;
  double xy;
  double yx;
  double yy;
  double x0;
  double y0;

It’s not an abstract interface. It’s not even something derived from GObject, for crying out loud. It’s six doubles duct-taped together! PyGTK should be able to wrap this in its sleep. And don’t even get me started on how pango.Matrix is most certainly not a widget; it’s a smegging matrix.

And to make things worse, there doesn’t even seem to be a way to make a trivial C function that creates a PangoMatrix* and make a PyGTK-compatible wrapper for it. Since PyGTK knows about pango.Matrix, and has methods that work with them, I obviously need to tell PyGTK that my trivial C function returns one. No such luck:

Could not write function ma_matrix_new_rotate: No ArgType for PangoMatrix*

And lest you think that PyGTK wants to internally call it PyPangoMatrix_Type — which, after all, would fit with the naming scheme for everything else it wraps out of GTK — that doesn’t work either.

Apparently pango.Matrix is in some kind of weird limbo where PyGTK knows about it but won’t let you actually use it at all.

Unless anyone knows the proper voodoo to make PyGTK cooperate, it looks like I’m going to have to implement the entire widget in C instead of Python, just because I can’t smuggle a PangoMatrix into my Python code. After I’ve gone ahead and implemented the entire widget except for what I need the PangoMatrix for.


Comments Off

Quick PyGTK Tip

If you ever find yourself writing a custom widget using PyGTK, and can’t figure out why none of your do_something methods are ever getting called, make sure you have this line of code after your class’s definition:

gobject.type_register (YourCustomWidgetClass)

Believe me, remembering this will save you at least an hour of very confused debugging. PyGTK will never complain that you forgot to do this. Instead, you’ll just end up with a widget that doesn’t actually do anything.

Comments Off