binding to the frame or the specific instance?

Ok, confused again with this example. From my understanding,
non-CommandEvent events must be bound to the instance itself, not to
the frame. But when I do this:

self.timer.Bind(wx.EVT_TIMER, self.OnTimer)

instead of:

self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer)

it doesn't work. So why does binding to the frame work in this case
and the other way doesn't work?

Thanks,
John

···

On 7/21/06, John Salerno <johnjsal@gmail.com> wrote:

> ---------- Forwarded message ----------
> From: Robin Dunn <robin@alldunn.com>
> To: wxPython-users@lists.wxwidgets.org
> Date: Thu, 20 Jul 2006 17:34:12 -0700
> Subject: Re: [wxPython-users] binding to the frame or the specific instance?
> John Salerno wrote:
> > Can someone explain to me the difference between these two ways of
> > binding a click event:
> >
> > self.Bind(wx.EVT_BUTTON, self.OnClick, self.button)
> >
> > and
> >
> > self.button.Bind(wx.EVT_BUTTON, self.OnClick)
> >
> > Both seem to work, so I assume in some cases it doesn't matter which
> > you use. Did I just get lucky here, or can buttons be done either way?
>
> http://wiki.wxpython.org/index.cgi/self.Bind_vs._self.button.Bind
>
> Yes, I was in a *very* metaphoric mood today. :wink:
>
> --
> Robin Dunn
> Software Craftsman
> http://wxPython.org Java give you jitters? Relax with wxPython!

Thanks very much, that was a big help! I read it in your book already,
but somehow that helped to solidify it a little more. It seems to make
more sense to me to always use self.widget.Bind instead of just
self.Bind, but as you know, there are possible repercussions to this.

John Salerno wrote:

Ok, confused again with this example. From my understanding,
non-CommandEvent events must be bound to the instance itself, not to
the frame. But when I do this:

self.timer.Bind(wx.EVT_TIMER, self.OnTimer)

instead of:

self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer)

it doesn't work. So why does binding to the frame work in this case
and the other way doesn't work?

Because for every rule there is an exception. :wink: Timers don't deliver the events to themselves[*], but to the window that was passed to the wx.Timer constructor or the SetOwner method.

[*] Actually in a way they do if there is no owner set, but instead of processing the event normally they call the Notify method of a derived class. This is done for backwards compatibility with how the timers used to work before they were taught how to send events to windows.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!