Skip to content

Apply gtk3 background. #10298

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
Jul 1, 2018
Merged

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Jan 23, 2018

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. (gtk3agg behaves in the same way after #10297 is applied).

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

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.
@tacaswell tacaswell merged commit 51f6ef8 into matplotlib:master Jul 1, 2018
@anntzer anntzer deleted the gtk3-background branch July 1, 2018 05:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants