[Pyrex] when pyrex gets tough

David McNab david at rebirthing.co.nz
Sun Sep 2 22:03:05 CEST 2007


On Sun, 2007-09-02 at 16:42 +0200, Stefan Behnel wrote:
> Any reason you're requiring tuple access and not using a wrapper class?

No actual requirement for tuple access, come to think.

What I do need is:
 - ability to easily construct and discard ratios as some kind of
   object, whether a python tuple, or a special class, or whatever
 - ability to access the existing ratio constants from python, in some
   form
 - ability to pass these ratios in as arguments

For (a poor) example of usage:

        import yuv4mpeg
        
        stream1 = yuv4mpeg.Stream()
        stream1.setFrameRate(yuv4mpeg.fpsRatioPal)
        
        stream2 = yuv4mpeg.Stream()
        fpsMyWebcam = yuv4mpeg.Ratio(15, 1) # new ratio for 15fps webcam
        stream2.setFrameRate(fpsMyWebcam)

Question is - how to implement this in Pyrex?

Unless I've been badly misreading the manual, there seems to be no
straightforward way to get hold of the extern'ed ratio struct constants
that are referenced from yuv4mpeg.h

It's easy to access stuff that's #defined'd, via:

        cdef extern from "yuv4mpeg.h:
                ...
                enum Y4CONSTS:
                        ...
                        Y4M_OK
                        Y4M_ERR_RANGE
                        Y4M_ERR_SYSTEM
                        Y4M_ERR_HEADER
                        ...
                ...

But how do you access extern'ed variables of a struct type?

I'd be thrilled to be proven wrong here, but this seems to have been one
case where wrapping with SWIG has proven easier and quicker than
wrapping with Pyrex.

BTW - I've published the SWIG wrapper to:

        http://www.freenet.org.nz/pyyuv4mpeg/

Cheers
David






More information about the Pyrex mailing list