Blob Blame History Raw
From 49484f456c93830c25dc7d4afe2110da8450a485 Mon Sep 17 00:00:00 2001
From: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Date: Tue, 21 Feb 2023 20:52:42 -0500
Subject: [PATCH 6/7] 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

Signed-off-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
---
 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 8628e14de0..3288192920 100644
--- a/lib/matplotlib/backends/backend_gtk4.py
+++ b/lib/matplotlib/backends/backend_gtk4.py
@@ -74,7 +74,11 @@ class FigureCanvasGTK4(_FigureCanvasGTK, Gtk.DrawingArea):
         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")
-- 
2.39.2