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

Skip to content

Commit 83b1cfd

Browse files
committed
Deprecate access to Cursor/MultiCursor event handlers.
1 parent bfa31a4 commit 83b1cfd

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
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
@@ -484,7 +484,7 @@ def test_MultiCursor(horizOn, vertOn):
484484
# Can't use `do_event` as that helper requires the widget
485485
# to have a single .ax attribute.
486486
event = mock_event(ax1, xdata=.5, ydata=.25)
487-
multi.onmove(event)
487+
multi._onmove(event)
488488

489489
# the lines in the first two ax should both move
490490
for l in multi.vlines:
@@ -495,7 +495,7 @@ def test_MultiCursor(horizOn, vertOn):
495495
# test a move event in an axes not part of the MultiCursor
496496
# the lines in ax1 and ax2 should not have moved.
497497
event = mock_event(ax3, xdata=.75, ydata=.75)
498-
multi.onmove(event)
498+
multi._onmove(event)
499499
for l in multi.vlines:
500500
assert l.get_xdata() == (.5, .5)
501501
for l in multi.hlines:

lib/matplotlib/widgets.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,8 +1509,8 @@ def __init__(self, ax, horizOn=True, vertOn=True, useblit=False,
15091509
**lineprops):
15101510
super().__init__(ax)
15111511

1512-
self.connect_event('motion_notify_event', self.onmove)
1513-
self.connect_event('draw_event', self.clear)
1512+
self.connect_event('motion_notify_event', self._onmove)
1513+
self.connect_event('draw_event', self._clear)
15141514

15151515
self.visible = True
15161516
self.horizOn = horizOn
@@ -1525,7 +1525,9 @@ def __init__(self, ax, horizOn=True, vertOn=True, useblit=False,
15251525
self.background = None
15261526
self.needclear = False
15271527

1528-
def clear(self, event):
1528+
clear = _api.deprecate_privatize_attribute('3.5')
1529+
1530+
def _clear(self, event):
15291531
"""Internal event handler to clear the cursor."""
15301532
if self.ignore(event):
15311533
return
@@ -1534,7 +1536,9 @@ def clear(self, event):
15341536
self.linev.set_visible(False)
15351537
self.lineh.set_visible(False)
15361538

1537-
def onmove(self, event):
1539+
onmove = _api.deprecate_privatize_attribute('3.5')
1540+
1541+
def _onmove(self, event):
15381542
"""Internal event handler to draw the cursor when the mouse moves."""
15391543
if self.ignore(event):
15401544
return
@@ -1632,15 +1636,17 @@ def __init__(self, canvas, axes, useblit=True, horizOn=False, vertOn=True,
16321636
def connect(self):
16331637
"""Connect events."""
16341638
self._cidmotion = self.canvas.mpl_connect('motion_notify_event',
1635-
self.onmove)
1636-
self._ciddraw = self.canvas.mpl_connect('draw_event', self.clear)
1639+
self._onmove)
1640+
self._ciddraw = self.canvas.mpl_connect('draw_event', self._clear)
16371641

16381642
def disconnect(self):
16391643
"""Disconnect events."""
16401644
self.canvas.mpl_disconnect(self._cidmotion)
16411645
self.canvas.mpl_disconnect(self._ciddraw)
16421646

1643-
def clear(self, event):
1647+
clear = _api.deprecate_privatize_attribute('3.5')
1648+
1649+
def _clear(self, event):
16441650
"""Clear the cursor."""
16451651
if self.ignore(event):
16461652
return
@@ -1650,7 +1656,9 @@ def clear(self, event):
16501656
for line in self.vlines + self.hlines:
16511657
line.set_visible(False)
16521658

1653-
def onmove(self, event):
1659+
onmove = _api.deprecate_privatize_attribute('3.5')
1660+
1661+
def _onmove(self, event):
16541662
if self.ignore(event):
16551663
return
16561664
if event.inaxes not in self.axes:

0 commit comments

Comments
 (0)