[PyKDE] SIP issues.

Gerard Vermeulen gerard.vermeulen at grenoble.cnrs.fr
Tue Nov 23 20:51:14 GMT 2004


Hi,

When trying to wrap QwtPlot3D (http://qwtplot3d.sourceforge.net), I encountered
several issues with SIP:     

(1) Problems in getting an (abstract) virtual operator() working. Finally, 
    the following code works with SIP4 (thanks to the extra class PyFunction)
    but not (yet) with SIP3: 

class Function: GridMapping
{

%TypeHeaderCode
#include <qwt3d_function.h>
using namespace Qwt3D;
%End // %TypeHeaderCode

public:
    // SIP does not handle an 'abstract virtual operator()' well
    // virtual double operator()(double x, double y) = 0;
private:
    Function();
}; // class Function

class PyFunction: Function
{

%TypeHeaderCode
#include <qwt3d_function.h>
using namespace Qwt3D;

class PyFunction: public Function
{
public:
    PyFunction(): Function() {}

    // (1) __call__ anticipates a code generation bug in SIP-4.0 and SIP-4.1
    // (2) __call__ is defined as a 'negative hat' to show that redefining
    // __call__ in a subclass has no effect when using SIP-3.11.
    virtual double __call__(double x, double y) { return -x*y; }
    virtual double operator()(double x, double y) { return __call__(x, y); }
}; // class PyFunction

%End // %TypeHeaderCode

public:
    PyFunction();

%If (NEWSIP)
    virtual double operator()(double, double);
%MethodCode
    sipRes = sipCpp->__call__(a0, a1);
%End // %MethodCode
%End // NEWSIP

%If (OLDSIP)
    // SIP-3.11.1: Operators cannot be virtual
    /*virtual*/ double operator()(double, double);
%MethodCode
    sipRes = sipCpp->__call__(a0, a1);
%End // %MethodCode
%End // OLDSIP

}; // class PyFunction


I use an __init__.py to make PyFunction an alias for Function:

from _Qwt3D import *

# Alias the helper classes away.
del PyFunction
from _Qwt3D import PyFunction as Function


(2) Why does the PyName annotation only apply to functions? 
    class def { public: double yield; }; can only be wrapped if PyName
    can also be used for class names and variable names.

(3) Slots like __getitem__, __len__, and __setitem__ of a Python type defined
    in a SIP file do not show with dir() (dir([]) shows those slots).

Gerard




More information about the PyQt mailing list