Extending wxPython

Hi. I’m trying to compile and run a toy example of a class extending

wx.Frame, using SWIG. The interface file is straightforward:

%module(package=“xxx”) MMM

%{

#include “python_wrap.h”

#include “wx/wxPython/wxPython.h”

#include"wx/wxPython/pyclasses.h"

#include#wx/listctrl.h”

%}

%import core.i

%import controls.i

%import windows.i

class mmmFrame: public wxFrame{

public:

MMMFrame(const wxString& title = _T("default"));

};

The SWIG generation and compilation work fine, but when I run a simple

python test using the new class, I get:

for _s in [wx._windows.Frame]: swig_setmethods.update(_s.swig_setmethods)
AttributeError: type object ‘Frame’ has no attribute ‘swig_setmethods

Indeed, SWIG generates the following code:

class MMMFrame(wx._windows.Frame):

"""Proxy of C++ MMMFrame class"""
__swig_setmethods__ = {}
for _s in [wx._windows.Frame]: __swig_setmethods__.update(_s.__swig_setmethods__)
__setattr__ = lambda self, name, value: _swig_setattr(self, MMMFrame, name, value)
__swig_getmethods__ = {}
for _s in [wx._windows.Frame]: __swig_getmethods__.update(_s.__swig_getmethods__)
__getattr__ = lambda self, name: _swig_getattr(self, MMMFrame, name)
__repr__ = _swig_repr
def __init__(self, *args, **kwargs)......

whereas what SWIG generates in Robin’s sources is more like:

class GridCellWorker(object):
“”“Proxy of C++ GridCellWorker class”""
thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc=‘The membership flag’)
def init(self): raise AttributeError, “No constructor defined”…

Where does the discrepancy come from? Note that I’m using Robin’s patched version

of SWIG.

Thanks for your help.

-Martin

Martin Trudeau wrote:

Hi. I'm trying to compile and run a toy example of a class extending
wx.Frame, using SWIG. The interface file is straightforward:
%module(package="xxx") MMM
%{
#include "python_wrap.h"
#include "wx/wxPython/wxPython.h"
#include"wx/wxPython/pyclasses.h"
#include "#wx/listctrl.h"
%}
%import core.i
%import controls.i
%import windows.i
class mmmFrame: public wxFrame{
public:
    MMMFrame(const wxString& title = _T("default"));
};

Is the case on the class name and the constructor name correct? They should be the same.

Where does the discrepancy come from? Note that I'm using Robin's patched version
of SWIG.

Which version? Also, which version of wxPython are you trying to be compatible with?

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Where does the discrepancy come from? Note that I'm using Robin's patched version
of SWIG.

Which version? Also, which version of wxPython are you trying to be compatible with?

I downloaded a version of wxPython last week from CVS. And I am
using the patched version of SWIG (1.3.29) that came with it.

Anyway, I solved my problem. I dug up from config.py the SWIG flag
I needed to make my generated python class compatible with wxPython,
namely '-modern'. This should be said explicitly in
$wxPython\docs\MigrationGuide.html and http://www.wxpython.org/migrationguide.php,
perhaps also mentioning the '-new_repr' flag as well. Too bad these are not mentioned
in SWIG's doc.

Thanks for your time.

-Martin

Martin Trudeau wrote:

Where does the discrepancy come from? Note that I'm using Robin's patched version
of SWIG.

Which version? Also, which version of wxPython are you trying to be compatible with?

I downloaded a version of wxPython last week from CVS. And I am
using the patched version of SWIG (1.3.29) that came with it.

Anyway, I solved my problem. I dug up from config.py the SWIG flag
I needed to make my generated python class compatible with wxPython,
namely '-modern'. This should be said explicitly in
$wxPython\docs\MigrationGuide.html and http://www.wxpython.org/migrationguide.php,
perhaps also mentioning the '-new_repr' flag as well.

If you use wx.build.config from your setup.py then you can get the flags used to run SWIG and also a bunch of other settings used by wxPython's setup.py.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!