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

Skip to content

Commit a080926

Browse files
authored
Merge pull request #20589 from QuLogic/size-cursors
Add directional sizing cursors
2 parents f230ce1 + cd4c898 commit a080926

File tree

9 files changed

+45
-34
lines changed

9 files changed

+45
-34
lines changed
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
``backend_gtk3.cursord``
2-
~~~~~~~~~~~~~~~~~~~~~~~~
3-
This dict is deprecated, in order to make the module importable on headless
4-
environments.
1+
``cursord`` in GTK, Qt, and wx backends
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
The ``backend_gtk3.cursord``, ``backend_qt.cursord``, and
4+
``backend_wx.cursord`` dictionaries are deprecated. This makes the GTK module
5+
importable on headless environments.

lib/matplotlib/backend_tools.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
`matplotlib.backend_managers.ToolManager`
1212
"""
1313

14-
from enum import IntEnum
14+
import enum
1515
import re
1616
import time
1717
from types import SimpleNamespace
@@ -25,9 +25,15 @@
2525
from matplotlib import cbook
2626

2727

28-
class Cursors(IntEnum): # Must subclass int for the macOS backend.
28+
class Cursors(enum.IntEnum): # Must subclass int for the macOS backend.
2929
"""Backend-independent cursor types."""
30-
HAND, POINTER, SELECT_REGION, MOVE, WAIT = range(5)
30+
POINTER = enum.auto()
31+
HAND = enum.auto()
32+
SELECT_REGION = enum.auto()
33+
MOVE = enum.auto()
34+
WAIT = enum.auto()
35+
RESIZE_HORIZONTAL = enum.auto()
36+
RESIZE_VERTICAL = enum.auto()
3137
cursors = Cursors # Backcompat.
3238

3339
# Views positions tool

lib/matplotlib/backends/_backend_tk.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
cursors.POINTER: "arrow",
3535
cursors.SELECT_REGION: "tcross",
3636
cursors.WAIT: "watch",
37-
}
37+
cursors.RESIZE_HORIZONTAL: "sb_h_double_arrow",
38+
cursors.RESIZE_VERTICAL: "sb_v_double_arrow",
39+
}
3840

3941

4042
@contextmanager

lib/matplotlib/backends/backend_gtk3.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ def _mpl_to_gtk_cursor(mpl_cursor):
9595
cursors.POINTER: "default",
9696
cursors.SELECT_REGION: "crosshair",
9797
cursors.WAIT: "wait",
98+
cursors.RESIZE_HORIZONTAL: "ew-resize",
99+
cursors.RESIZE_VERTICAL: "ns-resize",
98100
}[mpl_cursor]
99101
return Gdk.Cursor.new_from_name(Gdk.Display.get_default(), name)
100102

lib/matplotlib/backends/backend_qt5.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,15 @@
7373
(QtCore.Qt.ShiftModifier, QtCore.Qt.Key_Shift),
7474
(QtCore.Qt.MetaModifier, QtCore.Qt.Key_Meta),
7575
]
76-
cursord = {
76+
cursord = { # deprecated in Matplotlib 3.5.
7777
cursors.MOVE: QtCore.Qt.SizeAllCursor,
7878
cursors.HAND: QtCore.Qt.PointingHandCursor,
7979
cursors.POINTER: QtCore.Qt.ArrowCursor,
8080
cursors.SELECT_REGION: QtCore.Qt.CrossCursor,
8181
cursors.WAIT: QtCore.Qt.WaitCursor,
82-
}
82+
cursors.RESIZE_HORIZONTAL: QtCore.Qt.SizeHorCursor,
83+
cursors.RESIZE_VERTICAL: QtCore.Qt.SizeVerCursor,
84+
}
8385

8486

8587
# make place holder

lib/matplotlib/backends/backend_webagg_core.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from PIL import Image
2222
import tornado
2323

24-
from matplotlib import _api, backend_bases
24+
from matplotlib import _api, backend_bases, backend_tools
2525
from matplotlib.backends import backend_agg
2626
from matplotlib.backend_bases import _Backend
2727

@@ -364,7 +364,7 @@ class NavigationToolbar2WebAgg(backend_bases.NavigationToolbar2):
364364

365365
def __init__(self, canvas):
366366
self.message = ''
367-
self.cursor = 0
367+
self.cursor = None
368368
super().__init__(canvas)
369369

370370
def set_message(self, message):
@@ -374,6 +374,15 @@ def set_message(self, message):
374374

375375
def set_cursor(self, cursor):
376376
if cursor != self.cursor:
377+
cursor = {
378+
backend_tools.Cursors.HAND: 'pointer',
379+
backend_tools.Cursors.POINTER: 'default',
380+
backend_tools.Cursors.SELECT_REGION: 'crosshair',
381+
backend_tools.Cursors.MOVE: 'move',
382+
backend_tools.Cursors.WAIT: 'wait',
383+
backend_tools.Cursors.RESIZE_HORIZONTAL: 'ew-resize',
384+
backend_tools.Cursors.RESIZE_VERTICAL: 'ns-resize',
385+
}[cursor]
377386
self.canvas.send_event("cursor", cursor=cursor)
378387
self.cursor = cursor
379388

lib/matplotlib/backends/backend_wx.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1043,12 +1043,14 @@ def _set_frame_icon(frame):
10431043
frame.SetIcons(bundle)
10441044

10451045

1046-
cursord = {
1046+
cursord = { # deprecated in Matplotlib 3.5.
10471047
cursors.MOVE: wx.CURSOR_HAND,
10481048
cursors.HAND: wx.CURSOR_HAND,
10491049
cursors.POINTER: wx.CURSOR_ARROW,
10501050
cursors.SELECT_REGION: wx.CURSOR_CROSS,
10511051
cursors.WAIT: wx.CURSOR_WAIT,
1052+
cursors.RESIZE_HORIZONTAL: wx.CURSOR_SIZEWE,
1053+
cursors.RESIZE_VERTICAL: wx.CURSOR_SIZENS,
10521054
}
10531055

10541056

lib/matplotlib/backends/web_backend/js/mpl.js

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -444,22 +444,7 @@ mpl.figure.prototype.handle_figure_label = function (fig, msg) {
444444
};
445445

446446
mpl.figure.prototype.handle_cursor = function (fig, msg) {
447-
var cursor = msg['cursor'];
448-
switch (cursor) {
449-
case 0:
450-
cursor = 'pointer';
451-
break;
452-
case 1:
453-
cursor = 'default';
454-
break;
455-
case 2:
456-
cursor = 'crosshair';
457-
break;
458-
case 3:
459-
cursor = 'move';
460-
break;
461-
}
462-
fig.rubberband_canvas.style.cursor = cursor;
447+
fig.rubberband_canvas.style.cursor = msg['cursor'];
463448
};
464449

465450
mpl.figure.prototype.handle_message = function (fig, msg) {

src/_macosx.m

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,13 +1373,15 @@ -(void)save_figure:(id)sender
13731373
{
13741374
int i;
13751375
if(!PyArg_ParseTuple(args, "i", &i)) return NULL;
1376-
switch (i)
1377-
{ case 0: [[NSCursor pointingHandCursor] set]; break;
1376+
switch (i) {
13781377
case 1: [[NSCursor arrowCursor] set]; break;
1379-
case 2: [[NSCursor crosshairCursor] set]; break;
1380-
case 3: [[NSCursor openHandCursor] set]; break;
1378+
case 2: [[NSCursor pointingHandCursor] set]; break;
1379+
case 3: [[NSCursor crosshairCursor] set]; break;
1380+
case 4: [[NSCursor openHandCursor] set]; break;
13811381
/* OSX handles busy state itself so no need to set a cursor here */
1382-
case 4: break;
1382+
case 5: break;
1383+
case 6: [[NSCursor resizeLeftRightCursor] set]; break;
1384+
case 7: [[NSCursor resizeUpDownCursor] set]; break;
13831385
default: return NULL;
13841386
}
13851387
Py_RETURN_NONE;

0 commit comments

Comments
 (0)