Skip to content

Commit 733fbb0

Browse files
QuLogictacaswell
authored andcommitted
Deprecate access to Cursor/MultiCursor event handlers.
1 parent 2828912 commit 733fbb0

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed
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

+2-2
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

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

1619-
def clear(self, event):
1619+
clear = _api.deprecate_privatize_attribute('3.5')
1620+
1621+
def _clear(self, event):
16201622
"""Internal event handler to clear the cursor."""
16211623
if self.ignore(event):
16221624
return
@@ -1625,7 +1627,9 @@ def clear(self, event):
16251627
self.linev.set_visible(False)
16261628
self.lineh.set_visible(False)
16271629

1628-
def onmove(self, event):
1630+
onmove = _api.deprecate_privatize_attribute('3.5')
1631+
1632+
def _onmove(self, event):
16291633
"""Internal event handler to draw the cursor when the mouse moves."""
16301634
if self.ignore(event):
16311635
return
@@ -1749,8 +1753,8 @@ def connect(self):
17491753
"""Connect events."""
17501754
for canvas, info in self._canvas_infos.items():
17511755
info["cids"] = [
1752-
canvas.mpl_connect('motion_notify_event', self.onmove),
1753-
canvas.mpl_connect('draw_event', self.clear),
1756+
canvas.mpl_connect('motion_notify_event', self._onmove),
1757+
canvas.mpl_connect('draw_event', self._clear),
17541758
]
17551759

17561760
def disconnect(self):
@@ -1760,7 +1764,9 @@ def disconnect(self):
17601764
canvas.mpl_disconnect(cid)
17611765
info["cids"].clear()
17621766

1763-
def clear(self, event):
1767+
clear = _api.deprecate_privatize_attribute('3.5')
1768+
1769+
def _clear(self, event):
17641770
"""Clear the cursor."""
17651771
if self.ignore(event):
17661772
return
@@ -1770,7 +1776,9 @@ def clear(self, event):
17701776
for line in self.vlines + self.hlines:
17711777
line.set_visible(False)
17721778

1773-
def onmove(self, event):
1779+
onmove = _api.deprecate_privatize_attribute('3.5')
1780+
1781+
def _onmove(self, event):
17741782
if (self.ignore(event)
17751783
or event.inaxes not in self.axes
17761784
or not event.canvas.widgetlock.available(self)):

0 commit comments

Comments
 (0)