GUI neutral event handling has been a thorn in my side, trying to deal
with flakiness in some GUIs that don't properly handle multiple
connects and disconnects (yes tk and wx, I'm lookin' at you), and so
it has been partially implemented and partially broken on these
When I went to add key press event handling, I confronted these same
issues again and this time tackled them head on.
Now the FigureCanvasBase does all the connection and disconnection
handling by keeping a dictionary of callbacks. The backends no longer
need to implement mpl_connect or mpl_disconnect, as this is handled
entirely by the base class. Neither do they need to know about
MPLEvent (which no longer exists). This class has been factored into
a base class Event and two derived classes MouseEvent and KeyEvent.
The attributes are the same so it will be transparent to the user.
All the backend has to do is call, for example
FigureCanvasBase.button_release_event(self, x, y, self._button, self._key)
on every button release event and the base class will do the rest
(figure out data coords, whether you are over an axes, init the right
Event, and fire off the callbacks, handling multiple connects and
disconnects properly -- eg examples/coords_demo.py with and without
test_disconnect works on tk, wx and gtk.
The backend code is simpler too, and we now have GUI neutral key press
event handling too -- see examples/keypress_demo.py.
I ported these changes to WX, GTK and Tk and committed them. Gregory,
I still haven't gotten FLTK up and running, so I didn't try to port
these changes to FLTK, but I suspect it will be an easy for you. Give
it a whirl and let me know.
The backends need to call the FigureCanvasBase methods, with the args
as described in the docstrings of those methods: key_press_event,
button_press_event, button_release_event, motion_notify_event.
Now I feel better,