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 123da17

Browse filesBrowse files
authored
Merge pull request #19441 from anntzer/gtk3headless
Make backend_gtk3foo importable on headless environments.
2 parents 9ab4b73 + b909939 commit 123da17
Copy full SHA for 123da17

File tree

Expand file treeCollapse file tree

2 files changed

+19
-5
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+19
-5
lines changed
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
``backend_gtk3.cursord``
2+
~~~~~~~~~~~~~~~~~~~~~~~~
3+
This dict is deprecated, in order to make the module importable on headless
4+
environments.

‎lib/matplotlib/backends/backend_gtk3.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_gtk3.py
+15-5Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,15 @@
3737

3838
try:
3939
_display = Gdk.Display.get_default()
40-
cursord = {
40+
cursord = { # deprecated in Matplotlib 3.5.
4141
cursors.MOVE: Gdk.Cursor.new_from_name(_display, "move"),
4242
cursors.HAND: Gdk.Cursor.new_from_name(_display, "pointer"),
4343
cursors.POINTER: Gdk.Cursor.new_from_name(_display, "default"),
4444
cursors.SELECT_REGION: Gdk.Cursor.new_from_name(_display, "crosshair"),
4545
cursors.WAIT: Gdk.Cursor.new_from_name(_display, "wait"),
4646
}
4747
except TypeError as exc:
48-
# Happens when running headless. Convert to ImportError to cooperate with
49-
# backend switching.
50-
raise ImportError(exc) from exc
48+
cursord = {} # deprecated in Matplotlib 3.5.
5149

5250

5351
class TimerGTK3(TimerBase):
@@ -486,10 +484,22 @@ def set_message(self, s):
486484
escaped = GLib.markup_escape_text(s)
487485
self.message.set_markup(f'<small>{escaped}</small>')
488486

487+
@staticmethod
488+
@functools.lru_cache()
489+
def _mpl_to_gtk_cursor(mpl_cursor):
490+
name = {
491+
cursors.MOVE: "move",
492+
cursors.HAND: "pointer",
493+
cursors.POINTER: "default",
494+
cursors.SELECT_REGION: "crosshair",
495+
cursors.WAIT: "wait",
496+
}[mpl_cursor]
497+
return Gdk.Cursor.new_from_name(Gdk.Display.get_default(), name)
498+
489499
def set_cursor(self, cursor):
490500
window = self.canvas.get_property("window")
491501
if window is not None:
492-
window.set_cursor(cursord[cursor])
502+
window.set_cursor(self._mpl_to_gtk_cursor(cursor))
493503
Gtk.main_iteration()
494504

495505
def draw_rubberband(self, event, x0, y0, x1, y1):

0 commit comments

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