Hi,
I have a patch which implements the scroll wheel on wx using the
wx mouse wheel event.
Rather than a simple up/down mouse event wx uses:
delta: intervals per click
rotation: number of clicks
rate: number of lines per click
I convert this to:
step = rotation*delta/rate
I've added the step attribute to the mpl MouseEvent in addition to the
usual up/down button (up if step >= 0, down otherwise).
I removed the mpl_connect from the scroll event to pick. I don't know
why it was there.
I tested the patch on OS X WxAgg examples/image_slice_viewer.
Let me know if it is okay to post to svn, or if we are still in feature
freeze.
- Paul
Index: backend_bases.py
===================================================================
--- backend_bases.py (revision 4699)
+++ backend_bases.py (working copy)
@@ -776,6 +776,7 @@
inaxes = None # the Axes instance if mouse us over axes
xdata = None # x coord of mouse in data coords
ydata = None # y coord of mouse in data coords
+ step = None # for scroll events, the number of steps
"""
x = None # x position - pixels from left of canvas
@@ -784,9 +785,10 @@
inaxes = None # the Axes instance if mouse us over axes
xdata = None # x coord of mouse in data coords
ydata = None # y coord of mouse in data coords
+ step = None # for scroll events, the number of steps
def __init__(self, name, canvas, x, y, button=None, key=None,
- guiEvent=None):
+ step=None, guiEvent=None):
"""
x, y in figure coords, 0,0 = bottom, left
button pressed None, 1, 2, 3
@@ -794,6 +796,7 @@
LocationEvent.__init__(self, name, canvas, x, y, guiEvent=guiEvent)
self.button = button
self.key = key
+ self.step = step
class PickEvent(Event):
"""
@@ -872,7 +875,7 @@
self._key = None # the key pressed
self._lastx, self._lasty = None, None
self.button_pick_id = self.mpl_connect('button_press_event',self.pick)
- self.scroll_pick_id = self.mpl_connect('scroll_event',self.pick)
+ #self.scroll_pick_id = self.mpl_connect('scroll_event',self.pick)
if False:
## highlight the artists that are hit
@@ -1001,15 +1004,17 @@
event = PickEvent(s, self, mouseevent, artist, **kwargs)
self.callbacks.process(s, event)
- def scroll_event(self, x, y, button, guiEvent=None):
+ def scroll_event(self, x, y, step, guiEvent=None):
"""
Backend derived classes should call this function on any
scroll wheel event. x,y are the canvas coords: 0,0 is lower,
left. button and key are as defined in MouseEvent
"""
+ button = 'up' if step >= 0 else 'down'
self._button = button
s = 'scroll_event'
- mouseevent = MouseEvent(s, self, x, y, button, self._key,
guiEvent=guiEvent)
+ mouseevent = MouseEvent(s, self, x, y, button, self._key,
+ step=step, guiEvent=guiEvent)
self.callbacks.process(s, mouseevent)
Index: backends/backend_gtk.py
===================================================================
--- backends/backend_gtk.py (revision 4699)
+++ backends/backend_gtk.py (working copy)
@@ -179,10 +179,10 @@
# flipy so y=0 is bottom of canvas
y = self.allocation.height - event.y
if event.direction==gdk.SCROLL_UP:
- direction = 'up'
+ step = 1
else:
- direction = 'down'
- FigureCanvasBase.scroll_event(self, x, y, direction)
+ step = -1
+ FigureCanvasBase.scroll_event(self, x, y, step)
return False # finish event propagation?
def button_press_event(self, widget, event):
Index: backends/backend_wx.py
===================================================================
--- backends/backend_wx.py (revision 4699)
+++ backends/backend_wx.py (working copy)
@@ -1174,9 +1174,23 @@
FigureCanvasBase.button_release_event(self, x, y, 1, guiEvent=evt)
def _onMouseWheel(self, evt):
- # TODO: implement mouse wheel handler
- pass
+ """Translate mouse wheel events into matplotlib events"""
+ # Determine mouse location
+ x = evt.GetX()
+ y = self.figure.bbox.height() - evt.GetY()
+ # Convert delta/rotation/rate into a floating point step size
+ delta = evt.GetWheelDelta()
+ rotation = evt.GetWheelRotation()
+ rate = evt.GetLinesPerAction()
+ #print "delta,rotation,rate",delta,rotation,rate
+ step = rate*float(rotation)/delta
+
+ # Convert to mpl event
+ # Note: If Skip(True) then OS X generates two events per click
+ evt.Skip(False)
+ self.scroll_event(x, y, step, guiEvent=evt)
+
def _onMotion(self, evt):
"""Start measuring on an axis."""
-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel