Skip to content

Commit ed324fc

Browse files
committed
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
1 parent 70e0ba8 commit ed324fc

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lib/matplotlib/backends/backend_gtk4.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ def __init__(self, figure=None):
7474
self.set_focusable(True)
7575

7676
css = Gtk.CssProvider()
77-
css.load_from_data(b".matplotlib-canvas { background-color: white; }")
77+
style = '.matplotlib-canvas { background-color: white; }'
78+
if Gtk.check_version(4, 9, 3) is None:
79+
css.load_from_data(style, -1)
80+
else:
81+
css.load_from_data(style.encode('utf-8'))
7882
style_ctx = self.get_style_context()
7983
style_ctx.add_provider(css, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
8084
style_ctx.add_class("matplotlib-canvas")

0 commit comments

Comments
 (0)