Unbinding events

Hello,

how do I unbind a specific event handler for an event?

Suppose I do something like

window.Bind( wx.EVT_MOTION, self.onMotion )
window.Bind( wx.EVT_MOTION, self.onMotion2 )

How do I unbind *specifically* the second bind?

I tried various forms of Unbind() and Disconnect() and PyEventBinder() but
they only seem to work on wx.EVT_MOTION. My preferred way of doing this
would be something like

myEvt = window.Bind( wx.EVT_MOTION, self.onMotion )
myEvt2 = window.Bind( wx.EVT_MOTION, self.onMotion2 )
myEvt2.Disconnect()

In reality I don't know about the first Bind, since a user of fc2 has done
it in his application code. This messes up my current unbind code since
the unbind code now unbinds his event handler rather than mine.

I am on '2.8.8.1 (msw-unicode)'. Will an upgrade help here?

-Matthias

Try something like:

window.Bind( wx.EVT_MOTION, None )

Although I'm a little confused why you're binding to the same event
twice. Why not just do everything in one handler?

-Kyle Rickey

···

-----Original Message-----
From: wxpython-users-bounces@lists.wxwidgets.org
[mailto:wxpython-users-bounces@lists.wxwidgets.org] On Behalf Of Nitro
Sent: Tuesday, November 18, 2008 9:01 AM
To: wxPython-users@lists.wxwidgets.org
Subject: [wxpython-users] Unbinding events

Hello,

how do I unbind a specific event handler for an event?

Suppose I do something like

window.Bind( wx.EVT_MOTION, self.onMotion )
window.Bind( wx.EVT_MOTION, self.onMotion2 )

How do I unbind *specifically* the second bind?

I tried various forms of Unbind() and Disconnect() and PyEventBinder()
but
they only seem to work on wx.EVT_MOTION. My preferred way of doing this
would be something like

myEvt = window.Bind( wx.EVT_MOTION, self.onMotion )
myEvt2 = window.Bind( wx.EVT_MOTION, self.onMotion2 )
myEvt2.Disconnect()

In reality I don't know about the first Bind, since a user of fc2 has
done
it in his application code. This messes up my current unbind code since
the unbind code now unbinds his event handler rather than mine.

I am on '2.8.8.1 (msw-unicode)'. Will an upgrade help here?

-Matthias
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Nitro wrote:

Hello,

how do I unbind a specific event handler for an event?

Suppose I do something like

window.Bind( wx.EVT_MOTION, self.onMotion )
window.Bind( wx.EVT_MOTION, self.onMotion2 )

How do I unbind *specifically* the second bind?

I tried various forms of Unbind() and Disconnect() and PyEventBinder() but
they only seem to work on wx.EVT_MOTION. My preferred way of doing this
would be something like

myEvt = window.Bind( wx.EVT_MOTION, self.onMotion )
myEvt2 = window.Bind( wx.EVT_MOTION, self.onMotion2 )
myEvt2.Disconnect()

In reality I don't know about the first Bind, since a user of fc2 has done
it in his application code. This messes up my current unbind code since
the unbind code now unbinds his event handler rather than mine.

Currently there is no way to do this. It's a good idea however so I've added an item on my ToDo list to investigate the possibility.

···

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

Nitro wrote:

In reality I don't know about the first Bind, since a user of fc2 has done
it in his application code. This messes up my current unbind code since
the unbind code now unbinds his event handler rather than mine.

I think the answer may have to be: Don't do that!

It's probably better for FC users to only bind the FC events. I don't think there is any reason you'd have to bind the regular events -- let FC take care of that.

I'm not sure you've done it the same way for FC2, but for FC1, when you do:

Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMotion)

you get en event that is just like the regular EVT_MOTION, but with and addition attribute for the world coordinates, so it can be used the same way.

I wonder if there is a way to prevent folks from binding the regular events on the Canvas? As it is, it would be an easy mistake to make.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov