|
1 |
| -from types import SimpleNamespace |
<
8000
td data-grid-cell-id="diff-49bef07a6ad7921c1aedc5b8786e8f86f5cd96ac5bb639b6d431f9d2b07d784c-2-0-0" data-selected="false" role="gridcell" style="background-color:var(--diffBlob-deletionNum-bgColor, var(--diffBlob-deletion-bgColor-num));text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative left-side">2
| - |
3 | 1 | import matplotlib.widgets as widgets
|
4 | 2 | import matplotlib.pyplot as plt
|
5 | 3 | from matplotlib.testing.decorators import image_comparison
|
| 4 | +from matplotlib.testing.widgets import do_event, get_ax |
6 | 5 |
|
7 | 6 | from numpy.testing import assert_allclose
|
8 | 7 |
|
9 | 8 | import pytest
|
10 | 9 |
|
11 | 10 |
|
12 |
| -def get_ax(): |
13 |
| - fig, ax = plt.subplots(1, 1) |
14 |
| - ax.plot([0, 200], [0, 200]) |
15 |
| - ax.set_aspect(1.0) |
16 |
| - ax.figure.canvas.draw() |
17 |
| - return ax |
18 |
| - |
19 |
| - |
20 |
| -def do_event(tool, etype, button=1, xdata=0, ydata=0, key=None, step=1): |
21 |
| - """ |
22 |
| - *name* |
23 |
| -<
8000
span class=pl-s> the event name |
24 |
| -
|
25 |
| - *canvas* |
26 |
| - the FigureCanvas instance generating the event |
27 |
| -
|
28 |
| - *guiEvent* |
29 |
| - the GUI event that triggered the matplotlib event |
30 |
| -
|
31 |
| - *x* |
32 |
| - x position - pixels from left of canvas |
33 |
| -
|
34 |
| - *y* |
35 |
| - y position - pixels from bottom of canvas |
36 |
| -
|
37 |
| - *inaxes* |
38 |
| - the :class:`~matplotlib.axes.Axes` instance if mouse is over axes |
39 |
| -
|
40 |
| - *xdata* |
41 |
| - x coord of mouse in data coords |
42 |
| -
|
43 |
| - *ydata* |
44 |
| - y coord of mouse in data coords |
45 |
| -
|
46 |
| - *button* |
47 |
| - button pressed None, 1, 2, 3, 'up', 'down' (up and down are used |
48 |
| - for scroll events) |
49 |
| -
|
50 |
| - *key* |
51 |
| - the key depressed when the mouse event triggered (see |
52 |
| - :class:`KeyEvent`) |
53 |
| -
|
54 |
| - *step* |
55 |
| - number of scroll steps (positive for 'up', negative for 'down') |
56 |
| - """ |
57 |
| - event = SimpleNamespace() |
58 |
| - event.button = button |
59 |
| - ax = tool.ax |
60 |
| - event.x, event.y = ax.transData.transform([(xdata, ydata), |
61 |
| - (xdata, ydata)])[00] |
62 |
| - event.xdata, event.ydata = xdata, ydata |
63 |
| - event.inaxes = ax |
64 |
| - event.canvas = ax.figure.canvas |
65 |
| - event.key = key |
66 |
| - event.step = step |
67 |
| - event.guiEvent = None |
68 |
| - event.name = 'Custom' |
69 |
| - |
70 |
| - func = getattr(tool, etype) |
71 |
| - func(event) |
72 |
| - |
73 |
| - |
74 | 11 | def check_rectangle(**kwargs):
|
75 | 12 | ax = get_ax()
|
76 | 13 |
|
|
0 commit comments