[PyKDE] sip

Jim Bublitz jbublitz at nwinternet.com
Fri Jan 10 18:16:01 GMT 2003


On 10-Jan-03 Jason Lee wrote:
> I hope this is the right place.  The Riverbank Computing web page
> said it was, so...
 
> I'm new to sip.  I've been toying with swig, and haven't gotten
> boost to run.  I'm trying to get a Python wrapper for a C++
> library (duh :), but I'm having trouble setting up my .sip.  If
> I have an empty class, things work fine.

If the class is derived from base classes, remove
the access-specifiers:

    class someClass : public baseClass

in the sip file:

    class someClass : baseClass

> Once I  start adding lines from the header file, I start getting
> parse errors.  The  lines that seem to be causing problems are
> definitions of functions pointers  (

> static void(*clearScreen)(uchar w, uchar h);

sip won't handle these automatically - you need to provide
handwritten code and I'm not sure how to do that in this case. 
I've reposted this as a separate message, since it would be helpful
for me to learn how to do it also.

> or struct declarations.  The  odd thing about the struct,
> though, is that if it's empty, it's fine.  Once I 
> add anything to to (e.g., uchar R,G,B,Alpha;), I get a parse
> error.  

The easiest way to handle structs is as a class:

   struct someStruct
   {
       uchar R, G, B, alpha;
   };

can be done as:

   class someStruct
   {
   public:
       uchar R;
       uchar G;
       uchar B;
       uchar alpha;
   };

You need to add "public" because the default access type for
structs is public, while the default for classes is private (and
that's about the only difference between the two). It may be that
newer versions of sip now handle "struct" correctly, and the
problem may be with the list in the declaration as opposed to
declaring each variable individually. The "class" method above
should work though.

> It also errors out if I put a const int declaration outside any
> struct or class scope. 

I'm not sure what you mean here - global variable? It should work
OK, although I'm not sure if you can set the value of a global
variable from Python.

> I'm sure I'm missing something fundamental, but the docs aren't
> helpful, and the  PyQT .sips are a little overwhelming for a
> newbie. :) 

You're actually being too kind here - the documentation situation
is pretty poor. Phil will be providing better docs with sip 4.0.
I've also volunteered to write a tutorial for sip, and there are
other things in the works to try to make sip easier to use.
Unfortunately all of this will occur sometime in the future, which
isn't a big help to you now.

> Does anyone have any  pointers as to what I'm doing wrong?  I'd
> appreciate the help.
 
> BTW, if this is the wrong list, I apologize.  It seems to be,
> based on the web page, but if it's not, I'll gladly take my
> question somewhere else.

You're in the right place - please feel free to post any questions
you need answers to. PyQt is probably the best place to look for
most answers - compare some .h file to a corresponding .sip file.
The %If ... %End stuff is just versioning/platform/feature stuff,
roughly equivalent to #ifdef in C/C++. Most of the things you're
asking about aren't used in PyQt however, so about the only way
to get answers for those right now is to ask here.

Jim




More information about the PyQt mailing list