Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Problem with passing wxDC to c++ extension on linux

20 views
Skip to first unread message

Andrew Jones

unread,
Feb 11, 2015, 3:06:14 PM2/11/15
to wxpytho...@googlegroups.com
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
fastlines.h
fastlines.i
__init__.py
setup.py
test.py

Andrew Jones

unread,
Feb 11, 2015, 8:39:41 PM2/11/15
to wxpytho...@googlegroups.com
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

--
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-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages