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

Skip to content

Switch the cursor to a busy cursor while redrawing. #6603

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 4 commits into from
Aug 29, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Trigger event loop after setting cursor.
  • Loading branch information
anntzer committed Aug 23, 2017
commit 54689d75f12b75ee728742ffc294ff006049cadd
5 changes: 5 additions & 0 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -3201,6 +3201,11 @@ def save_figure(self, *args):

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.
"""

def update(self):
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/backends/backend_gtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ def set_message(self, s):

def set_cursor(self, cursor):
self.canvas.window.set_cursor(cursord[cursor])
gtk.main_iteration()

def release(self, event):
try: del self._pixmapBack
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backends/backend_gtk3.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ def set_message(self, s):

def set_cursor(self, cursor):
self.canvas.get_property("window").set_cursor(cursord[cursor])
#self.canvas.set_cursor(cursord[cursor])
Gtk.main_iteration()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you adding this cal to Gtk.main_iteration?

Copy link
Contributor Author

@anntzer anntzer Jun 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because otherwise the cursor is actually not set on the GUI (see docstring changed in CanvasBase.set_cursor). Basically, what happens is

Notification that a redraw is necessary.
Redraw starts and cursor is set.
[possibly long computation]
Return to GUI thread.

Note that the GUI event loop doesn't get to run between [cursor is set] and [possibly long computation], so depending on the details of the toolkit, the cursor change may not actually appear to the user before the end of the computation. Letting the GUI event loop run once allows it to change the cursor. (And upon testing, I see that Qt does not need this, probably because its version of setCursor triggers(?) the event loop.)


def release(self, event):
try: del self._pixmapBack
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/backends/backend_tkagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,7 @@ def release(self, event):

def set_cursor(self, cursor):
self.window.configure(cursor=cursord[cursor])
self.window.update_idletasks()

def _Button(self, text, file, command, extension='.gif'):
img_file = os.path.join(
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/backends/backend_wx.py
Original file line number Diff line number Diff line change
Expand Up @@ -1595,6 +1595,7 @@ def save_figure(self, *args):
def set_cursor(self, cursor):
cursor = wxc.Cursor(cursord[cursor])
self.canvas.SetCursor(cursor)
self.canvas.Update()

def release(self, event):
try:
Expand Down