Not sure is this will help you, but perhaps you could define your
__cinit__() to have an empty image (perhaps with a NULL pointer), and
then define some creational methods, then you could do from Python
side

img1 = Image()
img1.createFromFileData(filename)

img2 = Image()
img2.createFromNumpyData(numpy_array)

img3 = Image()
img4.createFromStringData(python_byte_string)


Other way could be do define static/class factory methods, and then you do

img1 = Image.createFromFileData(filename)

img2 = Image.createFromNumpyData(numpy_array)

img4 = Image.createFromStringData(python_byte_string)

The two alternatives are rather similar, however, the second has some
conveniences.

A BIG problem with the fist option is that if you let a Python
instance to have a NULL pointer, then you will need to check against
that NULL on almost every other method call calling you C lib
routines, if not, you could potentially get nasty segfaults.

By using the second patter, you can restrict Python instances to
always have a non-NULL, valid handle to a C-side, then you can code
your methods with prior knowledge that the handle is a valid one...

In short, all this is in general a matter of personal style and
preferences. I would perhaps follow option 2, I mean, define some
factory @classmethod's you call from Python side to create images from
the many sources...




On Tue, May 19, 2009 at 6:22 PM, Chris Colbert <[email protected]> wrote:
> True, but it seems a little "off" to programatically set every attribute one
> by one every time i create an instance of that type.
>
> Is it not recommended to declare a property for every attribute I want
> access from in python?
>
> Chris
>
> On Tue, May 19, 2009 at 5:17 PM, Robert Bradshaw
> <[email protected]> wrote:
>>
>> On May 19, 2009, at 2:02 PM, Chris Colbert wrote:
>>
>> > What you can do is allow it to pass in a char* (bytes) object with a
>> > length, have a cdef set method, use opaque object pointer wrappers
>> > (there was a previous thread about this).
>> >
>> > i'm not sure I understand what your saying with this ^^^
>> >
>> > You could also make a function
>> >
>> > > def testload(filename):
>> > >     cdef IplImage* img = load(filename)
>> > >     cdef PyIplImage pyimg = PyIplImage
>> > >     pyimg.img = img
>> > >     return pyimg
>> >
>> > this makes sense. Just instantiate an empty PyIplImage then set the
>> > pointer after instantiation. But that would mean all attributes
>> > (width, height, etc) would have to be accessed as properties right?
>> > since I wouldn't be able to set them on __init___
>>
>> You can set readonly attributes from C.
>>
>> - Robert
>>
>>
>> _______________________________________________
>> Cython-dev mailing list
>> [email protected]
>> http://codespeak.net/mailman/listinfo/cython-dev
>
>
> _______________________________________________
> Cython-dev mailing list
> [email protected]
> http://codespeak.net/mailman/listinfo/cython-dev
>
>



-- 
Lisandro Dalcín
---------------
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to