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

Skip to content

Commit 3eadeac

Browse files
authored
Merge pull request #23347 from anntzer/gtkcairo
Simplify/improve check for pycairo in Gtk-based backends.
2 parents 0d39a4f + 01c3ce1 commit 3eadeac

File tree

3 files changed

+11
-16
lines changed

3 files changed

+11
-16
lines changed

lib/matplotlib/backends/_backend_gtk.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,17 @@
1212
_Backend, FigureManagerBase, NavigationToolbar2, TimerBase)
1313
from matplotlib.backend_tools import Cursors
1414

15+
import gi
1516
# The GTK3/GTK4 backends will have already called `gi.require_version` to set
1617
# the desired GTK.
1718
from gi.repository import Gdk, Gio, GLib, Gtk
1819

1920

21+
try:
22+
gi.require_foreign("cairo")
23+
except ImportError as e:
24+
raise ImportError("Gtk-based backends require cairo") from e
25+
2026
_log = logging.getLogger(__name__)
2127

2228
backend_version = "%s.%s.%s" % (

lib/matplotlib/backends/backend_gtk3agg.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
import numpy as np
22

3-
from .. import _api, cbook
4-
try:
5-
from . import backend_cairo
6-
except ImportError as e:
7-
raise ImportError('backend Gtk3Agg requires cairo') from e
3+
from .. import _api, cbook, transforms
84
from . import backend_agg, backend_gtk3
9-
from .backend_cairo import cairo
105
from .backend_gtk3 import Gtk, _BackendGTK3
11-
from matplotlib import transforms
6+
7+
import cairo # Presence of cairo is already checked by _backend_gtk.
128

139

1410
class FigureCanvasGTK3Agg(backend_gtk3.FigureCanvasGTK3,
@@ -32,8 +28,6 @@ def on_draw_event(self, widget, ctx):
3228
else:
3329
bbox_queue = self._bbox_queue
3430

35-
ctx = backend_cairo._to_context(ctx)
36-
3731
for bbox in bbox_queue:
3832
x = int(bbox.x0)
3933
y = h - int(bbox.y1)

lib/matplotlib/backends/backend_gtk4agg.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import numpy as np
22

33
from .. import _api, cbook
4-
try:
5-
from . import backend_cairo
6-
except ImportError as e:
7-
raise ImportError('backend Gtk4Agg requires cairo') from e
84
from . import backend_agg, backend_gtk4
9-
from .backend_cairo import cairo
105
from .backend_gtk4 import Gtk, _BackendGTK4
116

7+
import cairo # Presence of cairo is already checked by _backend_gtk.
8+
129

1310
class FigureCanvasGTK4Agg(backend_gtk4.FigureCanvasGTK4,
1411
backend_agg.FigureCanvasAgg):
@@ -24,8 +21,6 @@ def on_draw_event(self, widget, ctx):
2421
allocation.x, allocation.y,
2522
allocation.width, allocation.height)
2623

27-
ctx = backend_cairo._to_context(ctx)
28-
2924
buf = cbook._unmultiplied_rgba8888_to_premultiplied_argb32(
3025
np.asarray(self.get_renderer().buffer_rgba()))
3126
height, width, _ = buf.shape

0 commit comments

Comments
 (0)