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

Skip to content

Expire cursor-related deprecations #24129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions doc/api/next_api_changes/removals/24129-OG.rst
Original file line number Diff line number Diff line change
@@ -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.
12 changes: 0 additions & 12 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 0 additions & 10 deletions lib/matplotlib/backend_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 4 additions & 16 deletions lib/matplotlib/backend_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 0 additions & 7 deletions lib/matplotlib/backends/_backend_tk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 0 additions & 24 deletions lib/matplotlib/backends/backend_gtk3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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):
Expand Down
7 changes: 0 additions & 7 deletions lib/matplotlib/backends/backend_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backends/backend_qt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 0 additions & 20 deletions lib/matplotlib/backends/backend_wx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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):
Expand Down