From adc305c2fcd6569238a739667e57ce2672462b37 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Sat, 8 Oct 2022 14:27:59 +0200 Subject: [PATCH] Expire cursor-related deprecations --- .../next_api_changes/removals/24129-OG.rst | 33 +++++++++++++++++++ lib/matplotlib/backend_bases.py | 12 ------- lib/matplotlib/backend_managers.py | 10 ------ lib/matplotlib/backend_tools.py | 20 +++-------- lib/matplotlib/backends/_backend_tk.py | 7 ---- lib/matplotlib/backends/backend_gtk3.py | 24 -------------- lib/matplotlib/backends/backend_qt.py | 7 ---- lib/matplotlib/backends/backend_qt5.py | 2 +- lib/matplotlib/backends/backend_wx.py | 20 ----------- 9 files changed, 38 insertions(+), 97 deletions(-) create mode 100644 doc/api/next_api_changes/removals/24129-OG.rst diff --git a/doc/api/next_api_changes/removals/24129-OG.rst b/doc/api/next_api_changes/removals/24129-OG.rst new file mode 100644 index 000000000000..28894274263d --- /dev/null +++ b/doc/api/next_api_changes/removals/24129-OG.rst @@ -0,0 +1,33 @@ +Interactive cursor details +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Setting a mouse cursor on a window has been moved from the toolbar to the +canvas. Consequently, several implementation details on toolbars and within +backends have been removed. + +``NavigationToolbar2.set_cursor`` and ``backend_tools.SetCursorBase.set_cursor`` +................................................................................ + +Instead, use the `.FigureCanvasBase.set_cursor` method on the canvas (available +as the ``canvas`` attribute on the toolbar or the Figure.) + +``backend_tools.SetCursorBase`` and subclasses +.............................................. + +``backend_tools.SetCursorBase`` was subclassed to provide backend-specific +implementations of ``set_cursor``. As that is now removed, the subclassing +is no longer necessary. Consequently, the following subclasses are also +removed: + +- ``matplotlib.backends.backend_gtk3.SetCursorGTK3`` +- ``matplotlib.backends.backend_qt5.SetCursorQt`` +- ``matplotlib.backends._backend_tk.SetCursorTk`` +- ``matplotlib.backends.backend_wx.SetCursorWx`` + +Instead, use the `.backend_tools.ToolSetCursor` class. + +``cursord`` in GTK and wx backends +.................................. + +The ``backend_gtk3.cursord`` and ``backend_wx.cursord`` dictionaries are +removed. This makes the GTK module importable on headless environments. diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index 26a2f9cd1432..fbd5b238cef9 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -3296,18 +3296,6 @@ def save_figure(self, *args): """Save the current figure.""" raise NotImplementedError - @_api.deprecated("3.5", alternative="`.FigureCanvasBase.set_cursor`") - def set_cursor(self, cursor): - """ - Set the current cursor to one of the :class:`Cursors` enums values. - - If required by the backend, this method should trigger an update in - the backend event loop after the cursor is set, as this method may be - called e.g. before a long-running task during which the GUI is not - updated. - """ - self.canvas.set_cursor(cursor) - def update(self): """Reset the Axes stack.""" self._nav_stack.clear() diff --git a/lib/matplotlib/backend_managers.py b/lib/matplotlib/backend_managers.py index 7c3f7b92106f..ac36e206bc4e 100644 --- a/lib/matplotlib/backend_managers.py +++ b/lib/matplotlib/backend_managers.py @@ -257,16 +257,6 @@ def add_tool(self, name, tool, *args, **kwargs): 'exists, not added') return self._tools[name] - if name == 'cursor' and tool_cls != backend_tools.SetCursorBase: - _api.warn_deprecated("3.5", - message="Overriding ToolSetCursor with " - f"{tool_cls.__qualname__} was only " - "necessary to provide the .set_cursor() " - "method, which is deprecated since " - "%(since)s and will be removed " - "%(removal)s. Please report this to the " - f"{tool_cls.__module__} author.") - tool_obj = tool_cls(self, name, *args, **kwargs) self._tools[name] = tool_obj diff --git a/lib/matplotlib/backend_tools.py b/lib/matplotlib/backend_tools.py index bc13951793b2..fbe7a157d4db 100644 --- a/lib/matplotlib/backend_tools.py +++ b/lib/matplotlib/backend_tools.py @@ -252,12 +252,12 @@ def set_figure(self, figure): self._toggled = True -class SetCursorBase(ToolBase): +class ToolSetCursor(ToolBase): """ Change to the current cursor while inaxes. - This tool, keeps track of all `ToolToggleBase` derived tools, and calls - `set_cursor` when a tool gets triggered. + This tool, keeps track of all `ToolToggleBase` derived tools, and updates + the cursor when a tool gets triggered. """ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -310,18 +310,6 @@ def _set_cursor_cbk(self, event): self.canvas.set_cursor(self._default_cursor) self._last_cursor = self._default_cursor - @_api.deprecated("3.5", alternative="`.FigureCanvasBase.set_cursor`") - def set_cursor(self, cursor): - """ - Set the cursor. - """ - self.canvas.set_cursor(cursor) - - -# This exists solely for deprecation warnings; remove with -# SetCursorBase.set_cursor. -ToolSetCursor = SetCursorBase - class ToolCursorPosition(ToolBase): """ @@ -979,7 +967,7 @@ def trigger(self, *args, **kwargs): 'yscale': ToolYScale, 'position': ToolCursorPosition, _views_positions: ToolViewsPositions, - 'cursor': SetCursorBase, + 'cursor': ToolSetCursor, 'rubberband': RubberbandBase, 'help': ToolHelpBase, 'copy': ToolCopyToClipboardBase, diff --git a/lib/matplotlib/backends/_backend_tk.py b/lib/matplotlib/backends/_backend_tk.py index 5d92e35469c2..fcf260f13524 100644 --- a/lib/matplotlib/backends/_backend_tk.py +++ b/lib/matplotlib/backends/_backend_tk.py @@ -910,13 +910,6 @@ def remove_rubberband(self): property(lambda self: self.figure.canvas._rubberband_rect)) -@_api.deprecated("3.5", alternative="ToolSetCursor") -class SetCursorTk(backend_tools.SetCursorBase): - def set_cursor(self, cursor): - NavigationToolbar2Tk.set_cursor( - self._make_classic_style_pseudo_toolbar(), cursor) - - class ToolbarTk(ToolContainerBase, tk.Frame): def __init__(self, toolmanager, window=None): ToolContainerBase.__init__(self, toolmanager) diff --git a/lib/matplotlib/backends/backend_gtk3.py b/lib/matplotlib/backends/backend_gtk3.py index 89e92690c7eb..b89261f52c9e 100644 --- a/lib/matplotlib/backends/backend_gtk3.py +++ b/lib/matplotlib/backends/backend_gtk3.py @@ -9,7 +9,6 @@ from matplotlib.backend_bases import ( FigureCanvasBase, ToolContainerBase, CloseEvent, KeyEvent, LocationEvent, MouseEvent, ResizeEvent) -from matplotlib.backend_tools import Cursors try: import gi @@ -39,22 +38,6 @@ @_api.caching_module_getattr # module-level deprecations class __getattr__: - @_api.deprecated("3.5", obj_type="") - @property - def cursord(self): - try: - new_cursor = functools.partial( - Gdk.Cursor.new_from_name, Gdk.Display.get_default()) - return { - Cursors.MOVE: new_cursor("move"), - Cursors.HAND: new_cursor("pointer"), - Cursors.POINTER: new_cursor("default"), - Cursors.SELECT_REGION: new_cursor("crosshair"), - Cursors.WAIT: new_cursor("wait"), - } - except TypeError: - return {} - icon_filename = _api.deprecated("3.6", obj_type="")(property( lambda self: "matplotlib.png" if sys.platform == "win32" else "matplotlib.svg")) @@ -493,13 +476,6 @@ def trigger(self, *args, **kwargs): self._make_classic_style_pseudo_toolbar()) -@_api.deprecated("3.5", alternative="ToolSetCursor") -class SetCursorGTK3(backend_tools.SetCursorBase): - def set_cursor(self, cursor): - NavigationToolbar2GTK3.set_cursor( - self._make_classic_style_pseudo_toolbar(), cursor) - - @backend_tools._register_tool_class(FigureCanvasGTK3) class HelpGTK3(backend_tools.ToolHelpBase): def _normalize_shortcut(self, key): diff --git a/lib/matplotlib/backends/backend_qt.py b/lib/matplotlib/backends/backend_qt.py index b91446c4e632..3866a5ab24e7 100644 --- a/lib/matplotlib/backends/backend_qt.py +++ b/lib/matplotlib/backends/backend_qt.py @@ -976,13 +976,6 @@ def trigger(self, *args): self._make_classic_style_pseudo_toolbar()) -@_api.deprecated("3.5", alternative="ToolSetCursor") -class SetCursorQt(backend_tools.SetCursorBase): - def set_cursor(self, cursor): - NavigationToolbar2QT.set_cursor( - self._make_classic_style_pseudo_toolbar(), cursor) - - @backend_tools._register_tool_class(FigureCanvasQT) class RubberbandQt(backend_tools.RubberbandBase): def draw_rubberband(self, x0, y0, x1, y1): diff --git a/lib/matplotlib/backends/backend_qt5.py b/lib/matplotlib/backends/backend_qt5.py index 3c6b2c66a845..d40dcfaff699 100644 --- a/lib/matplotlib/backends/backend_qt5.py +++ b/lib/matplotlib/backends/backend_qt5.py @@ -8,7 +8,7 @@ # Public API cursord, _create_qApp, _BackendQT, TimerQT, MainWindow, FigureCanvasQT, FigureManagerQT, ToolbarQt, NavigationToolbar2QT, SubplotToolQt, - SaveFigureQt, ConfigureSubplotsQt, SetCursorQt, RubberbandQt, + SaveFigureQt, ConfigureSubplotsQt, RubberbandQt, HelpQt, ToolCopyToClipboardQT, # internal re-exports FigureCanvasBase, FigureManagerBase, MouseButton, NavigationToolbar2, diff --git a/lib/matplotlib/backends/backend_wx.py b/lib/matplotlib/backends/backend_wx.py index 952dd27a3903..d76fdb8f670a 100644 --- a/lib/matplotlib/backends/backend_wx.py +++ b/lib/matplotlib/backends/backend_wx.py @@ -39,19 +39,6 @@ PIXELS_PER_INCH = 75 -@_api.caching_module_getattr # module-level deprecations -class __getattr__: - cursord = _api.deprecated("3.5", obj_type="")(property(lambda self: { - cursors.MOVE: wx.CURSOR_HAND, - cursors.HAND: wx.CURSOR_HAND, - cursors.POINTER: wx.CURSOR_ARROW, - cursors.SELECT_REGION: wx.CURSOR_CROSS, - cursors.WAIT: wx.CURSOR_WAIT, - cursors.RESIZE_HORIZONTAL: wx.CURSOR_SIZEWE, - cursors.RESIZE_VERTICAL: wx.CURSOR_SIZENS, - })) - - @_api.deprecated("3.6") def error_msg_wx(msg, parent=None): """Signal an error condition with a popup error dialog.""" @@ -1292,13 +1279,6 @@ def trigger(self, *args): self._make_classic_style_pseudo_toolbar()) -@_api.deprecated("3.5", alternative="ToolSetCursor") -class SetCursorWx(backend_tools.SetCursorBase): - def set_cursor(self, cursor): - NavigationToolbar2Wx.set_cursor( - self._make_classic_style_pseudo_toolbar(), cursor) - - @backend_tools._register_tool_class(_FigureCanvasWxBase) class RubberbandWx(backend_tools.RubberbandBase): def draw_rubberband(self, x0, y0, x1, y1):