[PyQt] using a Macro to define %MappedType

Phil Thompson phil at riverbankcomputing.com
Fri Aug 8 17:46:40 BST 2008


On Fri, 08 Aug 2008 17:36:04 +0100, Damien Fagnou
<damien-f at moving-picture.com> wrote:
> Hi ,
> 
> we have hierachy of object binded with boost that need to be able to be 
> passed to a qt class bound with sip
> class myWidget : public QGLWidget
> {
>       void setMyObject( boost::shared_ptr<MyClassA> A );
>       void setMyOtherObject( boost::shared_ptr<MyClassB> B );
>       void setMyLastObject( boost::shared_ptr<MyClassC> C );
> }
> 
> in my myWidget.sip
> 
> I have
> 
> %Include MyClassA.sip
> 
> where classA.sip is
> %MappedType MyClassAPtr
> {
> %TypeHeaderCode                                                          

> #include 
> <boost/python/extract.hpp>                                       
> #include "MyClassA.sip"
> using namespace boost::python;                                           
> %End
> 
> %ConvertToTypeCode
>    ......
>    boost::python::extract<MyClassAPtr> convert( sipPy );
>    .....
>    return 0;                                                    %End
> 
> %ConvertFromTypeCode
>    return  boost::python::object(sipCpp).ptr();
> %End
> }
> 
> this is working fine , but I have many , many classes , ideally I would 
> like to be able to right a template or macro
> so I could just do
> 
> MY_CONVERT( MyClassAPtr )
> MY_CONVERT( MyClassBPtr )
> MY_CONVERT( MyClassEPtr )
> 
> before the code of my widget . is there something like %Macro file value 
> .. or something of that type ?

No.

> I guess I could write scripts to generate those *.sip file from the 
> template before hand .

Or look at a macro package like m4.

Phil



More information about the PyQt mailing list