|
37 | 37 |
|
38 | 38 | try:
|
39 | 39 | _display = Gdk.Display.get_default()
|
40 |
| - cursord = { |
| 40 | + cursord = { # deprecated in Matplotlib 3.5. |
41 | 41 | cursors.MOVE: Gdk.Cursor.new_from_name(_display, "move"),
|
42 | 42 | cursors.HAND: Gdk.Cursor.new_from_name(_display, "pointer"),
|
43 | 43 | cursors.POINTER: Gdk.Cursor.new_from_name(_display, "default"),
|
44 | 44 | cursors.SELECT_REGION: Gdk.Cursor.new_from_name(_display, "crosshair"),
|
45 | 45 | cursors.WAIT: Gdk.Cursor.new_from_name(_display, "wait"),
|
46 | 46 | }
|
47 | 47 | 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. |
51 | 49 |
|
52 | 50 |
|
53 | 51 | class TimerGTK3(TimerBase):
|
@@ -486,10 +484,22 @@ def set_message(self, s):
|
486 | 484 | escaped = GLib.markup_escape_text(s)
|
487 | 485 | self.message.set_markup(f'<small>{escaped}</small>')
|
488 | 486 |
|
| 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 | + |
489 | 499 | def set_cursor(self, cursor):
|
490 | 500 | window = self.canvas.get_property("window")
|
491 | 501 | if window is not None:
|
492 |
| - window.set_cursor(cursord[cursor]) |
| 502 | + window.set_cursor(self._mpl_to_gtk_cursor(cursor)) |
493 | 503 | Gtk.main_iteration()
|
494 | 504 |
|
495 | 505 | def draw_rubberband(self, event, x0, y0, x1, y1):
|
|
0 commit comments