Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fe0095e

Browse filesBrowse files
authored
Merge pull request #6603 from anntzer/waitcursor-while-redrawing
Switch the cursor to a busy cursor while redrawing.
2 parents efb030d + d1516e6 commit fe0095e
Copy full SHA for fe0095e

9 files changed

+38
-10
lines changed

‎lib/matplotlib/backend_bases.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backend_bases.py
+11-6Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2806,7 +2806,8 @@ def __init__(self, canvas):
28062806
self._idPress = None
28072807
self._idRelease = None
28082808
self._active = None
2809-
self._lastCursor = None
2809+
# This cursor will be set after the initial draw.
2810+
self._lastCursor = cursors.POINTER
28102811
self._init_toolbar()
28112812
self._idDrag = self.canvas.mpl_connect(
28122813
'motion_notify_event', self.mouse_move)
@@ -2892,14 +2893,13 @@ def _set_cursor(self, event):
28922893
self.set_cursor(cursors.POINTER)
28932894
self._lastCursor = cursors.POINTER
28942895
else:
2895-
if self._active == 'ZOOM':
2896-
if self._lastCursor != cursors.SELECT_REGION:
2897-
self.set_cursor(cursors.SELECT_REGION)
2898-
self._lastCursor = cursors.SELECT_REGION
2896+
if (self._active == 'ZOOM'
2897+
and self._lastCursor != cursors.SELECT_REGION):
2898+
self.set_cursor(cursors.SELECT_REGION)
2899+
self._lastCursor = cursors.SELECT_REGION
28992900
elif (self._active == 'PAN' and
29002901
self._lastCursor != cursors.MOVE):
29012902
self.set_cursor(cursors.MOVE)
2902-
29032903
self._lastCursor = cursors.MOVE
29042904

29052905
def mouse_move(self, event):
@@ -3189,6 +3189,11 @@ def save_figure(self, *args):
31893189

31903190
def set_cursor(self, cursor):
31913191
"""Set the current cursor to one of the :class:`Cursors` enums values.
3192+
3193+
If required by the backend, this method should trigger an update in
3194+
the backend event loop after the cursor is set, as this method may be
3195+
called e.g. before a long-running task during which the GUI is not
3196+
updated.
31923197
"""
31933198

31943199
def update(self):

‎lib/matplotlib/backend_tools.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backend_tools.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
class Cursors(object):
2626
"""Simple namespace for cursor reference"""
27-
HAND, POINTER, SELECT_REGION, MOVE = list(range(4))
27+
HAND, POINTER, SELECT_REGION, MOVE, WAIT = list(range(5))
2828
cursors = Cursors()
2929

3030
# Views positions tool

‎lib/matplotlib/backends/backend_agg.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_agg.py
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from math import radians, cos, sin
3131
from matplotlib import verbose, rcParams, __version__
3232
from matplotlib.backend_bases import (
33-
_Backend, FigureCanvasBase, FigureManagerBase, RendererBase)
33+
_Backend, FigureCanvasBase, FigureManagerBase, RendererBase, cursors)
3434
from matplotlib.cbook import maxdict
3535
from matplotlib.figure import Figure
3636
from matplotlib.font_manager import findfont, get_font
@@ -423,9 +423,14 @@ def draw(self):
423423
# acquire a lock on the shared font cache
424424
RendererAgg.lock.acquire()
425425

426+
toolbar = self.toolbar
426427
try:
428+
if toolbar:
429+
toolbar.set_cursor(cursors.WAIT)
427430
self.figure.draw(self.renderer)
428431
finally:
432+
if toolbar:
433+
toolbar.set_cursor(toolbar._lastCursor)
429434
RendererAgg.lock.release()
430435

431436
def get_renderer(self, cleared=False):

‎lib/matplotlib/backends/backend_gtk.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_gtk.py
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
cursors.HAND : gdk.Cursor(gdk.HAND2),
5555
cursors.POINTER : gdk.Cursor(gdk.LEFT_PTR),
5656
cursors.SELECT_REGION : gdk.Cursor(gdk.TCROSS),
57+
cursors.WAIT : gdk.Cursor(gdk.WATCH),
5758
}
5859

