From ed324fcca8af0323325c3a610fd5d9828afa9927 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 21 Feb 2023 20:52:42 -0500 Subject: [PATCH] Fix setting CSS with latest GTK4 In the upcoming 4.10 release, the type annotation was fixed [1]. There may be some overrides added in PyGObject [2] to avoid this difference, but we don't depend on a specific version of it to be able to rely on that (and it's not released yet.) This code should work with the override as well. [1] https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/5441 [2] https://gitlab.gnome.org/GNOME/pygobject/-/merge_requests/231 --- lib/matplotlib/backends/backend_gtk4.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/backends/backend_gtk4.py b/lib/matplotlib/backends/backend_gtk4.py index 8628e14de096..328819292018 100644 --- a/lib/matplotlib/backends/backend_gtk4.py +++ b/lib/matplotlib/backends/backend_gtk4.py @@ -74,7 +74,11 @@ def __init__(self, figure=None): self.set_focusable(True) css = Gtk.CssProvider() - css.load_from_data(b".matplotlib-canvas { background-color: white; }") + style = '.matplotlib-canvas { background-color: white; }' + if Gtk.check_version(4, 9, 3) is None: + css.load_from_data(style, -1) + else: + css.load_from_data(style.encode('utf-8')) style_ctx = self.get_style_context() style_ctx.add_provider(css, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION) style_ctx.add_class("matplotlib-canvas")