From: John H. <jdh...@ac...> - 2004-04-16 12:31:25
|
I think now is a good time to start implementing some GUI neutral event handling and wanted to bounce some ideas off the list. The idea is for matplotlib to define its own event handler in matplotlib.events and each of the GUIs trigger these events. Users could register with the event handler using an observer pattern. In user space, you could do something like the following and expect it to work across Tk, Wx and GTK:: import matplotlib.events as events def key_press(event): print event.key events.connect('key_press', key_press) def button_press_press(event): print event.button events.connect('button_press', button_press) Each of the GUIs would call matplotlib.events.notify. The backends would have to map the GUI constants, eg LEFT_BUTTON, to the appropriate matplotlib.event constant and handle things like flip y inversion since the matplotlib coordinate system is 0,0 = lower, left. This would also lay the groundwork for generalizing things like examples/object_picker.py, writing generic measure tools, and so on. You could write a GUI neutral axes resize tool where the user could click on an axes and drag the size. So it would be useful for the users who want to define some GUI interaction and or the developers who want to add features across backends w/o having to know all the widget sets. My questions are * Does this look like a good framework? * Does someone want to implement the interface matplotlib.events? * Do the GUI maintainers for Tk (Todd), Wx (Jeremy) and GTK (Me) have time to do the mapping? If not can we get another volunteer? * What events do we want to define? The ones I use a lot are:: key_press_event key_release_event motion_notify_event button_press_event button_release_event If these basic events are implemented at the backend level, we could catch them and trigger more complicated events like 'drag_rectangle' in matplotlib.events. Ie, catch press, mouse move, and release, and then trigger drag_rectangle with start and end locations in event.start and event.end. * There is the issue of coords. x, y can be given in data, axes (0-1) or data coords. Probably best to give all three event.xdata, event.ydata, event.xaxis, event.yaxis, event.xdisplay, event.ydisplay See examples/coords_demo_gtk.py for an example of connecting to a GTK event and mapping the display coords to data space. Jeremy and Todd, this would be a good example to implement as stage 1 for the event handling. Of course, there is no end to how far you could go with this, defining a basic cross GUI widget API for dialog boxes, entry boxes and so on. A meta-wx, if you will. But that is an issue for another day. JDH |