[PyKDE] SIP questions

Phil Thompson phil at river-bank.demon.co.uk
Tue Mar 25 21:19:01 GMT 2003


On Tuesday 25 March 2003 7:20 pm, WELCH,DONALD J (HP-Vancouver,ex1) wrote:
> Greetings-
>
> I am attempting to wrap a shared library on Linux using SIP. This shared
> library's API defines several C++ classes that interelate (in both IS-A and
> HAS-A relationships). Currently, all the classes are declared in a single
> .h file.
>
> Questions:
>
> 1. What is the difference between %Import and %Include?

%Import is used when you are wrapping a library that sub-classes from another 
library that has also been wrapped. So PyKDE effectively %Imports PyQt.

%Include is similar to the C pre-processor's #include.

> 2. Should I define a single top level .sip file that has the %Module
> statement and then %Imports/%Includes each of the .sip files for each class
> that is being wrapped? If not, where does the %Module statement go? I am
> confused bt the PyQt file qtmod.sip that %Includes other .sip files, but
> then those .sip files %Import qtmod.sip.

You've mis-read the .sip files. qtmod.sip does not %Include any file that 
%Imports qtmod.sip.

Whether you put each class into a separate .sip file is a readability issue 
and is up to you.

> 3. In the PyQt .sip files, the %Module statement includes a 0 (zero) after
> the module name. This is not in the SIP docs. What does it mean?

It's for SIP v4 and is a version number. SIP v3 ignores it.

> 4. Should the .sip file for each class %Include or %Import the .sip file
> for classes that are referenced by the wrapped class?

Neither - if I've understood the question properly.

> 5. In many of the PyQt .sip files, there isn't any %Include or %Imports to
> define base classes. How is this so?

SIP is run against the qtmod.sip file (not against each individual .sip file) 
and it brings in all the necessary stuff through %Includes.

> 6. Is it possible to add methods to classes in the .sip file that don't
> exist in (or exist differently) the wrapped .cpp code? For example, could I
> add a method that returns a Python list instead of having the Python client
> code call getFirst()/getNext() to enumerate a list of items?

Yes - you can lie to SIP as much as you want.

Depending on the nature of the class, alternatives would be to replace the 
class entirely with a Python list (using %MappedType), or implement 
appropriate Python operators (see qstringlist.sip).

> 7. Are there any tools to automate h2sip (at least the basic stuff that can
> be automated)?

Over to you Jim.

However, be aware that you sometimes have to supply SIP with more information 
(eg. /Transfer/ flags) which cannot be done automatically.

Phil




More information about the PyQt mailing list