From: Brian C. <co...@ey...> - 2009-04-24 18:12:56
|
Oops, need to invoke base class ctor: class SubscriberListener( SessionListener): def __init__(self): SessionListener.__init__(self) -Brian On 4/24/09 7:45 AM, "Christophe Dupre" <chr...@vh...> wrote: Thanks Brian. That seems to work, although I now hit a new hurdle. Here is my new class which inherits from SessionListener. class SubscriberListener( SessionListener): def __init__(self): pass def OnSessionEvent( self, session, msg ): print "hello world" listener = SubscriberListener() session = Session() If I call: session.SetSessionListener(listener) I get the following error: Traceback (most recent call last): File "<pyshell#62>", line 1, in <module> session.SetSessionListener(listener) File "C:\Python26\swig\Examples\python\PubSub\include\vhpubsub\example.py", line 215, in SetSessionListener def SetSessionListener(self, *args): return _example.Session_SetSessionListener(self, *args) TypeError: in method 'Session_SetSessionListener', argument 2 of type 'vhpubsub::SessionListener *' vhpubsub is the namespace from the c++ library. Any idea? Thanks, Christophe From: Brian Cole [mailto:co...@ey...] Sent: 23 April 2009 17:35 To: Miklos Vajna Cc: swi...@li... Subject: Re: [Swig-user] python wrapper to c++ library with abstract classes Python is falling through to the default swig __init__ implementation. You need to specify a constructor in your subclass: class test(SessionListener): i = 9 def __init__(self): pass def f(self): return i You'll probably have to override "OnSessionEvent" as well, but I'm guessing that's what your 'f' method is. -Brian On 4/23/09 9:22 AM, "Miklos Vajna" <vm...@fr...> wrote: On Thu, Apr 23, 2009 at 08:00:48AM -0500, Christophe Dupre <chr...@vh...> wrote: > In the library, the is a class which looks like this: > > class SessionListener > > { > > public: > > virtual ~SessionListener() {} > > virtual void OnSessionEvent(Session* session, const SessionEvent* > event) = 0; // throw() > > > > protected: > > SessionListener() {} > > }; Given that I guess you want to pass the class instance back to the C++ library later, you'll need the director feature. Have you enable it? In the interface file you'll need something like this: ---- %module(directors="1") <your module name> // generate directors for all classes that have virtual methods %feature("director"); ---- No virus found in this incoming message. Checked by AVG - www.avg.com <http://www.avg.com> Version: 8.5.287 / Virus Database: 270.12.3/2075 - Release Date: 04/22/09 17:25:00 |