EVT Tutotial

[snip event autobinding stuff...]

class MyForm(dabo.ui.dForm):
  def afterInit(self):
    self.addObject(dabo.ui.dButton, Caption="Hit me",
        RegID="mybutton")
  def onHit_mybutton(self, evt):
    print "the button was pushed"

Be careful there. Needing to pass a quoted string, which ultimately
references a bound method of a slightly different name, is a bit of a
kludge. I can't really offer up a better solution other than passing
the bound method itself (self.onHit_mybutton), but I would imagine that
is also less than desireable for some.

- Josiah

···

Paul McNett <p@ulmcnett.com> wrote:

This is essentially what the VB6 IDE does. Once you've named a control, you "bind" an event handler by defining a method like "foo_OnClick"; I've always found that a bit kludgey, but it does work. You can get into trouble, though, if you rename the control after defining a few of these methods.

     As I mentioned in another reply, RegID is special, and has additional constraints. It is somewhat like a name, but more like a design contract. It is no different than if you were to bind to a particular method and then later go back and change the name of the method - you've broken the binding.

Freewheeling a bit: in effect, what you're doing is implicitly folding the binding of of events for an object into the addObject call. Why not make that explicit? Maybe something like

        self.addObject(dabo.ui.dButton, Caption="Hit me",
                       onHit=functionObject1,
                       onMouseOver=functionObject2)

This decouples event binding from widget naming, which is probably a Good Thing.

     I like that idea. It would take a bit of work to implement, but it certainly is clean and Pythonic.

  You could follow this up by allowing dynamic changing of bindings through something like

   aWidget.EventBindings(onThis=thisHandler, onThat=None, ...)

(The "None" says "unbind the event".)

     Objects have bindEvent() and unbindEvent() methods that accomplish this.

-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com

···

On Jan 23, 2006, at 8:10 PM, Don Dwiggins wrote: