Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5aa85d6

Browse filesBrowse files
committed
Add test_and_drag widget test helper
1 parent 6e15597 commit 5aa85d6
Copy full SHA for 5aa85d6

File tree

2 files changed

+107
-160
lines changed
Filter options

2 files changed

+107
-160
lines changed

‎lib/matplotlib/testing/widgets.py

Copy file name to clipboardExpand all lines: lib/matplotlib/testing/widgets.py
+29Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.