Problem with passing wxDC to c++ extension on linux

I’ve written an extension which attempts to speed up the DC DrawLines routine when using numpy arrays. It does this by converting the numpy array to integers, passing the array and the dc to a c++ function, and casting the array directly to wxPoints when calling DrawLines. It works well on windows and gives speedups of 10 - 20x. Heres the cpp file.

#include <wx/wx.h>
#include “fastlines.h”

void dc_fastlines(wxDC dc, int pts, int n)
{
dc->DrawLines(n/2, (wxPoint *) pts);
}

``

This is wrapped by the following function in python to convert the numpy array to int and make it a 1 dimensional array for passing the the c++ function:

def FastLines(dc, pts):
ipts = pts.astype(int)
ipts.shape = (ipts.size, )
print “DC is”, dc
dc_fastlines(dc, ipts)

``

When I attempt to run it on linux (RHEL6) I get the following error:

DC is <wx._gdi.PaintDC; proxy of <Swig Object of type ‘wxPaintDC *’ at 0x9d777c8> >
Traceback (most recent call last):
File “test.py”, line 29, in OnPaint
FastLines(dc, pts1)
File “/home/kea/ajones/ner/lib/python/wx_accelerators/fastlines/init.py”, line 19, in FastLines
dc_fastlines(dc, ipts)
File “/home/kea/ajones/ner/lib/python/wx_accelerators/fastlines/fastlines.py”, line 88, in dc_fastlines
return _fastlines.dc_fastlines(*args, **kwargs)
TypeError: in method ‘dc_fastlines’, argument 1 of type ‘wxDC *’

``

Again, this works beautifully under windows. Any idea why this error might happen on linux? I’ve tried changing it to specify a wxPaintDC instead and get a TypeError again complaining about type wxPaintDC *.

I’m using wxPython classic version 3.0.2 and python 2.7.8. The extension was built using the patched version of swig. The included files provide a working example on windows that fails on linux.

Thanks,

Andrew

fastlines.cpp (132 Bytes)

fastlines.h (100 Bytes)

fastlines.i (382 Bytes)

init.py|attachment (504 Bytes)

setup.py (1.26 KB)

test.py (845 Bytes)

It looks like the problem was a swig version mismatch. Rebuilding wxPython after editing the config.py file to set the variables SWIG to the correct path to the patched swig and USE_SWIG = 1 to force it to regenerate the swig wrappers instead of using the packaged ones worked.

Andrew

···

On Wed, Feb 11, 2015 at 3:06 PM, Andrew Jones arjones6@gmail.com wrote:

I’ve written an extension which attempts to speed up the DC DrawLines routine when using numpy arrays. It does this by converting the numpy array to integers, passing the array and the dc to a c++ function, and casting the array directly to wxPoints when calling DrawLines. It works well on windows and gives speedups of 10 - 20x. Heres the cpp file.

#include <wx/wx.h>
#include “fastlines.h”

void dc_fastlines(wxDC dc, int pts, int n)
{
dc->DrawLines(n/2, (wxPoint *) pts);
}

``

This is wrapped by the following function in python to convert the numpy array to int and make it a 1 dimensional array for passing the the c++ function:

def FastLines(dc, pts):
ipts = pts.astype(int)
ipts.shape = (ipts.size, )
print “DC is”, dc
dc_fastlines(dc, ipts)

``

When I attempt to run it on linux (RHEL6) I get the following error:

DC is <wx._gdi.PaintDC; proxy of <Swig Object of type ‘wxPaintDC *’ at 0x9d777c8> >
Traceback (most recent call last):
File “test.py”, line 29, in OnPaint
FastLines(dc, pts1)
File “/home/kea/ajones/ner/lib/python/wx_accelerators/fastlines/init.py”, line 19, in FastLines
dc_fastlines(dc, ipts)
File “/home/kea/ajones/ner/lib/python/wx_accelerators/fastlines/fastlines.py”, line 88, in dc_fastlines
return _fastlines.dc_fastlines(*args, **kwargs)
TypeError: in method ‘dc_fastlines’, argument 1 of type ‘wxDC *’

``

Again, this works beautifully under windows. Any idea why this error might happen on linux? I’ve tried changing it to specify a wxPaintDC instead and get a TypeError again complaining about type wxPaintDC *.

I’m using wxPython classic version 3.0.2 and python 2.7.8. The extension was built using the patched version of swig. The included files provide a working example on windows that fails on linux.

Thanks,

Andrew

You received this message because you are subscribed to a topic in the Google Groups “wxPython-users” group.

To unsubscribe from this topic, visit https://groups.google.com/d/topic/wxpython-users/s1vcZr3GTgs/unsubscribe.

To unsubscribe from this group and all its topics, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.