Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 96f6c90

Browse files
committed
Simplify reset _selection_completed after clearing selector and fix it for all selector
1 parent 2d5ca2a commit 96f6c90

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

lib/matplotlib/tests/test_widgets.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,13 +460,18 @@ def onselect(epress, erelease):
460460
assert artist.get_alpha() == 0.3
461461

462462

463-
def test_span_selector_clear():
463+
@pytest.mark.parametrize('selector', ['span', 'rectangle'])
464+
def test_selector_clear(selector):
464465
ax = get_ax()
465466

466467
def onselect(*args):
467468
pass
468469

469-
tool = widgets.SpanSelector(ax, onselect, 'horizontal', interactive=True)
470+
if selector == 'span':
471+
tool = widgets.SpanSelector(ax, onselect, 'horizontal',
472+
interactive=True)
473+
else:
474+
tool = widgets.RectangleSelector(ax, onselect, interactive=True)
470475
do_event(tool, 'press', xdata=10, ydata=10, button=1)
471476
do_event(tool, 'onmove', xdata=100, ydata=120, button=1)
472477
do_event(tool, 'release', xdata=100, ydata=120, button=1)
@@ -486,7 +491,6 @@ def onselect(*args):
486491
do_event(tool, 'press', xdata=130, ydata=130, button=1)
487492
do_event(tool, 'release', xdata=130, ydata=130, button=1)
488493
assert tool._selection_completed
489-
assert tool.extents == (10, 100)
490494

491495
do_event(tool, 'on_key_press', key='escape')
492496
assert not tool._selection_completed

lib/matplotlib/widgets.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1978,9 +1978,11 @@ def on_key_press(self, event):
19781978
key = event.key or ''
19791979
key = key.replace('ctrl', 'control')
19801980
if key == self.state_modifier_keys['clear']:
1981+
self._selection_completed = False
19811982
for artist in self.artists:
19821983
artist.set_visible(False)
19831984
self.update()
1985+
return
19841986
for (state, modifier) in self.state_modifier_keys.items():
19851987
if modifier in key:
19861988
self._state.add(state)
@@ -2315,11 +2317,6 @@ def direction(self, direction):
23152317
else:
23162318
self._direction = direction
23172319

2318-
def _on_key_press(self, event):
2319-
key = event.key or ''
2320-
if key == self.state_modifier_keys['clear']:
2321-
self._selection_completed = False
2322-
23232320
def _release(self, event):
23242321
"""Button release event handler."""
23252322
self._set_cursor(False)

0 commit comments

Comments
 (0)