matplotlib/matplotlib — Issue #585: macosx backend ignores multiple mpl_connect() calls
Author: jpterlouw
Created: 2011-11-14 13:25:44+00:00
State: open

When I try to connect more than one event type to one handler function, with the macosx backend only the first one has effect and subsequent connects are ignored. Other backends (Qt4, GTK) don't have this behaviour. Example:

from matplotlib.pyplot import figure, show
def handler(event): print event.name
fig = figure()
ax = fig.add_subplot(111)
fig.canvas.mpl_connect('key_press_event', handler)
fig.canvas.mpl_connect('motion_notify_event', handler)
show()

Here only keypress events are reported by the handler function. When I reverse the mpl_connect() calls, only motion events are reported.

When I use a separate handler function for every event type, then all events are reported:

from matplotlib.pyplot import figure, show
def handler(event): print event.name
def handler2(event): print event.name
fig = figure()
ax = fig.add_subplot(111)
fig.canvas.mpl_connect('motion_notify_event', handler)
fig.canvas.mpl_connect('key_press_event', handler2)
show()

I found out about this when one of our users reported that keypresses were not handled properly under Mac OSX in a piece of software that I maintain.

Thanks, Hans