88
99from unittest import mock
1010
11+ from matplotlib import _api
12+ from matplotlib .backend_bases import MouseEvent , KeyEvent
1113import matplotlib .pyplot as plt
1214
1315
@@ -24,6 +26,7 @@ def noop(*args, **kwargs):
2426 pass
2527
2628
29+ @_api .deprecated ("3.11" , alternative = "MouseEvent or KeyEvent" )
2730def mock_event (ax , button = 1 , xdata = 0 , ydata = 0 , key = None , step = 1 ):
2831 r"""
2932 Create a mock event that can stand in for `.Event` and its subclasses.
@@ -65,6 +68,7 @@ def mock_event(ax, button=1, xdata=0, ydata=0, key=None, step=1):
6568 return event
6669
6770
71+ @_api .deprecated ("3.11" , alternative = "callbacks.process(event)" )
6872def do_event (tool , etype , button = 1 , xdata = 0 , ydata = 0 , key = None , step = 1 ):
6973 """
7074 Trigger an event on the given tool.
@@ -105,15 +109,12 @@ def click_and_drag(tool, start, end, key=None):
105109 An optional key that is pressed during the whole operation
106110 (see also `.KeyEvent`).
107111 """
108- if key is not None :
109- # Press key
110- do_event (tool , 'on_key_press' , xdata = start [0 ], ydata = start [1 ],
111- button = 1 , key = key )
112+ ax = tool .ax
113+ if key is not None : # Press key
114+ KeyEvent ._from_ax_coords ("key_press_event" , ax , start , key )._process ()
112115 # Click, move, and release mouse
113- do_event (tool , 'press' , xdata = start [0 ], ydata = start [1 ], button = 1 )
114- do_event (tool , 'onmove' , xdata = end [0 ], ydata = end [1 ], button = 1 )
115- do_event (tool , 'release' , xdata = end [0 ], ydata = end [1 ], button = 1 )
116- if key is not None :
117- # Release key
118- do_event (tool , 'on_key_release' , xdata = end [0 ], ydata = end [1 ],
119- button = 1 , key = key )
116+ MouseEvent ._from_ax_coords ("button_press_event" , ax , start , 1 )._process ()
117+ MouseEvent ._from_ax_coords ("motion_notify_event" , ax , end , 1 )._process ()
118+ MouseEvent ._from_ax_coords ("button_release_event" , ax , end , 1 )._process ()
119+ if key is not None : # Release key
120+ KeyEvent ._from_ax_coords ("key_release_event" , ax , end , key )._process ()
0 commit comments