Skip to content

Commit ed6be7a

Browse files
committed
Deprecate various wx Toolbar attributes.
These are clearly internal helpers involved in zoombox drawing, and will likely be changed soon anyways.
1 parent 100c7cf commit ed6be7a

File tree

4 files changed

+71
-35
lines changed

4 files changed

+71
-35
lines changed

doc/api/api_changes_3.3/deprecations.rst

+5
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,11 @@ NavigationToolbar2QT.ctx
392392
~~~~~~~~~~~~~~~~~~~~~~~~
393393
This attribute is deprecated.
394394

395+
NavigationToolbar2Wx attributes
396+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
397+
The ``prevZoomRect``, ``retinaFix``, ``savedRetinaImage``, ``wxoverlay``,
398+
``zoomAxes``, ``zoomStartX``, and ``zoomStartY`` attributes are deprecated.
399+
395400
NavigationToolbar2.press and .release
396401
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
397402
These methods were called when pressing or releasing a mouse button,

lib/matplotlib/backends/backend_wx.py

+42-34
Original file line numberDiff line numberDiff line change
@@ -1126,12 +1126,20 @@ def __init__(self, canvas):
11261126

11271127
NavigationToolbar2.__init__(self, canvas)
11281128
self._idle = True
1129-
self.prevZoomRect = None
1129+
self._prevZoomRect = None
11301130
# for now, use alternate zoom-rectangle drawing on all
11311131
# Macs. N.B. In future versions of wx it may be possible to
11321132
# detect Retina displays with window.GetContentScaleFactor()
11331133
# and/or dc.GetContentScaleFactor()
1134-
self.retinaFix = 'wxMac' in wx.PlatformInfo
1134+
self._retinaFix = 'wxMac' in wx.PlatformInfo
1135+
1136+
prevZoomRect = cbook._deprecate_privatize_attribute("3.3")
1137+
retinaFix = cbook._deprecate_privatize_attribute("3.3")
1138+
savedRetinaImage = cbook._deprecate_privatize_attribute("3.3")
1139+
wxoverlay = cbook._deprecate_privatize_attribute("3.3")
1140+
zoomAxes = cbook._deprecate_privatize_attribute("3.3")
1141+
zoomStartX = cbook._deprecate_privatize_attribute("3.3")
1142+
zoomStartY = cbook._deprecate_privatize_attribute("3.3")
11351143

