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

Skip to content

Commit 44405a0

Browse files
QuLogictacaswell
authored andcommitted
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 733fbb0 commit 44405a0

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
@@ -1616,16 +1616,21 @@ def __init__(self, ax, horizOn=True, vertOn=True, useblit=False,
16161616
self.background = None
16171617
self.needclear = False
16181618

1619-
clear = _api.deprecate_privatize_attribute('3.5')
1619+
@_api.deprecated('3.5')
1620+
def clear(self, event):
1621+
"""Internal event handler to clear the cursor."""
1622+
self._clear(event)
1623+
if self.ignore(event):
1624+
return
1625+
self.linev.set_visible(False)
1626+
self.lineh.set_visible(False)
16201627

16211628
def _clear(self, event):
16221629
"""Internal event handler to clear the cursor."""
16231630
if self.ignore(event):
16241631
return
16251632
if self.useblit:
16261633
self.background = self.canvas.copy_from_bbox(self.ax.bbox)
1627-
self.linev.set_visible(False)
1628-
self.lineh.set_visible(False)
16291634

16301635
onmove = _api.deprecate_privatize_attribute('3.5')
16311636

@@ -1644,15 +1649,15 @@ def _onmove(self, event):
16441649
self.needclear = False
16451650
return
16461651
self.needclear = True
1647-
if not self.visible:
1648-
return
1652+
16491653
self.linev.set_xdata((event.xdata, event.xdata))
1654+
self.linev.set_visible(self.visible and self.vertOn)
16501655

16511656
self.lineh.set_ydata((event.ydata, event.ydata))
1652-
self.linev.set_visible(self.visible and self.vertOn)
16531657
self.lineh.set_visible(self.visible and self.horizOn)
16541658

1655-
self._update()
1659+
if self.visible and (self.vertOn or self.horizOn):
1660+
self._update()
16561661

16571662
def _update(self):
16581663
if self.useblit:
@@ -1764,7 +1769,14 @@ def disconnect(self):
17641769
canvas.mpl_disconnect(cid)
17651770
info["cids"].clear()
17661771

1767-
clear = _api.deprecate_privatize_attribute('3.5')
1772+
@_api.deprecated('3.5')
1773+
def clear(self, event):
1774+
"""Clear the cursor."""
1775+
if self.ignore(event):
1776+
return
1777+
self._clear(event)
1778+
for line in self.vlines + self.hlines:
1779+
line.set_visible(False)
17681780

17691781
def _clear(self, event):
17701782
"""Clear the cursor."""
@@ -1773,8 +1785,6 @@ def _clear(self, event):
17731785
if self.useblit:
17741786
for canvas, info in self._canvas_infos.items():
17751787
info["background"] = canvas.copy_from_bbox(canvas.figure.bbox)
1776-
for line in self.vlines + self.hlines:
1777-
line.set_visible(False)
17781788

17791789
onmove = _api.deprecate_privatize_attribute('3.5')
17801790

@@ -1784,8 +1794,6 @@ def _onmove(self, event):
17841794
or not event.canvas.widgetlock.available(self)):
17851795
return
17861796
self.needclear = True
1787-
if not self.visible:
1788-
return
17891797
if self.vertOn:
17901798
for line in self.vlines:
17911799
line.set_xdata((event.xdata, event.xdata))
@@ -1794,7 +1802,8 @@ def _onmove(self, event):
17941802
for line in self.hlines:
17951803
line.set_ydata((event.ydata, event.ydata))
17961804
line.set_visible(self.visible)
1797-
self._update()
1805+
if self.visible and (self.vertOn or self.horizOn):
1806+
self._update()
17981807

17991808
def _update(self):
18001809
if self.useblit:

0 commit comments

Comments
 (0)