Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
I have been trying to use (abuse?) the observer swig interface to get my
Python objects to be 'Observable', not so simple! In fact, no luck! I thought it would be as simple as defining an Observable class of type 'IsObservable' (all this in the SWIG interface file). The Python class would then inherit from it, initialize itself and the Observable class and VOILA! But alas, after much ranting and raving no luck? Any suggestions? |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
On 2003.11.10 17:23, Andre Louw wrote:
> I have been trying to use (abuse?) the observer swig interface to get > my Python objects to be 'Observable', not so simple! In fact, no > luck! Andre', I'd go for containment instead of inheritance, as the latter does not happily cross the Python/C boundaries. Defining a Python class like: import QuantLib class MyObserver: def __init__(self): self.obs = QuantLib.Observer(self.update) def update(self): print "Override me!" def registerWith(self,o): self.obs.registerWith(o) and inheriting from MyObserver should work, but beware---I didn't test it. As a matter of fact, I didn't even tried to run it through the Python interpreter... Later, Luigi |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
In reply to this post by Andre Louw-2
Luigi,
I probably did not express myself properly. The Observer side works well (even using inheritance), the problem being that Python objects can only observe QuantLib C++ objects (those defined as type 'isObservable' in their SWIG interface files). I'm looking at the other side where a Python object becomes observable by other Python objects. Something in the line of class Foo(Observable): def __init__(self): Observable.__init__(self) def changeMe(self): self.notifyObservers() class FooObserver: def __init__(self): self.obs = QuantLib.Observer(self.update) def update(self): print "Happens when Foo changed" def registerWith(self,o): self.obs.registerWith(o) f = Foo() fo = FooObserver() fo.registerWith(f) f.changeMe() --> should result in an update in FooObserver... Andre |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
On 2003.11.11 06:07, Andre Louw wrote:
> Luigi, > > The Observer side works well (even using inheritance), the problem > being that Python objects can only observe QuantLib C++ objects > (those defined as type 'isObservable' in their SWIG interface files). > I'm looking at the other side where a Python object becomes > observable by other Python objects. > > Something in the line of > > class Foo(Observable): > def __init__(self): > Observable.__init__(self) > def changeMe(self): > self.notifyObservers() ... [show rest of quote] Oh, I see. Hmm, I'll have to give it some thought. Can you file this as a feature request? Later, Luigi |
Free forum by Nabble | Disable Popup Ads | Edit this page |