Skip to content

Commit dd119f7

Browse files
committed
Regenerate background when RectangleSelector active-flag is set back on.
Otherwise, if the selector is made inactive and then back to active, the "old" selector gets captured in the background image and spurious appears. No tests because good luck with that, but can be tried with examples/widgets/rectangle_selector.py.
1 parent 7d0cb13 commit dd119f7

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

lib/matplotlib/widgets.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -1456,8 +1456,22 @@ def update_background(self, event):
14561456
"""Force an update of the background."""
14571457
# If you add a call to `ignore` here, you'll want to check edge case:
14581458
# `release` can call a draw event even when `ignore` is True.
1459-
if self.useblit:
1459+
if not self.useblit:
1460+
return
1461+
# Make sure that widget artists don't get accidentally included in the
1462+
# background, by re-rendering the background if needed (and then
1463+
# re-re-rendering the canvas with the visible widget artists).
1464+
needs_redraw = any(artist.get_visible() for artist in self.artists)
1465+
with ExitStack() as stack:
1466+
if needs_redraw:
1467+
for artist in self.artists:
1468+
stack.callback(artist.set_visible, artist.get_visible())
1469+
artist.set_visible(False)
1470+
self.canvas.draw()
14601471
self.background = self.canvas.copy_from_bbox(self.ax.bbox)
1472+
if needs_redraw:
1473+
self.update()
1474+
14611475

14621476
def connect_default_events(self):
14631477
"""Connect the major canvas events to methods."""

0 commit comments

Comments
 (0)