From: Kent J. <ke...@td...> - 2004-08-18 15:37:35
|
Mark, This is a limitation of Python - you can't overload methods by parameter type the way you can in Java. For frameUpdate and observerUpdate try this: def frameUpdate(self, g): # Forward to the parent class implementation swing.JFrame.update(self, g) def observerUpdate(self, observable, doc): # Whatever you wanted to put into your original update() goes here print "actionCommand="+doc If you have a lot of classes where you need to do this (inherit from both JFrame and Observable and implement Observable.update()) you could make a mixin class that defines the update() dispatcher, the frameUpdate() forwarding method, and a default implementation of observerUpdate(). Then your Frame/Observable classes could also inherit the mixin and just override observerUpdate() to do what is needed. HTH, Kent > From: Mark Stang <ma...@ma...> > Date: 2004/08/18 Wed AM 09:16:30 EDT > To: Kent Johnson <ke...@td...> > CC: jyt...@li... > Subject: Re: RE: [Jython-users] Where is this coming from > > Kent, > Thanks for the ideas. I will try and implement them. However, I don't > know how to specify "frameupdate" vs "observerupdate". I suppose I > could try JFrame.update and Observer.update in order to call the parent > methods. However, I would expect that Jython would do this. It > appears that it thinks I overrode the parent JFrame update with a local > update and then complained because the parameters don't match. I would > think that it should be able to tell the difference between the two. > Maybe it is a problem with Python. I should try and duplicate the > problem in Python to see if it is a bug in Jython. > > I utilize the Observer Pattern all over my Java code so this is > something that I am going to have to fix in a lot of places or come up > with a new way to do it. > > Thanks! > > Mark > > On Wed, 2004-08-18 at 04:43, Kent Johnson wrote: > > > I would try making update() take an optional third argument. Then use the class of the second argument to figure out which call it is. Something like this: > > import java > > class ClientDesktop(swing.JFrame, Observer): > > def update(self, graphicsOrObservable, doc=None): > > if isinstance(graphicsOrObservable, java.awt.Graphics): > > frameUpdate(self, graphicsOrObservable) > > else: > > observerUpdate(self, graphicsOrObservable, doc) > > > > I don't know if this will work but it's worth a try... > > Kent > > > > > > > > From: Mark Stang <ma...@ma...> > > > Date: 2004/08/18 Wed AM 01:03:48 EDT > > > To: jyt...@li... > > > Subject: RE: [Jython-users] Where is this coming from > > > > > > Any ideas on how to "inform" jython? Or I have to find another way to > > > implement it? > > > > > > And since I have two of them defined with different number of > > > parameters, shouldn't it be able to tell the difference? > > > > > > Thanks, > > > > > > Mark > > > > > > On Tue, 2004-08-17 at 21:31, Jeff Emanuel wrote: > > > > > > > JFrame also defines a method named update. > > > > > > > > void update(Graphics g) > > > > > > > > > > > > Jython can't tell the difference between you overriding JFrame.update > > > > or implementing Observer.update. When JFrame calls update on itself, > > > > Jython thinks that have an overridden update method with the wrong > > > > number of arguments. > > > > > > > > > > > > ________________________________ > > > > > > > > From: jyt...@li... on behalf of Mark Stang > > > > Sent: Tue 8/17/2004 8:12 PM > > > > To: jyt...@li... > > > > Subject: [Jython-users] Where is this coming from > > > > > > > > > > > > Hi, > > > > I have a python class that extends javax.swing.JFrame and java.util.Observer. As part of the Observer implementation I created a "update" method. > > > > > > > > class ClientDesktop(swing.JFrame, Observer): > > > > def __init__(self, title): > > > > swing.JFrame.__init__(self, title=title, size=(200,200)) > > > > > > > > def update(self, observable, doc): > > > > print "actionCommand="+doc > > > > > > > > When I run it: > > > > > > > > if __name__== "__main__": > > > > desktop = ClientDesktop("title") > > > > desktop.visible = 1 > > > > > > > > I get: > > > > Traceback (innermost last): > > > > (no code object) at line 0 > > > > TypeError: update() takes at least 3 arguments (2 given) > > > > > > > > If I remove the update method it runs fine. > > > > > > > > Any thoughts as to where this is coming from? > > > > > > > > Thanks! > > > > > > > > Mark > > > > > > -- > > > Mark Stang <ma...@ma...> > > > > > > > > > > > > > > ------------------------------------------------------- > > SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media > > 100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33 > > Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift. > > http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285 > > _______________________________________________ > > Jython-users mailing list > > Jyt...@li... > > https://lists.sourceforge.net/lists/listinfo/jython-users > > -- > Mark Stang <ma...@ma...> > > |