8000 Add update parameter to clear selector method to make it more generic… · matplotlib/matplotlib@369ea27 · GitHub
[go: up one dir, main page]

Skip to content

Commit 369ea27

Browse files
committed
Add update parameter to clear selector method to make it more generic and simplify code
1 parent f5540f5 commit 369ea27

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

lib/matplotlib/widgets.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2039,11 +2039,22 @@ def get_visible(self):
20392039
property(lambda self: self._visible,
20402040
lambda self, value: setattr(self, "_visible", value)))
20412041

2042-
def clear(self):
2043-
"""Clear the selection and set the selector ready to make a new one."""
2042+
def clear(self, update=True):
2043+
"""
2044+
Clear the selection and set the selector ready to make a new one.
2045+
2046+
Parameters
2047+
----------
2048+
update : bool
2049+
Call the `update` method of the selector to remove the selector
2050+
from the figure. If False, the selector will be removed at the
2051+
next draw.
2052+
2053+
"""
20442054
self._selection_completed = False
20452055
self.set_visible(False)
2046-
self.update()
2056+
if update:
2057+
self.update()
20472058

20482059
@property
20492060
def artists(self):
@@ -3046,12 +3057,10 @@ def _release(self, event):
30463057
# either x or y-direction
30473058
minspanxy = (spanx <= self.minspanx or spany <= self.minspany)
30483059
if (self._drawtype != 'none' and minspanxy):
3049-
for artist in self.artists:
3050-
artist.set_visible(False)
30513060
if self._selection_completed:
30523061
# Call onselect, only when the selection is already existing
30533062
self.onselect(self._eventpress, self._eventrelease)
3054-
self._selection_completed = False
3063+
self.clear(update=False)
30553064
else:
30563065
self.onselect(self._eventpress, self._eventrelease)
30573066
self._selection_completed = True

0 commit comments

Comments
 (0)
0