Skip to content

Commit 91850cc

Browse files
committed
Apply gtk3 background.
Currently, gtk3 widget backgrounds are not being applied (which only matters if the figure patch is partially transparent). The lines added by this PR are equivalent to the call to `painter.eraseRect(self.rect())` in the qt5agg backend (compare http://doc.qt.io/qt-5/qpainter.html#eraseRect and https://developer.gnome.org/gtk3/stable/GtkStyleContext.html#gtk-render-background). As an example, run import os; os.environ["MPLBACKEND"] = "gtk3cairo" from pylab import * from gi.repository import Gtk rcParams["figure.facecolor"] = (0, 0, 0, 0) css = Gtk.CssProvider() css.load_from_data(b"* {background-color: red;}") gcf().canvas.get_style_context().add_provider( css, Gtk.STYLE_PROVIDER_PRIORITY_USER) gca() show() Without this patch, the red background is not drawn.
1 parent a0994d3 commit 91850cc

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/matplotlib/backends/backend_gtk3agg.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from . import backend_agg, backend_cairo, backend_gtk3
55
from ._gtk3_compat import gi
66
from .backend_cairo import cairo
7-
from .backend_gtk3 import _BackendGTK3
7+
from .backend_gtk3 import Gtk, _BackendGTK3
88
from matplotlib import transforms
99

1010
# The following combinations are allowed:
@@ -38,6 +38,10 @@ def on_draw_event(self, widget, ctx):
3838

3939
if not len(self._bbox_queue):
4040
self._render_figure(w, h)
41+
Gtk.render_background(
42+
self.get_style_context(), ctx,
43+
allocation.x, allocation.y,
44+
allocation.width, allocation.height)
4145
bbox_queue = [transforms.Bbox([[0, 0], [w, h]])]
4246
else:
4347
bbox_queue = self._bbox_queue

lib/matplotlib/backends/backend_gtk3cairo.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from . import backend_cairo, backend_gtk3
22
from ._gtk3_compat import gi
33
from .backend_cairo import cairo
4-
from .backend_gtk3 import _BackendGTK3
4+
from .backend_gtk3 import Gtk, _BackendGTK3
55
from matplotlib.backend_bases import cursors
66

77

@@ -39,6 +39,9 @@ def on_draw_event(self, widget, ctx):
3939
# toolbar.set_cursor(cursors.WAIT)
4040
self._renderer.set_context(ctx)
4141
allocation = self.get_allocation()
42+
Gtk.render_background(
43+
self.get_style_context(), ctx,
44+
allocation.x, allocation.y, allocation.width, allocation.height)
4245
self._render_figure(allocation.width, allocation.height)
4346
# if toolbar:
4447
# toolbar.set_cursor(toolbar._lastCursor)

0 commit comments

Comments
 (0)