Skip to content

Commit 5638ee7

Browse files
committed
Remove visibility changes in draw for *Cursor widgets.
This can be all handled in the mouse move event handler instead, and prevents triggering extra draws in nbAgg. Fixes #19633.
1 parent a42f4ac commit 5638ee7

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

lib/matplotlib/widgets.py

+18-11
Original file line numberDiff line numberDiff line change
@@ -1525,16 +1525,21 @@ def __init__(self, ax, horizOn=True, vertOn=True, useblit=False,
15251525
self.background = None
15261526
self.needclear = False
15271527

1528-
clear = _api.deprecate_privatize_attribute('3.5')
1528+
@_api.deprecated('3.5')
1529+
def clear(self, event):
1530+
"""Internal event handler to clear the cursor."""
1531+
self._clear(event)
1532+
if self.ignore(event):
1533+
return
1534+
self.linev.set_visible(False)
1535+
self.lineh.set_visible(False)
15291536

15301537
def _clear(self, event):
15311538
"""Internal event handler to clear the cursor."""
15321539
if self.ignore(event):
15331540
return
15341541
if self.useblit:
15351542
self.background = self.canvas.copy_from_bbox(self.ax.bbox)
1536-
self.linev.set_visible(False)
1537-
self.lineh.set_visible(False)
15381543

15391544
onmove = _api.deprecate_privatize_attribute('3.5')
15401545

@@ -1553,12 +1558,11 @@ def _onmove(self, event):
15531558
self.needclear = False
15541559
return
15551560
self.needclear = True
1556-
if not self.visible:
1557-
return
1561+
15581562
self.linev.set_xdata((event.xdata, event.xdata))
1563+
self.linev.set_visible(self.visible and self.vertOn)
15591564

15601565
self.lineh.set_ydata((event.ydata, event.ydata))
1561-
self.linev.set_visible(self.visible and self.vertOn)
15621566
self.lineh.set_visible(self.visible and self.horizOn)
15631567

15641568
self._update()
@@ -1644,7 +1648,14 @@ def disconnect(self):
16441648
self.canvas.mpl_disconnect(self._cidmotion)
16451649
self.canvas.mpl_disconnect(self._ciddraw)
16461650

1647-
clear = _api.deprecate_privatize_attribute('3.5')
1651+
@_api.deprecated('3.5')
1652+
def clear(self, event):
1653+
"""Clear the cursor."""
1654+
if self.ignore(event):
1655+
return
1656+
self._clear(event)
1657+
for line in self.vlines + self.hlines:
1658+
line.set_visible(False)
16481659

16491660
def _clear(self, event):
16501661
"""Clear the cursor."""
@@ -1653,8 +1664,6 @@ def _clear(self, event):
16531664
if self.useblit:
16541665
self.background = (
16551666
self.canvas.copy_from_bbox(self.canvas.figure.bbox))
1656-
for line in self.vlines + self.hlines:
1657-
line.set_visible(False)
16581667

16591668
onmove = _api.deprecate_privatize_attribute('3.5')
16601669

@@ -1666,8 +1675,6 @@ def _onmove(self, event):
16661675
if not self.canvas.widgetlock.available(self):
16671676
return
16681677
self.needclear = True
1669-
if not self.visible:
1670-
return
16711678
if self.vertOn:
16721679
for line in self.vlines:
16731680
line.set_xdata((event.xdata, event.xdata))

0 commit comments

Comments
 (0)