Skip to content

Commit c5946e1

Browse files
committed
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.
1 parent 3232f58 commit c5946e1

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

doc/api/api_changes_3.3/deprecations.rst

+4
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,10 @@ These attributes are deprecated. In order to access the parent window, use
373373
also be accessible as ``toolbar.parent()``. The base directory to the icons
374374
is ``os.path.join(mpl.get_data_path(), "images")``.
375375

376+
NavigationToolbar2QT.ctx
377+
~~~~~~~~~~~~~~~~~~~~~~~~
378+
This attribute is deprecated.
379+
376380
Path helpers in :mod:`.bezier`
377381
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
378382

lib/matplotlib/backends/backend_gtk3.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,11 @@ def __init__(self, canvas, window):
452452
self.win = window
453453
GObject.GObject.__init__(self)
454454
NavigationToolbar2.__init__(self, canvas)
455-
self.ctx = None
455+
456+
@cbook.deprecated("3.3")
457+
@property
458+
def ctx(self):
459+
return self.canvas.get_property("window").cairo_create()
456460

457461
def set_message(self, s):
458462
self.message.set_label(s)
@@ -464,7 +468,7 @@ def set_cursor(self, cursor):
464468
def draw_rubberband(self, event, x0, y0, x1, y1):
465469
# adapted from
466470
# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/189744
467-
self.ctx = self.canvas.get_property("window").cairo_create()
471+
ctx = self.canvas.get_property("window").cairo_create()
468472

469473
# todo: instead of redrawing the entire figure, copy the part of
470474
# the figure that was covered by the previous rubberband rectangle
@@ -477,11 +481,11 @@ def draw_rubberband(self, event, x0, y0, x1, y1):
477481
h = abs(y1 - y0)
478482
rect = [int(val) for val in (min(x0, x1), min(y0, y1), w, h)]
479483

480-
self.ctx.new_path()
481-
self.ctx.set_line_width(0.5)
482-
self.ctx.rectangle(rect[0], rect[1], rect[2], rect[3])
483-
self.ctx.set_source_rgb(0, 0, 0)
484-
self.ctx.stroke()
484+
ctx.new_path()
485+
ctx.set_line_width(0.5)
486+
ctx.rectangle(*rect)
487+
ctx.set_source_rgb(0, 0, 0)
488+
ctx.stroke()
485489

486490
def _init_toolbar(self):
487491
self.set_style(Gtk.ToolbarStyle.ICONS)

0 commit comments

Comments
 (0)