| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff 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. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1517,7 +1517,7 @@ def test_MultiCursor(horizOn, vertOn): | |||
| 1517 | 1517 | # Can't use `do_event` as that helper requires the widget | |
| 1518 | 1518 | # to have a single .ax attribute. | |
| 1519 | 1519 | event = mock_event(ax1, xdata=.5, ydata=.25) | |
| 1520 | - multi.onmove(event) | ||
| 1520 | + multi._onmove(event) | ||
| 1521 | 1521 | ||
| 1522 | 1522 | # the lines in the first two ax should both move | |
| 1523 | 1523 | for l in multi.vlines: | |
@@ -1528,7 +1528,7 @@ def test_MultiCursor(horizOn, vertOn): | |||
| 1528 | 1528 | # test a move event in an Axes not part of the MultiCursor | |
| 1529 | 1529 | # the lines in ax1 and ax2 should not have moved. | |
| 1530 | 1530 | event = mock_event(ax3, xdata=.75, ydata=.75) | |
| 1531 | - multi.onmove(event) | ||
| 1531 | + multi._onmove(event) | ||
| 1532 | 1532 | for l in multi.vlines: | |
| 1533 | 1533 | assert l.get_xdata() == (.5, .5) | |
| 1534 | 1534 | for l in multi.hlines: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1600,8 +1600,8 @@ def __init__(self, ax, horizOn=True, vertOn=True, useblit=False, | |||
| 1600 | 1600 | **lineprops): | |
| 1601 | 1601 | super().__init__(ax) | |
| 1602 | 1602 | ||
| 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) | ||
| 1605 | 1605 | ||
| 1606 | 1606 | self.visible = True | |
| 1607 | 1607 | self.horizOn = horizOn | |
@@ -1616,16 +1616,25 @@ def __init__(self, ax, horizOn=True, vertOn=True, useblit=False, | |||
| 1616 | 1616 | self.background = None | |
| 1617 | 1617 | self.needclear = False | |
| 1618 | 1618 | ||
| 1619 | + @_api.deprecated('3.5') | ||
| 1619 | 1620 | def clear(self, event): | |
| 1620 | 1621 | """Internal event handler to clear the cursor.""" | |
| 1622 | + self._clear(event) | ||
| 1621 | 1623 | if self.ignore(event): | |
| 1622 | 1624 | return | |
| 1623 | - if self.useblit: | ||
| 1624 | - self.background = self.canvas.copy_from_bbox(self.ax.bbox) | ||
| 1625 | 1625 | self.linev.set_visible(False) | |
| 1626 | 1626 | self.lineh.set_visible(False) | |
| 1627 | 1627 | ||
| 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): | ||
| 1629 | 1638 | """Internal event handler to draw the cursor when the mouse moves.""" | |
| 1630 | 1639 | if self.ignore(event): | |
| 1631 | 1640 | return | |
@@ -1640,15 +1649,15 @@ def onmove(self, event): | |||
| 1640 | 1649 | self.needclear = False | |
| 1641 | 1650 | return | |
| 1642 | 1651 | self.needclear = True | |
| 1643 | - if not self.visible: | ||
| 1644 | - return | ||
| 1652 | + | ||
| 1645 | 1653 | self.linev.set_xdata((event.xdata, event.xdata)) | |
| 1654 | + self.linev.set_visible(self.visible and self.vertOn) | ||
| 1646 | 1655 | ||
| 1647 | 1656 | self.lineh.set_ydata((event.ydata, event.ydata)) | |
| 1648 | - self.linev.set_visible(self.visible and self.vertOn) | ||
| 1649 | 1657 | self.lineh.set_visible(self.visible and self.horizOn) | |
| 1650 | 1658 | ||
| 1651 | - self._update() | ||
| 1659 | + if self.visible and (self.vertOn or self.horizOn): | ||
| 1660 | + self._update() | ||
| 1652 | 1661 | ||
| 1653 | 1662 | def _update(self): | |
| 1654 | 1663 | if self.useblit: | |
@@ -1749,8 +1758,8 @@ def connect(self): | |||
| 1749 | 1758 | """Connect events.""" | |
| 1750 | 1759 | for canvas, info in self._canvas_infos.items(): | |
| 1751 | 1760 | 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), | ||
| 1754 | 1763 | ] | |
| 1755 | 1764 | ||
| 1756 | 1765 | def disconnect(self): | |
@@ -1760,24 +1769,31 @@ def disconnect(self): | |||
| 1760 | 1769 | canvas.mpl_disconnect(cid) | |
| 1761 | 1770 | info["cids"].clear() | |
| 1762 | 1771 | ||
| 1772 | + @_api.deprecated('3.5') | ||
| 1763 | 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) | ||
| 1780 | + | ||
| 1781 | + def _clear(self, event): | ||
| 1764 | 1782 | """Clear the cursor.""" | |
| 1765 | 1783 | if self.ignore(event): | |
| 1766 | 1784 | return | |
| 1767 | 1785 | if self.useblit: | |
| 1768 | 1786 | for canvas, info in self._canvas_infos.items(): | |
| 1769 | 1787 | info["background"] = canvas.copy_from_bbox(canvas.figure.bbox) | |
| 1770 | - for line in self.vlines + self.hlines: | ||
| 1771 | - line.set_visible(False) | ||
| 1772 | 1788 | ||
| 1773 | - def onmove(self, event): | ||
| 1789 | + onmove = _api.deprecate_privatize_attribute('3.5') | ||
| 1790 | + | ||
| 1791 | + def _onmove(self, event): | ||
| 1774 | 1792 | if (self.ignore(event) | |
| 1775 | 1793 | or event.inaxes not in self.axes | |
| 1776 | 1794 | or not event.canvas.widgetlock.available(self)): | |
| 1777 | 1795 | return | |
| 1778 | 1796 | self.needclear = True | |
| 1779 | - if not self.visible: | ||
| 1780 | - return | ||
| 1781 | 1797 | if self.vertOn: | |
| 1782 | 1798 | for line in self.vlines: | |
| 1783 | 1799 | line.set_xdata((event.xdata, event.xdata)) | |
@@ -1786,7 +1802,8 @@ def onmove(self, event): | |||
| 1786 | 1802 | for line in self.hlines: | |
| 1787 | 1803 | line.set_ydata((event.ydata, event.ydata)) | |
| 1788 | 1804 | line.set_visible(self.visible) | |
| 1789 | - self._update() | ||
| 1805 | + if self.visible and (self.vertOn or self.horizOn): | ||
| 1806 | + self._update() | ||
| 1790 | 1807 | ||
| 1791 | 1808 | def _update(self): | |
| 1792 | 1809 | if self.useblit: | |
| Back | FazBrowse Home | New Git URL |
0 commit comments