8000 Add a click_and_move widget test helper by dstansby · Pull Request #21780 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Add a click_and_move widget test helper #21780

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions lib/matplotlib/testing/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,32 @@ def do_event(tool, etype, button=1, xdata=0, ydata=0, key=None, step=1):
event = mock_event(tool.ax, button, xdata, ydata, key, step)
func = getattr(tool, etype)
func(event)


def click_and_drag(tool, start, end, key=None):
"""
Helper to simulate a mouse drag operation.

Parameters
----------
tool : `matplotlib.widgets.Widget`
start : [float, float]
Starting point in data coordinates.
end : [float, float]
End point in data coordinates.
key : None or str
An optional key that is pressed during the whole operation
(see also `.KeyEvent`).
"""
if key is not None:
# Press key
do_event(tool, 'on_key_press', xdata=start[0], ydata=start[1],
button=1, key=key)
# Click, move, and release mouse
do_event(tool, 'press', xdata=start[0], ydata=start[1], button=1)
do_event(tool, 'onmove', xdata=end[0], ydata=end[1], button=1)
do_event(tool, 'release', xdata=end[0], ydata=end[1], button=1)
if key is not None:
# Release key
do_event(tool, 'on_key_release', xdata=end[0], ydata=end[1],
button=1, key=key)
Loading
0