[PyQt] SIP properties
phil at riverbankcomputing.com
Fri Apr 11 23:16:54 BST 2008
On Friday 11 April 2008, Kevin Watters wrote:
> I want to make an option for SIP to autogenerate properties (i.e., GetTitle
> and SetTitle just become Title).
> I've been reading through transform.c, trying to get a feel for how this
> might happen, but I think I'm lacking the "big picture" when it comes to
> how SIP implements methods and attribute lookups in general.
> I see from some bits in transform.c, mailing list posts, and PyQT's docs on
> the usage of "super" that a all attribute lookups are lazy. This is
> great--I don't want to lose the positive impact this will have on my app's
> startup time. But that means my initial plan for just introspecting on all
> classes in Python via startup and assigning properties at module load time
> is not going to work, since I think it would mean that I would be accessing
> EVERY single Get/Set method, negating any benefit of the lazy lookups.
> I know properties are descriptors that call special functions when accessed
> or set, and I know how to create them in pure Python. I know that
> isinstance(MySipType(), object) == True, which my SIP derived classes are
> new-style and can benefit from properties (via descriptors). But I'm
> missing an understanding of where this would fit into the transformation
> process defined in transform.c.
> Can anyone with a better understanding of SIP's internals point me in the
> right direction?
The first question to answer is how are you going to specify the necessary
information in the .sip files. I'd suggest using function annotations like...
const char *GetTitle() const /PropertyGetter=Title/;
void SetTitle(const char *title) /PropertySetter=Title/;
Now you know that you want to create a property called "Title" and you know
the C getter and setter. That data structure should be created in parser.y.
transform.c won't do much, you just need to generate the relevant code in
More information about the PyQt