@@ -83,3 +83,32 @@ def do_event(tool, etype, button=1, xdata=0, ydata=0, key=None, step=1):
8383 event = mock_event (tool .ax , button , xdata , ydata , key , step )
8484 func = getattr (tool , etype )
8585 func (event )
86+
87+
88+ def click_and_drag (tool , start , end , key = None ):
89+ """
90+ Helper to simulate a mouse drag operation.
91+
92+ Parameters
93+ ----------
94+ tool : `matplotlib.widgets.Widget`
95+ start : [float, float]
96+ Starting point in data coordinates.
97+ end : [float, float]
98+ End point in data coordinates.
99+ key : None or str
100+ An optional key that is pressed during the whole operation
101+ (see also `.KeyEvent`).
102+ """
103+ if key is not None :
104+ # Press key
105+ do_event (tool , 'on_key_press' , xdata = start [0 ], ydata = start [1 ],
106+ button = 1 , key = key )
107+ # Click, move, and release mouse
108+ do_event (tool , 'press' , xdata = start [0 ], ydata = start [1 ], button = 1 )
109+ do_event (tool , 'onmove' , xdata = end [0 ], ydata = end [1 ], button = 1 )
110+ do_event (tool , 'release' , xdata = end [0 ], ydata = end [1 ], button = 1 )
111+ if key is not None :
112+ # Release key
113+ do_event (tool , 'on_key_release' , xdata = end [0 ], ydata = end [1 ],
114+ button = 1 , key = key )
0 commit comments