11361144
def get_canvas(self, frame, fig):
11371145
return type(self.canvas)(frame, -1, fig)
@@ -1201,53 +1209,53 @@ def set_cursor(self, cursor):
12011209
def press_zoom(self, event):
12021210
super().press_zoom(event)
12031211
if self.mode.name == 'ZOOM':
1204-
if not self.retinaFix:
1205-
self.wxoverlay = wx.Overlay()
1212+
if not self._retinaFix:
1213+
self._wxoverlay = wx.Overlay()
12061214
else:
12071215
if event.inaxes is not None:
1208-
self.savedRetinaImage = self.canvas.copy_from_bbox(
1216+
self._savedRetinaImage = self.canvas.copy_from_bbox(
12091217
event.inaxes.bbox)
1210-
self.zoomStartX = event.xdata
1211-
self.zoomStartY = event.ydata
1212-
self.zoomAxes = event.inaxes
1218+
self._zoomStartX = event.xdata
1219+
self._zoomStartY = event.ydata
1220+
self._zoomAxes = event.inaxes
12131221

12141222
def release_zoom(self, event):
12151223
super().release_zoom(event)
12161224
if self.mode.name == 'ZOOM':
12171225
# When the mouse is released we reset the overlay and it
12181226
# restores the former content to the window.
1219-
if not self.retinaFix:
1220-
self.wxoverlay.Reset()
1221-
del self.wxoverlay
1227+
if not self._retinaFix:
1228+
self._wxoverlay.Reset()
1229+
del self._wxoverlay
12221230
else:
1223-
del self.savedRetinaImage
1224-
if self.prevZoomRect:
1225-
self.prevZoomRect.pop(0).remove()
1226-
self.prevZoomRect = None
1227-
if self.zoomAxes:
1228-
self.zoomAxes = None
1231+
del self._savedRetinaImage
1232+
if self._prevZoomRect:
1233+
self._prevZoomRect.pop(0).remove()
1234+
self._prevZoomRect = None
1235+
if self._zoomAxes:
1236+
self._zoomAxes = None
12291237

12301238
def draw_rubberband(self, event, x0, y0, x1, y1):
1231-
if self.retinaFix: # On Macs, use the following code
1239+
if self._retinaFix: # On Macs, use the following code
12321240
# wx.DCOverlay does not work properly on Retina displays.
12331241
rubberBandColor = '#C0C0FF'
1234-
if self.prevZoomRect:
1235-
self.prevZoomRect.pop(0).remove()
1236-
self.canvas.restore_region(self.savedRetinaImage)
1237-
X0, X1 = self.zoomStartX, event.xdata
1238-
Y0, Y1 = self.zoomStartY, event.ydata
1242+
if self._prevZoomRect:
1243+
self._prevZoomRect.pop(0).remove()
1244+
self.canvas.restore_region(self._savedRetinaImage)
1245+
X0, X1 = self._zoomStartX, event.xdata
1246+
Y0, Y1 = self._zoomStartY, event.ydata
12391247
lineX = (X0, X0, X1, X1, X0)
12401248
lineY = (Y0, Y1, Y1, Y0, Y0)
1241-
self.prevZoomRect = self.zoomAxes.plot(
1249+
self._prevZoomRect = self._zoomAxes.plot(
12421250
lineX, lineY, '-', color=rubberBandColor)
1243-
self.zoomAxes.draw_artist(self.prevZoomRect[0])
1244-
self.canvas.blit(self.zoomAxes.bbox)
1251+
self._zoomAxes.draw_artist(self._prevZoomRect[0])
1252+
self.canvas.blit(self._zoomAxes.bbox)
12451253
return
12461254

12471255
# Use an Overlay to draw a rubberband-like bounding box.
12481256

12491257
dc = wx.ClientDC(self.canvas)
1250-
odc = wx.DCOverlay(self.wxoverlay, dc)
1258+
odc = wx.DCOverlay(self._wxoverlay, dc)
12511259
odc.Clear()
12521260

12531261
# Mac's DC is already the same as a GCDC, and it causes
@@ -1439,14 +1447,14 @@ def set_cursor(self, cursor):
14391447
class RubberbandWx(backend_tools.RubberbandBase):
14401448
def __init__(self, *args, **kwargs):
14411449
backend_tools.RubberbandBase.__init__(self, *args, **kwargs)
1442-
self.wxoverlay = None
1450+
self._wxoverlay = None
14431451

14441452
def draw_rubberband(self, x0, y0, x1, y1):
14451453
# Use an Overlay to draw a rubberband-like bounding box.
1446-
if self.wxoverlay is None:
1447-
self.wxoverlay = wx.Overlay()
1454+
if self._wxoverlay is None:
1455+
self._wxoverlay = wx.Overlay()
14481456
dc = wx.ClientDC(self.canvas)
1449-
odc = wx.DCOverlay(self.wxoverlay, dc)
1457+
odc = wx.DCOverlay(self._wxoverlay, dc)
14501458
odc.Clear()
14511459

14521460
dc = wx.GCDC(dc)
@@ -1477,10 +1485,10 @@ def draw_rubberband(self, x0, y0, x1, y1):
14771485
dc.DrawRectangle(rect)
14781486

14791487
def remove_rubberband(self):
1480-
if self.wxoverlay is None:
1488+
if self._wxoverlay is None:
14811489
return
1482-
self.wxoverlay.Reset()
1483-
self.wxoverlay = None
1490+
self._wxoverlay.Reset()
1491+
self._wxoverlay = None
14841492

14851493
else:
14861494
# on Mac OS retina displays DCOverlay does not work

lib/matplotlib/cbook/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from .deprecation import (
3232
deprecated, warn_deprecated,
3333
_rename_parameter, _delete_parameter, _make_keyword_only,
34-
_deprecate_method_override,
34+
_deprecate_method_override, _deprecate_privatize_attribute,
3535
_suppress_matplotlib_deprecation_warning,
3636
MatplotlibDeprecationWarning, mplDeprecation)
3737

lib/matplotlib/cbook/deprecation.py

+23
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,29 @@ def wrapper(*args, **kwargs):
251251
return deprecate
252252

253253

254+
class _deprecate_privatize_attribute:
255+
"""
256+
Helper to deprecate public access to an attribute.
257+
258+
This helper should only be used at class scope, as follows::
259+
260+
class Foo:
261+
attr = _deprecate_privatize_attribute(*args, **kwargs)
262+
263+
were *all* parameters are forwarded to `deprecate`. This form makes
264+
``attr`` a property which forwards access to ``self._attr`` (same name but
265+
with a leading underscore), with a deprecation warning. Note that the
266+
attribute name is derived from *the name this helper is assigned to*.
267+
"""
268+
269+
def __init__(self, *args, **kwargs):
270+
self.deprecator = deprecated(*args, **kwargs)
271+
272+
def __set_name__(self, owner, name):
273+
setattr(owner, name, self.deprecator(
274+
property(lambda self: getattr(self, f"_{name}")), name=name))
275+
276+
254277
def _rename_parameter(since, old, new, func=None):
255278
"""
256279
Decorator indicating that parameter *old* of *func* is renamed to *new*.

0 commit comments

Comments
 (0)