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

Skip to content

Commit 1c01eab

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 28dd795 commit 1c01eab

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

lib/matplotlib/widgets.py

Lines changed: 22 additions & 13 deletions
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,15 +1558,15 @@ 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

1564-
self._update()
1568+
if self.visible and (self.vertOn or self.horizOn):
1569+
self._update()
15651570

15661571
def _update(self):
15671572
if self.useblit:
@@ -1644,7 +1649,14 @@ def disconnect(self):
16441649
self.canvas.mpl_disconnect(self._cidmotion)
16451650
self.canvas.mpl_disconnect(self._ciddraw)
16461651

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

16491661
def _clear(self, event):
16501662
"""Clear the cursor."""
@@ -1653,8 +1665,6 @@ def _clear(self, event):
16531665
if self.useblit:
16541666
self.background = (
16551667
self.canvas.copy_from_bbox(self.canvas.figure.bbox))
1656-
for line in self.vlines + self.hlines:
1657-
line.set_visible(False)
16581668

16591669
onmove = _api.deprecate_privatize_attribute('3.5')
16601670

@@ -1666,8 +1676,6 @@ def _onmove(self, event):
16661676
if not self.canvas.widgetlock.available(self):
16671677
return
16681678
self.needclear = True
1669-
if not self.visible:
1670-
return
16711679
if self.vertOn:
16721680
for line in self.vlines:
16731681
line.set_xdata((event.xdata, event.xdata))
@@ -1676,7 +1684,8 @@ def _onmove(self, event):
16761684
for line in self.hlines:
16771685
line.set_ydata((event.ydata, event.ydata))
16781686
line.set_visible(self.visible)
1679-
self._update()
1687+
if self.visible and (self.vertOn or self.horizOn):
1688+
self._update()
16801689

16811690
def _update(self):
16821691
if self.useblit:

0 commit comments

Comments
 (0)