Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d007262

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 c19ebd6 commit d007262

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Deprecations
2+
````````````
3+
4+
The ``NavigationToolbar2GTK3.ctx`` attribute is deprecated.

lib/matplotlib/backends/backend_gtk3.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,11 @@ def __init__(self, canvas, window):
457457
self.win = window
458458
GObject.GObject.__init__(self)
459459
NavigationToolbar2.__init__(self, canvas)
460-
self.ctx = None
460+
461+
@cbook.deprecated("3.2")
462+
@property
463+
def ctx(self):
464+
return self.canvas.get_property("window").cairo_create()
461465

462466
def set_message(self, s):
463467
self.message.set_label(s)
@@ -469,7 +473,7 @@ def set_cursor(self, cursor):
469473
def draw_rubberband(self, event, x0, y0, x1, y1):
470474
# adapted from
471475
# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/189744
472-
self.ctx = self.canvas.get_property("window").cairo_create()
476+
ctx = self.canvas.get_property("window").cairo_create()
473477

474478
# todo: instead of redrawing the entire figure, copy the part of
475479
# the figure that was covered by the previous rubberband rectangle
@@ -482,11 +486,11 @@ def draw_rubberband(self, event, x0, y0, x1, y1):
482486
h = abs(y1 - y0)
483487
rect = [int(val) for val in (min(x0, x1), min(y0, y1), w, h)]
484488

485-
self.ctx.new_path()
486-
self.ctx.set_line_width(0.5)
487-
self.ctx.rectangle(rect[0], rect[1], rect[2], rect[3])
488-
self.ctx.set_source_rgb(0, 0, 0)
489-
self.ctx.stroke()
489+
ctx.new_path()
490+
ctx.set_line_width(0.5)
491+
ctx.rectangle(*rect)
492+
ctx.set_source_rgb(0, 0, 0)
493+
ctx.stroke()
490494

491495
def _init_toolbar(self):
492496
self.set_style(Gtk.ToolbarStyle.ICONS)

0 commit comments

Comments
 (0)