[PyQt] converting SWIG objects to SIP objects
Phil Thompson
phil at riverbankcomputing.com
Wed Sep 1 20:08:21 BST 2010
On Wed, 01 Sep 2010 11:00:30 -0400, Blaine Bell
<blaine.bell at schrodinger.com> wrote:
> I was able to write a SIP function that takes a SWIG object, converts it
> to a SIP object, as well as a function that converts a SIP object back
> to a SWIG object:
>
> The object I have implemented in SIP and SWIG is called "ChmMol":
>
> ChmMol *convertChmMoltoSIP(SIP_PYOBJECT);
> %MethodCode
> if (!SWIGTYPE_p_ChmMol){
> SWIG_init();
> }
> if ((SWIG_ConvertPtr(a0,(void **) &sipRes, SWIGTYPE_p_ChmMol, 0 ))
> == -1) return NULL;
> %End
> SIP_PYOBJECT convertChmMoltoSWIG(ChmMol *);
> %MethodCode
> if (!SWIGTYPE_p_ChmMol){
> SWIG_init();
> }
> sipRes = SWIG_NewPointerObj(a0, SWIGTYPE_p_ChmMol, 0);
> %End
>
>
> In order to do this, I needed to include the c++ file that was generated
> by swig executable running on the SWIG .i file. Including that c++ file
> (in the "%ModuleCode") instantiates an entirely new SWIG dictionary
> inside my SIP DLL that needs to be initialized (hence, the SWIG_init()
> call).
>
> My question to the SIP experts: is there a way to allow SIP to allow
> SWIG or SIP objects as arguments that have a specific type?
For a specific type you could define it to SIP as a %MappedType and
implement conversion code that called the SWIG API.
> Is there a
> Directive or Annotation that allows me to write a conversion, so I can
> override the conversion from the Python object to C++ object for each
type?
No, although I'm not sure I understand the question.
Phil
More information about the PyQt
mailing list