mirror of
https://github.com/wxWidgets/Phoenix.git
synced 2025-12-15 17:20:07 +01:00
dc.DrawLinesFromBuffer demo and test to intc data type. Updated documentation.
This commit is contained in:
@@ -22,8 +22,9 @@ def TestLinesFromBuffer(dc, log):
|
||||
y2 = np.sin(vs * 16 * np.pi) * w/2 * vs + h/2
|
||||
|
||||
|
||||
pts1 = np.append(x1, y1, 1).astype('int32')
|
||||
pts2 = np.append(x2, y2, 1).astype('int32')
|
||||
# Data has to be the same size as a C integer
|
||||
pts1 = np.append(x1, y1, 1).astype('intc')
|
||||
pts2 = np.append(x2, y2, 1).astype('intc')
|
||||
|
||||
dc.SetPen(wx.BLACK_PEN)
|
||||
t1 = time.time()
|
||||
@@ -110,9 +111,16 @@ the python buffer protocol.
|
||||
DrawLinesFromBuffer(pyBuff)
|
||||
</pre>
|
||||
|
||||
The buffer object needs to provide an array of C integers organized as
|
||||
x, y point pairs. The size of a C integer is platform dependent.
|
||||
With numpy, the intc data type will provide the appropriate element size.
|
||||
|
||||
If called with an object that doesn't support
|
||||
the python buffer protocol, or if the underlying element size does not
|
||||
match the size of a wxPoint, a TypeError exception is raised.
|
||||
match the size of a C integer, a TypeError exception is raised. If
|
||||
the buffer provided has float data with the same element size as a
|
||||
C integer, no error will be raised, but the lines will not be drawn
|
||||
in the appropriate places.
|
||||
"""
|
||||
|
||||
|
||||
|
||||
14
etg/dc.py
14
etg/dc.py
@@ -481,7 +481,19 @@ def run():
|
||||
c.addPyMethod('DrawLinesFromBuffer', '(self, pyBuff)',
|
||||
doc="""\
|
||||
Implementation of DrawLines that can use numpy arrays, or anything else that uses the
|
||||
python buffer protocol, directly.
|
||||
python buffer protocol directly without any element conversion. This provides a
|
||||
significant performance increase over the standard DrawLines function.
|
||||
|
||||
The pyBuff argument needs to provide an array of C integers organized as
|
||||
x, y point pairs. The size of a C integer is platform dependent.
|
||||
With numpy, the intc data type will provide the appropriate element size.
|
||||
|
||||
If called with an object that doesn't support
|
||||
the python buffer protocol, or if the underlying element size does not
|
||||
match the size of a C integer, a TypeError exception is raised. If
|
||||
the buffer provided has float data with the same element size as a
|
||||
C integer, no error will be raised, but the lines will not be drawn
|
||||
in the appropriate places.
|
||||
|
||||
:param pyBuff: A python buffer containing integer pairs
|
||||
""",
|
||||
|
||||
@@ -48,8 +48,9 @@ class dcDrawLists_Tests(wtc.WidgetTestCase):
|
||||
ys.shape = ys.size, 1
|
||||
pts = np.append(xs, ys, 1)
|
||||
|
||||
dc.DrawLinesFromBuffer(pts.astype('int32'))
|
||||
self.assertRaises(TypeError, dc.DrawLinesFromBuffer, pts.astype('int64'))
|
||||
dc.DrawLinesFromBuffer(pts.astype('intc'))
|
||||
self.assertRaises(TypeError, dc.DrawLinesFromBuffer,
|
||||
pts.astype('int64') if np.intc(1).nbytes != np.int64(1).nbytes else pts.astype('int32'))
|
||||
self.assertRaises(TypeError, dc.DrawLinesFromBuffer, pts.tolist())
|
||||
del dc
|
||||
|
||||
|
||||
Reference in New Issue
Block a user