From: D-Man <ds...@ri...> - 2001-04-03 19:40:36
|
On Wed, Apr 04, 2001 at 04:24:21AM -0400, cindy wrote: | > | > class Foo : | > def func( self ) : | > print "func was called" | > | > def runme( self ) : | > func() # this won't work as you've seen in your code | > | > def runme2( self ) : | > self.func() # this will work as expected | | This I undertstand, but I don't see how "self" can be used on a | class that is inherited and that is abstract, such as Component. | When I do "self.enableEvents(java.awt.event.WindowEvent.WINDOW_EVENT_MASK)" | I get an AttribueError on enableEvents, which I would expect. | Thanks. | Wayne I see the problem now. The problem lies in enableEvents being protected, and Jython's name mangling of it. First I'll explain a little bit about inheritance, but I'll keep everything 'public' (like in Python). If I make a class, class P : def p_func( self ) : pass and a child class class C( P ) : pass then try this child_object = C() dir( child_object ) I will see p_func as a member of child_object. This is because it is inherited. If the parent class is 'abstract' that only means you can't use 'new' on it. It has no effect on inheritance. So with that knowledge, a class that inherits from java.awt.Component should have a member 'enableEvents'. The problem here is it is 'protected'. In Java that means that only subclasses and classes in the same package can access the function. Other classes can't call it. Apparently jython does some name mangling on protected members by prefixing "super__" to it. (I certainly hope it is mentioned in the documentation, but like a <ahem> genius^H^H^H^H^H^Hidiot I haven't checked ;-)) The following code worked for me : from java.awt import Component , AWTEvent class C( Component ) : def __init__( self ) : self.super__enableEvents( AWTEvent.WINDOW_EVENT_MASK ) I hope this clears up some confusion! As always ask again if you have any more problems. -D |