Skip to content

Commit

Permalink
Remove visibility changes in draw for *Cursor widgets.
Browse files Browse the repository at this point in the history
This can be all handled in the mouse move event handler instead, and
prevents triggering extra draws in nbAgg.

Fixes #19633.
  • Loading branch information
QuLogic committed Apr 7, 2021
1 parent 28dd795 commit 1c01eab
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions lib/matplotlib/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1525,16 +1525,21 @@ def __init__(self, ax, horizOn=True, vertOn=True, useblit=False,
self.background = None
self.needclear = False

clear = _api.deprecate_privatize_attribute('3.5')
@_api.deprecated('3.5')
def clear(self, event):
"""Internal event handler to clear the cursor."""
self._clear(event)
if self.ignore(event):
return
self.linev.set_visible(False)
self.lineh.set_visible(False)

def _clear(self, event):
"""Internal event handler to clear the cursor."""
if self.ignore(event):
return
if self.useblit:
self.background = self.canvas.copy_from_bbox(self.ax.bbox)
self.linev.set_visible(False)
self.lineh.set_visible(False)

onmove = _api.deprecate_privatize_attribute('3.5')

Expand All @@ -1553,15 +1558,15 @@ def _onmove(self, event):
self.needclear = False
return
self.needclear = True
if not self.visible:
return

self.linev.set_xdata((event.xdata, event.xdata))
self.linev.set_visible(self.visible and self.vertOn)

self.lineh.set_ydata((event.ydata, event.ydata))
self.linev.set_visible(self.visible and self.vertOn)
self.lineh.set_visible(self.visible and self.horizOn)

self._update()
if self.visible and (self.vertOn or self.horizOn):
self._update()

def _update(self):
if self.useblit:
Expand Down Expand Up @@ -1644,7 +1649,14 @@ def disconnect(self):
self.canvas.mpl_disconnect(self._cidmotion)
self.canvas.mpl_disconnect(self._ciddraw)

clear = _api.deprecate_privatize_attribute('3.5')
@_api.deprecated('3.5')
def clear(self, event):
"""Clear the cursor."""
if self.ignore(event):
return
self._clear(event)
for line in self.vlines + self.hlines:
line.set_visible(False)

def _clear(self, event):
"""Clear the cursor."""
Expand All @@ -1653,8 +1665,6 @@ def _clear(self, event):
if self.useblit:
self.background = (
self.canvas.copy_from_bbox(self.canvas.figure.bbox))
for line in self.vlines + self.hlines:
line.set_visible(False)

onmove = _api.deprecate_privatize_attribute('3.5')

Expand All @@ -1666,8 +1676,6 @@ def _onmove(self, event):
if not self.canvas.widgetlock.available(self):
return
self.needclear = True
if not self.visible:
return
if self.vertOn:
for line in self.vlines:
line.set_xdata((event.xdata, event.xdata))
Expand All @@ -1676,7 +1684,8 @@ def _onmove(self, event):
for line in self.hlines:
line.set_ydata((event.ydata, event.ydata))
line.set_visible(self.visible)
self._update()
if self.visible and (self.vertOn or self.horizOn):
self._update()

def _update(self):
if self.useblit:
Expand Down

0 comments on commit 1c01eab

Please sign in to comment.