disconnect an event when zoom-to-rectangle gets activated

Hello everyone,

although I thought this topic had been discussed earlier I wasn't able to find
it in the archives. So please forgive me if I'm repeating something. Here the
question I'm not able to answer on my own:

Is there a possibility to disconnect an event when someone wants to use the
zoom-to-rectangle mechanism so that the code which originally would be
executed on the event isn't actually executed as long as the zooming is
activated? To have an example to talk about:

···

############
from pylab import *

def click(event):
    """If the left mouse button is pressed: draw a little square. """
    if event.button==1 and event.inaxes:
        x,y = event.xdata,event.ydata
        plot([x],[y],'rs')
        draw()

plot((arange(100)/99.0)**3)
gca().set_autoscale_on(False)
connect('button_press_event',click)
show()
############

If one runs this script and tries to use the zooming he will always add such a
little red square to the plot. Can this be prevented somehow?

Thanks for your help,
Martin

Hello everyone,

although I thought this topic had been discussed earlier I wasn't able to find
it in the archives. So please forgive me if I'm repeating something. Here the
question I'm not able to answer on my own:

We really shoud wiki more of these email discussions as they come
along. It's so much easier to search there, since things are in some
sort of logical arrangement.

Is there a possibility to disconnect an event when someone wants to use the
zoom-to-rectangle mechanism so that the code which originally would be
executed on the event isn't actually executed as long as the zooming is
activated? To have an example to talk about:

############
from pylab import *

def click(event):
    """If the left mouse button is pressed: draw a little square. """
    if event.button==1 and event.inaxes:
        x,y = event.xdata,event.ydata
        plot([x],[y],'rs')
        draw()

plot((arange(100)/99.0)**3)
gca().set_autoscale_on(False)
connect('button_press_event',click)
show()
############

If one runs this script and tries to use the zooming he will always add such a
little red square to the plot. Can this be prevented somehow?

Yes, first you need to have a reference to your toolbar handy. It took
me a few minutes to work out how to do this with pylab, since I
usually use it in a wxPython frame where the toolbar is explicity
defined, but apparently in pylab you can use :

tb = get_current_fig_manager().toolbar

Then check the mode attribute of the toolbar in your click script:

if tb.mode = "":
  do_stuff
else
  ignore

So your script becomes:

···

On 25/11/06, Martin Richter <lawn.mower@...380...> wrote:

##############
from pylab import *

def click(event):
    """If the left mouse button is pressed: draw a little square. """
    tb = get_current_fig_manager().toolbar
    if event.button==1 and event.inaxes and tb.mode == '':
        x,y = event.xdata,event.ydata
        plot([x],[y],'rs')
        draw()

plot((arange(100)/99.0)**3)
gca().set_autoscale_on(False)
connect('button_press_event',click)
show()
##############

I hope that helps,

Angus.
--
AJC McMorland, PhD Student
Physiology, University of Auckland

Thank you Angus,

this was exactly what I was looking for!

Martin