From c5946e1c9839a4ef98d834787618180feb1db5bf Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Thu, 10 Jan 2019 11:46:47 +0100 Subject: [PATCH] Deprecate NavigationToolbar2GTK3.ctx. No alternative documented: messing with the window cairo context is quite low level; if you're doing that, creating the context should not be that hard. --- doc/api/api_changes_3.3/deprecations.rst | 4 ++++ lib/matplotlib/backends/backend_gtk3.py | 18 +++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/doc/api/api_changes_3.3/deprecations.rst b/doc/api/api_changes_3.3/deprecations.rst index ab3b3323030a..8cb2ef56157c 100644 --- a/doc/api/api_changes_3.3/deprecations.rst +++ b/doc/api/api_changes_3.3/deprecations.rst @@ -373,6 +373,10 @@ These attributes are deprecated. In order to access the parent window, use also be accessible as ``toolbar.parent()``. The base directory to the icons is ``os.path.join(mpl.get_data_path(), "images")``. +NavigationToolbar2QT.ctx +~~~~~~~~~~~~~~~~~~~~~~~~ +This attribute is deprecated. + Path helpers in :mod:`.bezier` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/lib/matplotlib/backends/backend_gtk3.py b/lib/matplotlib/backends/backend_gtk3.py index 237df2355c18..52d7012b469c 100644 --- a/lib/matplotlib/backends/backend_gtk3.py +++ b/lib/matplotlib/backends/backend_gtk3.py @@ -452,7 +452,11 @@ def __init__(self, canvas, window): self.win = window GObject.GObject.__init__(self) NavigationToolbar2.__init__(self, canvas) - self.ctx = None + + @cbook.deprecated("3.3") + @property + def ctx(self): + return self.canvas.get_property("window").cairo_create() def set_message(self, s): self.message.set_label(s) @@ -464,7 +468,7 @@ def set_cursor(self, cursor): def draw_rubberband(self, event, x0, y0, x1, y1): # adapted from # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/189744 - self.ctx = self.canvas.get_property("window").cairo_create() + ctx = self.canvas.get_property("window").cairo_create() # todo: instead of redrawing the entire figure, copy the part of # the figure that was covered by the previous rubberband rectangle @@ -477,11 +481,11 @@ def draw_rubberband(self, event, x0, y0, x1, y1): h = abs(y1 - y0) rect = [int(val) for val in (min(x0, x1), min(y0, y1), w, h)] - self.ctx.new_path() - self.ctx.set_line_width(0.5) - self.ctx.rectangle(rect[0], rect[1], rect[2], rect[3]) - self.ctx.set_source_rgb(0, 0, 0) - self.ctx.stroke() + ctx.new_path() + ctx.set_line_width(0.5) + ctx.rectangle(*rect) + ctx.set_source_rgb(0, 0, 0) + ctx.stroke() def _init_toolbar(self): self.set_style(Gtk.ToolbarStyle.ICONS)