Updated for PythonCard 0.8.2 and later on 2007-06-26

Subject: [Pythoncard-users] addMethod, dynamic method binding

I made an addition to the Scriptable class in model.py so that we can add
methods during runtime. It uses 'instanceMethod' from the 'new' module. The
following interaction in the shell shows how this can be used. Startup
minimal.py with the shell and type the following lines to add a button with
a mouseClick handler.

>>> def on_btn1_mouseClick(self, event):
... 	self.components.field1.text = event.target.name
...
>>> self.addMethod(on_btn1_mouseClick)
>>> comp['btn1'] = {'type':'Button', 'name':'btn1', 'position':(0, 30), 'label':'btn1 hello'}

This simplifies creating PythonCard UIs on the fly. The more important
reason for making this addition is to bring us closer to runtime editing of
scripts.

It is critical that you call addMethod prior to creating your component so
that the automatic event binding works correctly.