Re: embedding, getargs/mkvalue asymmetry

Dianne Hackborn (hackbod@newt.CS.ORST.EDU)
15 Feb 1995 07:39:09 GMT

Hark! The herald "Hammond, Mark" <MHammond@jm.cmutual.com.au> posts:
| I too have worked extensively with Python in a GUI. I have exactly the same
| issues.
|
| My approach is thus:
| * Python code "registers" an event. Registry consists of the event itself
| (eg, the message) and a Python function object.
| * C++ code calls "call_object()" on the object itself.
...

This is something I am going to be doing -- haven't yet, so take this all
with a grain of salt -- and my current plan is to have the GUI objects
available to the Python program as complete classes, which it can then make
subclasses of, to overide any of the default member functions. I feel like
this is the "natural" approach for an OO language to take.

Of course, while this should work fine when the script is creating its own
objects, it's not quite as easy if the application is making the objects
which the script would then want to overide afterwards. Right now, I'm
thinking of either supplying some object.subclass() function through which
you hand in your new subclass to an already created object, at which point
the two objects would be combined and replace the current object, or if
possible finding some way that the script can get its subclasses to the
application in time for them to be used.

Actually, now that I think about it, the first approach is... interesting.
It basically follows how Python classes are built, right? Just stick a new
instance symbol table at the front of the search tree, and you have a
subclass. There could be a problem with updating all references to the
instance, but if nothing else I'd imagine it would work well to have a
wrapper class that is "the instance" to everyone using it, and thus holds
the only link to the actual instance. It would then be the one responsible
for "dynamic subclassing" of its instance. Hmmmmm...

To make this more concrete, imagine you have a text editor, and each file
being edited is a class. You currently have one file being edited,
"File1", which is a wrapper around the instance of class "TextEdit" for
this file. Now your program wants to overide some methods in it:

class myEdit:
def endSession(x):
print 'I won't let you!'
return False

And insert itself into that current TextEdit instance:

File1.subclass(myEdit())

And now "File1.endSession("dummy")" will always call your new method.

Does this make sense? Does it seem like something reasonable to do, for
both the script writer and how Python works? The only real question I can
think of off-hand is how how member functions in old instances will react;
they probably won't start searching for attributes at the new subclass,
will they? [Or actually, 'self' probably -always- points to the
lowest-level subclass, right? Then it should work. Maybe. :)]

------------------------------------------------------------------------------
Dianne Kyra Hackborn "Pat Buchannan is so homophobic he blames global
hackbod@mail.cs.orst.edu warming on the AIDS quilt."
Oregon State University -- Dennis Miller
//www.cs.orst.edu/~hackbod/