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

Skip to content

Commit c1588e6

Browse files
authored
Merge pull request #19763 from QuLogic/widget-events
Remove visibility changes in draw for *Cursor widgets
2 parents eb92923 + 44405a0 commit c1588e6

File tree

3 files changed

+41
-19
lines changed

3 files changed

+41
-19
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
``Cursor`` and ``MultiCursor`` event handlers are now private
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
Access to the event handlers for the `.Cursor` and `.MultiCursor` widgets is
5+
now deprecated.

lib/matplotlib/tests/test_widgets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,7 +1517,7 @@ def test_MultiCursor(horizOn, vertOn):
15171517
# Can't use `do_event` as that helper requires the widget
15181518
# to have a single .ax attribute.
15191519
event = mock_event(ax1, xdata=.5, ydata=.25)
1520-
multi.onmove(event)
1520+
multi._onmove(event)
15211521

15221522
# the lines in the first two ax should both move
15231523
for l in multi.vlines:
@@ -1528,7 +1528,7 @@ def test_MultiCursor(horizOn, vertOn):
15281528
# test a move event in an Axes not part of the MultiCursor
15291529
# the lines in ax1 and ax2 should not have moved.
15301530
event = mock_event(ax3, xdata=.75, ydata=.75)
1531-
multi.onmove(event)
1531+
multi._onmove(event)
15321532
for l in multi.vlines:
15331533
assert l.get_xdata() == (.5, .5)
15341534
for l in multi.hlines:

lib/matplotlib/widgets.py

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,8 +1600,8 @@ def __init__(self, ax, horizOn=True, vertOn=True, useblit=False,
16001600
**lineprops):
16011601
super().__init__(ax)
16021602

1603-
self.connect_event('motion_notify_event', self.onmove)
1604-
self.connect_event('draw_event', self.clear)
1603+
self.connect_event('motion_notify_event', self._onmove)
1604+
self.connect_event('draw_event', self._clear)
16051605

16061606
self.visible = True
16071607
self.horizOn = horizOn
@@ -1616,16 +1616,25 @@ def __init__(self, ax, horizOn=True, vertOn=True, useblit=False,
16161616
self.background = None
16171617
self.needclear = False
16181618

1619+
@_api.deprecated('3.5')
16191620
def clear(self, event):
16201621
"""Internal event handler to clear the cursor."""
1622+
self._clear(event)
16211623
if self.ignore(event):
16221624
return
1623-
if self.useblit:
1624-
self.background = self.canvas.copy_from_bbox(self.ax.bbox)
16251625
self.linev.set_visible(False)
16261626
self.lineh.set_visible(False)
16271627

1628-
def onmove(self, event):
1628+
def _clear(self, event):
1629+
"""Internal event handler to clear the cursor."""
1630+
if self.ignore(event):
1631+
return
1632+
if self.useblit:
1633+
self.background = self.canvas.copy_from_bbox(self.ax.bbox)
1634+
1635+
onmove = _api.deprecate_privatize_attribute('3.5')
1636+
1637+
def _onmove(self, event):
16291638
"""Internal event handler to draw the cursor when the mouse moves."""
16301639
if self.ignore(event):
16311640
return
@@ -1640,15 +1649,15 @@ def onmove(self, event):
16401649
self.needclear = False
16411650
return
16421651
self.needclear = True
1643-
if not self.visible:
1644-
return
1652+
16451653
self.linev.set_xdata((event.xdata, event.xdata))
1654+
self.linev.set_visible(self.visible and self.vertOn)
16461655

16471656
self.lineh.set_ydata((event.ydata, event.ydata))
1648-
self.linev.set_visible(self.visible and self.vertOn)
16491657
self.lineh.set_visible(self.visible and self.horizOn)
16501658

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

16531662
def _update(self):
16541663
if self.useblit:
@@ -1749,8 +1758,8 @@ def connect(self):
17491758
"""Connect events."""
17501759
for canvas, info in self._canvas_infos.items():
17511760
info["cids"] = [
1752-
canvas.mpl_connect('motion_notify_event', self.onmove),
1753-
canvas.mpl_connect('draw_event', self.clear),
1761+
canvas.mpl_connect('motion_notify_event', self._onmove),
1762+
canvas.mpl_connect('draw_event', self._clear),
17541763
]
17551764

17561765
def disconnect(self):
@@ -1760,24 +1769,31 @@ def disconnect(self):
17601769
canvas.mpl_disconnect(cid)
17611770
info["cids"].clear()
17621771

1772+
@_api.deprecated('3.5')
17631773
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)
1780+
1781+
def _clear(self, event):
17641782
"""Clear the cursor."""
17651783
if self.ignore(event):
17661784
return
17671785
if self.useblit:
17681786
for canvas, info in self._canvas_infos.items():
17691787
info["background"] = canvas.copy_from_bbox(canvas.figure.bbox)
1770-
for line in self.vlines + self.hlines:
1771-
line.set_visible(False)
17721788

1773-
def onmove(self, event):
1789+
onmove = _api.deprecate_privatize_attribute('3.5')
1790+
1791+
def _onmove(self, event):
17741792
if (self.ignore(event)
17751793
or event.inaxes not in self.axes
17761794
or not event.canvas.widgetlock.available(self)):
17771795
return
17781796
self.needclear = True
1779-
if not self.visible:
1780-
return
17811797
if self.vertOn:
17821798
for line in self.vlines:
17831799
line.set_xdata((event.xdata, event.xdata))
@@ -1786,7 +1802,8 @@ def onmove(self, event):
17861802
for line in self.hlines:
17871803
line.set_ydata((event.ydata, event.ydata))
17881804
line.set_visible(self.visible)
1789-
self._update()
1805+
if self.visible and (self.vertOn or self.horizOn):
1806+
self._update()
17901807

17911808
def _update(self):
17921809
if self.useblit:

0 commit comments

Comments
 (0)