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

Skip to content

Commit 66e6842

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 8466da0 commit 66e6842

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
@@ -473,7 +473,11 @@ def __init__(self, canvas, window):
473473
self.win = window
474474
GObject.GObject.__init__(self)
475475
NavigationToolbar2.__init__(self, canvas)
476-
self.ctx = None
476+
477+
@cbook.deprecated("3.1")
478+
@property
479+
def ctx(self):
480+
return self.canvas.get_property("window").cairo_create()
477481

478482
def set_message(self, s):
479483
self.message.set_label(s)
@@ -484,7 +488,7 @@ def set_cursor(self, cursor):
484488

485489
def draw_rubberband(self, event, x0, y0, x1, y1):
486490
'adapted from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/189744'
487-
self.ctx = self.canvas.get_property("window").cairo_create()
491+
ctx = self.canvas.get_property("window").cairo_create()
488492

489493
# todo: instead of redrawing the entire figure, copy the part of
490494
# the figure that was covered by the previous rubberband rectangle
@@ -497,11 +501,11 @@ def draw_rubberband(self, event, x0, y0, x1, y1):
497501
h = abs(y1 - y0)
498502
rect = [int(val) for val in (min(x0, x1), min(y0, y1), w, h)]
499503

500-
self.ctx.new_path()
501-
self.ctx.set_line_width(0.5)
502-
self.ctx.rectangle(rect[0], rect[1], rect[2], rect[3])
503-
self.ctx.set_source_rgb(0, 0, 0)
504-
self.ctx.stroke()
504+
ctx.new_path()
505+
ctx.set_line_width(0.5)
506+
ctx.rectangle(*rect)
507+
ctx.set_source_rgb(0, 0, 0)
508+
ctx.stroke()
505509

506510
def _init_toolbar(self):
507511
self.set_style(Gtk.ToolbarStyle.ICONS)

0 commit comments

Comments
 (0)