import sys
import matplotlib
import matplotlib.pyplot as plt
print matplotlib.__version__, matplotlib.get_backend()
def hit(event):
sys.stderr.write('hit\n')
fig = plt.figure()
cid0 = fig.canvas.mpl_connect('key_press_event', hit)
cid1 = fig.canvas.mpl_connect('button_press_event', hit)
print cid0, cid1
plt.show()
With the code above, why can't I have both mouse press event and key press events firing hit? It seems in the order above only the key press events work, whereas if I swap the lines 10 and 11 around (order cid0 and cid1 assignment), then only the mouse events work. I.e. whichever one I connected first hogs the event handler. Is this a built in limitation of matplotlib, or am I trying to connect multiple events in the wrong way?
edit with some extra info: My matplotlib.__version__ is 1.1.0. I have tried with GTKAgg and TkAgg backends with the same result. Using python and ipython, with or without -wthread -pylab, ipython qtconsole --pylab=inline, does not make a difference. The connection ids I get are cid0 == cid1 == 6.
edit 2: My problem still remains today with matplotlib version 1.2.x and TkAgg backend, sys.version 2.7.2+ (default, Oct 4 2011, 20:06:09) [GCC 4.6.1]
sys.version,matplotlib.backends.backendand yourmatplotlib.__version__?hit) with2.6.5 (r265:79063, Apr 16 2010, 13:57:41) [GCC 4.4.3], Matplotlib version0.99.1.1andTkAggas default backend.cid0 == cid1, which smells funny. if i usehit_ = lambda x: hit(x)and then connect one of them tohit_instead, i getcid0 != cid1and the event handler is fired for both use-cases as expected. this is the current workaround i will use, but if anyone can get to the root cause of this i would be interested to hear, thanks !