HI all,
Robin Dunn has been working on adding better support for dumping data
directly to wxPython from the num* packages. I've been talking to him
about the new array interface, and he might well support it
(particularly if one of us contributes code), but in the meantime, he's
got a number of things working with python buffers. For instance:
wx.Image.SetDataBuffer(dataBuffer)
That sets the data for a wxImage to the buffer handed in. This isn't as
nice as the array protocol, as it has no way of checking anything other
than if the length of the buffer is correct, but it is a good way to
maximize performance for this sort of thing.
he's now working on adding methods for creating wx.Bitmaps directly from
buffers. In the process if testing some of this, I discovered that
numarray (which Robin is testing with) works fine, but numpy does not. I
get:
File "/usr/lib/python2.4/site-packages/wx-2.6-gtk2-unicode/wx/_core.py",
line 2814, in SetDataBuffer
return _core_.Image_SetDataBuffer(*args, **kwargs)
TypeError: non-character array cannot be interpreted as character buffer
If I try to pass in a numpy array, while it works great with a numarray
array.
While I'm a great advocate of the new array protocol, it seems
supporting the buffer protocol also would be a good idea. I've enclosed
some simple test code. It works with numarray, but not numpy 1.0b4
Tested with Python 2.4.3, wxPython 2.6.3.0, Linux fedora core4
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
[EMAIL PROTECTED]
#!/usr/bin/env python
import wx
dim=100
R=0; G=1; B=2; A=3
import numpy as N
arr = N.empty((dim, dim, 4), N.uint8)
#import numarray as N
#arr = N.array(shape=(dim, dim, 4), typecode='u1')
arr[:,:,R] = 125
arr[:,:,G] = 0
arr[:,:,B] = 255
alpha = N.arange(dim) * 255 / dim
arr[:,:,A] = alpha
class F(wx.Frame):
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
self.Bind(wx.EVT_PAINT, self.OnPaint)
def OnPaint(self, event):
dc = wx.PaintDC(self)
print "Drawing the bitmap"
dc.DrawBitmap(bmp, 20, 20, True)
A = wx.App()
RGB = arr[:,:,0:3].copy()
Alpha = arr[:,:,3].copy()
I = wx.EmptyImage(dim, dim)
I.SetDataBuffer(RGB)
I.SetAlphaBuffer(Alpha)
bmp = wx.BitmapFromImage(I)
f = F(None)
f.Show()
A.MainLoop()
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion