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

Skip to content

Simplify/improve check for pycairo in Gtk-based backends. #23347

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 1 commit into from
Jun 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions lib/matplotlib/backends/_backend_gtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@
_Backend, FigureManagerBase, NavigationToolbar2, TimerBase)
from matplotlib.backend_tools import Cursors

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


try:
gi.require_foreign("cairo")
except ImportError as e:
raise ImportError("Gtk-based backends require cairo") from e

_log = logging.getLogger(__name__)

backend_version = "%s.%s.%s" % (
Expand Down
12 changes: 3 additions & 9 deletions lib/matplotlib/backends/backend_gtk3agg.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import numpy as np

from .. import _api, cbook
try:
from . import backend_cairo
except ImportError as e:
raise ImportError('backend Gtk3Agg requires cairo') from e
from .. import _api, cbook, transforms
from . import backend_agg, backend_gtk3
from .backend_cairo import cairo
from .backend_gtk3 import Gtk, _BackendGTK3
from matplotlib import transforms

import cairo # Presence of cairo is already checked by _backend_gtk.


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

ctx = backend_cairo._to_context(ctx)

for bbox in bbox_queue:
x = int(bbox.x0)
y = h - int(bbox.y1)
Expand Down
9 changes: 2 additions & 7 deletions lib/matplotlib/backends/backend_gtk4agg.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import numpy as np

from .. import _api, cbook
try:
from . import backend_cairo
except ImportError as e:
raise ImportError('backend Gtk4Agg requires cairo') from e
from . import backend_agg, backend_gtk4
from .backend_cairo import cairo
from .backend_gtk4 import Gtk, _BackendGTK4

import cairo # Presence of cairo is already checked by _backend_gtk.


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

ctx = backend_cairo._to_context(ctx)

buf = cbook._unmultiplied_rgba8888_to_premultiplied_argb32(
np.asarray(self.get_renderer().buffer_rgba()))
height, width, _ = buf.shape
Expand Down