5960
# ref gtk+/gtk/gtkwidget.h
@@ -386,16 +387,20 @@ def _render_figure(self, pixmap, width, height):
386387
def expose_event(self, widget, event):
387388
"""Expose_event for all GTK backends. Should not be overridden.
388389
"""
390+
toolbar = self.toolbar
391+
if toolbar:
392+
toolbar.set_cursor(cursors.WAIT)
389393
if GTK_WIDGET_DRAWABLE(self):
390394
if self._need_redraw:
391395
x, y, w, h = self.allocation
392396
self._pixmap_prepare (w, h)
393397
self._render_figure(self._pixmap, w, h)
394398
self._need_redraw = False
395-
396399
x, y, w, h = event.area
397400
self.window.draw_drawable (self.style.fg_gc[self.state],
398401
self._pixmap, x, y, x, y, w, h)
402+
if toolbar:
403+
toolbar.set_cursor(toolbar._lastCursor)
399404
return False # finish event propagation?
400405

401406
filetypes = FigureCanvasBase.filetypes.copy()
@@ -619,6 +624,7 @@ def set_message(self, s):
619624

620625
def set_cursor(self, cursor):
621626
self.canvas.window.set_cursor(cursord[cursor])
627+
gtk.main_iteration()
622628

623629
def release(self, event):
624630
try: del self._pixmapBack

‎lib/matplotlib/backends/backend_gtk3.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_gtk3.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
cursors.HAND : Gdk.Cursor.new(Gdk.CursorType.HAND2),
5252
cursors.POINTER : Gdk.Cursor.new(Gdk.CursorType.LEFT_PTR),
5353
cursors.SELECT_REGION : Gdk.Cursor.new(Gdk.CursorType.TCROSS),
54+
cursors.WAIT : Gdk.Cursor.new(Gdk.CursorType.WATCH),
5455
}
5556

5657

@@ -499,7 +500,7 @@ def set_message(self, s):
499500

500501
def set_cursor(self, cursor):
501502
self.canvas.get_property("window").set_cursor(cursord[cursor])
502-
#self.canvas.set_cursor(cursord[cursor])
503+
Gtk.main_iteration()
503504

504505
def release(self, event):
505506
try: del self._pixmapBack

‎lib/matplotlib/backends/backend_gtk3cairo.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_gtk3cairo.py
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from . import backend_cairo, backend_gtk3
77
from .backend_cairo import cairo, HAS_CAIRO_CFFI
88
from .backend_gtk3 import _BackendGTK3
9+
from matplotlib.backend_bases import cursors
910
from matplotlib.figure import Figure
1011

1112

@@ -35,10 +36,15 @@ def _render_figure(self, width, height):
3536
def on_draw_event(self, widget, ctx):
3637
""" GtkDrawable draw event, like expose_event in GTK 2.X
3738
"""
39+
toolbar = self.toolbar
40+
if toolbar:
41+
toolbar.set_cursor(cursors.WAIT)
3842
self._renderer.set_context(ctx)
3943
allocation = self.get_allocation()
4044
x, y, w, h = allocation.x, allocation.y, allocation.width, allocation.height
4145
self._render_figure(w, h)
46+
if toolbar:
47+
toolbar.set_cursor(toolbar._lastCursor)
4248
return False # finish event propagation?
4349

4450

‎lib/matplotlib/backends/backend_qt5.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_qt5.py
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
cursors.HAND: QtCore.Qt.PointingHandCursor,
9191
cursors.POINTER: QtCore.Qt.ArrowCursor,
9292
cursors.SELECT_REGION: QtCore.Qt.CrossCursor,
93+
cursors.WAIT: QtCore.Qt.WaitCursor,
9394
}
9495

9596

‎lib/matplotlib/backends/backend_tkagg.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_tkagg.py
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
cursors.HAND: "hand2",
4646
cursors.POINTER: "arrow",
4747
cursors.SELECT_REGION: "tcross",
48+
cursors.WAIT: "watch",
4849
}
4950

5051

@@ -697,6 +698,7 @@ def release(self, event):
697698

698699
def set_cursor(self, cursor):
699700
self.window.configure(cursor=cursord[cursor])
701+
self.window.update_idletasks()
700702

701703
def _Button(self, text, file, command, extension='.gif'):
702704
img_file = os.path.join(

‎lib/matplotlib/backends/backend_wx.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_wx.py
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,6 +1474,7 @@ def updateButtonText(self, lst):
14741474
cursors.HAND: wx.CURSOR_HAND,
14751475
cursors.POINTER: wx.CURSOR_ARROW,
14761476
cursors.SELECT_REGION: wx.CURSOR_CROSS,
1477+
cursors.WAIT: wx.CURSOR_WAIT,
14771478
}
14781479

14791480

@@ -1594,6 +1595,7 @@ def save_figure(self, *args):
15941595
def set_cursor(self, cursor):
15951596
cursor = wxc.Cursor(cursord[cursor])
15961597
self.canvas.SetCursor(cursor)
1598+
self.canvas.Update()
15971599

15981600
def release(self, event):
15991601
try:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.