Ed Leafe wrote:
+ Add code to autoBindEvents() to search not just the form and the
class for matching method signatures, but also all parent containers.
All found method signatures will be bound, even if there's one at the
panel level and one at the form level.
Why containers? How would they have methods if they weren't defined
as classes?
But how does Python know, at runtime, whether a given instance was defined in a
user class definition or just instantiated from a base dabo object, without a
ton of black magic voodoo? Also, people could dynamically add their own methods
to a running instance, making it a (unlikely) possibility. Why not search all
containers, looking for on<Event>_regID() constructs? The searching only happens
once.
There is also one big questionmark: what if you define a button
class, and want to bind Hit to a method? If the button class had an
onHit() method, would that work?
Yes:
class MyButton(dButton):
def onHit(self, evt):
print "hit!"
The callback would fire using the above code.
What if several were dropped on a
form? You couldn't have a RegID-based method, since that ID wouldn't be
determined until the instance was added to the form.
The developer/user determines the RegID, right?
class MyAcceptButton(MyButton):
def onHit(self, evt):
print "accept!"
class MyCancelButton(MyButton):
def onCancel(self, evt):
print "cancel!"
class MyForm(dForm):
def afterInit(self):
self.addObject(MyAcceptButton, RegID="btnAccept")
self.addObject(MyCancelButton, RegID="btnCancel")
def onHit_btnAccept(self, evt):
print "form: accept!"
def onHit_btnCancel(self, evt):
print "form: cancel!"
Whenever I start thinking about this, I keep hearing a voice that
says "Explicit is better than implicit...". ;-)
Me too. Autobinding is definitely on the implicit side, but not completely so.
The user still has to explicitly define the methods.
--
Paul McNett
http://paulmcnett.com
http://dabodev.com
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev