I tried to learn how to make a C++ extension for wxPython.
My frist aim was to make wxPython byndings for the simple FooButton class presented in http://wiki.wxpython.org/C%2B%2BExtensions.
Since that tutorial seems to be outdated, after a lot of searches on the wxPython-users group I finally managed to compile the extension.
A small wxPython application uses the FooButton extension without any errors - but the button does not appear!
Later I added a diagnostic print statement in the C++ constructor of FooButton and indeed I get the correct output in the terminal (but the
FooButton does not appear in the wxPython application. If I substitute an ordinary wx.Button for FooButton the wx.Button appears wthout any problem.
I used wxPython 2.9.4.0 and build swig 1.3.29 with the appropriate patch applied.
Here is the FooButton.i interface file:
%module foobutton
%{
#include “wx/wx.h”
#include “wx/wxPython/wxPython.h”
#include “wx/wxPython/pyclasses.h”
class wxPyTreeCtrl;#include “foobutton.h”
%}class wxPyTreeCtrl;
%import typemaps.i
%import my_typemaps.i%import core.i
%import controls.i%pythoncode { import wx }
%pythoncode { docfilter = wx._core.__DocFilter(globals()) }class FooButton : public wxButton
{
public:
FooButton(wxWindow *parent,
wxWindowID id,
const wxString& label,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = “foobutton”);
~FooButton();
private:
DECLARE_CLASS(FooButton);
};
I use the following Makefile:
WX_CXXFLAGS = -fpic -I/home/romuald/software/wxPython-src-2.9.4.0/include -I/home/romuald/software/wxPython-src-2.9.4.0/wxPython/include -I/home/romuald/software/wxPython-src-2.9.4.0/bld/lib/wx/include/gtk2-unicode-2.9 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES -D__WXGTK__ -DSWIG_TYPE_TABLE=_wxPython_table -pthread
WX_LIBS = -L/usr/local/lib -pthread -L/usr/lib/x86_64-linux-gnu -L/home/romuald/software/wxPython-src-2.9.4.0/bld/lib -lwx_gtk2u_core-2.9 -lwx_baseu-2.9 -lwx_gtk2u_aui-2.9 -lwxcode_gtk2_freechart-2.8
LIBS =py: foobutton.o foobutton_wrap.o
g++ -shared foobutton.o foobutton_wrap.o $(WX_LIBS) $(LIBS) -o _foobutton.sofoobutton.o: foobutton.cpp
g++ -c -o $@ $(WX_CXXFLAGS) foobutton.cppfoobutton_wrap.o: foobutton_wrap.cxx
g++ -c $(WX_CXXFLAGS) -I/usr/include/python2.7 foobutton_wrap.cxxfoobutton_wrap.cxx: foobutton.i
wxswig -c++ -python -Wall -nodefault -python -keyword -new_repr -modern -D__WXGTK__ -I/home/romuald/software/wxPython-src-2.9.4.0/wxPython/src foobutton.i
I would be grateful for any hint what I should change and what is the reason for the fact that the FooButton does not appear.