[wxPython-users] Creating Custom wxPython Widget

Christopher Anderson sidewinder.asu at gmail.com
Thu Dec 7 12:15:59 PST 2006


Robin Dunn wrote:
> As others have mentioned, the easiest thing would be to write an
> extension module for creating and accessing your C++ data structures,
> and (re)write the widget itself in Python.  You could even avoid SWIG
> altogether this way and just write the data structure extension module
> by hand, which will let you end up with a more efficient extension.  Or,
> if some other tool fits your brain better then you could use that.

Yes, I am kind of flip flopping in my mind between doing it this way,
or trying to wrap a C++ widget. The main issue for me is speed and
efficiency as far as accessing the data is concerned. One widget that
I will be creating will need to take a large array of floating point
data, and based on the values in the array plot colored points in a 2D
image. If I were to create this widget entirely in python, and connect
it to a data structure extension module, I would need some way of
getting fairly direct access to that raw data array (which would
reside on the C++ side of things). This doesn't seem to me to be a
particularly obvious or easy task. I totally understand how to wrap c
functions that pass values back and forth, but I don't want to copy
the entire data array (into a list for example) and pass it, since
that would be slow.

The only thing I have found yet that might do what I want is the NumPy
array object, which appears to allow access to the raw data from both
python and from within a C extension module. So I could create a NumPy
array in the extension module, give it a pointer to my data array, and
then pass it to the wxPython object which would then use it to draw
the pixels. Does this sound like it would work?

Thanks to everyone,
Chris Anderson




More information about the wxpython-users mailing list