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

Skip to content

Commit 5587bb4

Browse files
committed
Privatize more attributes, which are not expected to be used by users.
1 parent 524f2b7 commit 5587bb4

1 file changed

Lines changed: 47 additions & 58 deletions

File tree

lib/matplotlib/widgets.py

Lines changed: 47 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,11 +2022,19 @@ def __init__(self, ax, onselect, direction, minspan=0, useblit=False,
20222022
line_props=props,
20232023
useblit=self.useblit)
20242024

2025-
self.active_handle = None
2025+
self._active_handle = None
20262026

20272027
if self.interactive:
20282028
self.artists.extend([line for line in self._edge_handles.artists])
20292029

2030+
rect = _api.deprecate_privatize_attribute("3.5")
2031+
2032+
rectprops = _api.deprecate_privatize_attribute("3.5")
2033+
2034+
active_handle = _api.deprecate_privatize_attribute("3.5")
2035+
2036+
pressv = _api.deprecate_privatize_attribute("3.5")
2037+
20302038
def new_axes(self, ax):
20312039
"""Set SpanSelector to operate on a new Axes."""
20322040
self.ax = ax
@@ -2056,9 +2064,9 @@ def _press(self, event):
20562064
if self.interactive and self._rect.get_visible():
20572065
self._set_active_handle(event)
20582066
else:
2059-
self.active_handle = None
2067+
self._active_handle = None
20602068

2061-
if self.active_handle is None or not self.interactive:
2069+
if self._active_handle is None or not self.interactive:
20622070
# Clear previous rectangle before drawing new rectangle.
20632071
self.update()
20642072

@@ -2072,26 +2080,6 @@ def _press(self, event):
20722080

20732081
return False
20742082

2075-
@_api.deprecated("3.5")
2076-
@property
2077-
def rect(self):
2078-
return self._rect
2079-
2080-
@_api.deprecated("3.5")
2081-
@property
2082-
def pressv(self):
2083-
return self._pressv
2084-
2085-
@_api.deprecated("3.5")
2086-
@pressv.setter
2087-
def pressv(self, value):
2088-
self._pressv = value
2089-
2090-
@_api.deprecated("3.5")
2091-
@property
2092-
def rectprops(self):
2093-
return self._rectprops
2094-
20952083
@property
20962084
def direction(self):
20972085
"""Direction of the span selector: 'vertical' or 'horizontal'."""
@@ -2127,18 +2115,18 @@ def _onmove(self, event):
21272115
vpress = self.eventpress.ydata
21282116

21292117
# move existing span
2130-
# When "dragging from anywhere", the `self.active_handle` is set to 'C'
2118+
# When "dragging from anywhere", the `self._active_handle` is set to 'C'
21312119
# in _set_active_handle (match notation used in the RectangleSelector)
2132-
if self.active_handle == 'C' and self._extents_on_press is not None:
2120+
if self._active_handle == 'C' and self._extents_on_press is not None:
21332121
vmin, vmax = self._extents_on_press
21342122
dv = v - vpress
21352123
vmin += dv
21362124
vmax += dv
21372125

21382126
# resize an existing shape
2139-
elif self.active_handle and self.active_handle != 'C':
2127+
elif self._active_handle and self._active_handle != 'C':
21402128
vmin, vmax = self._extents_on_press
2141-
if self.active_handle == 'min':
2129+
if self._active_handle == 'min':
21422130
vmin = v
21432131
else:
21442132
vmax = v
@@ -2173,20 +2161,20 @@ def _set_active_handle(self, event):
21732161
# Prioritise center handle over other handles
21742162
# Use 'C' to match the notation used in the RectangleSelector
21752163
if 'move' in self.state:
2176-
self.active_handle = 'C'
2164+
self._active_handle = 'C'
21772165
elif e_dist > self.maxdist:
21782166
# Not close to any handles
2179-
self.active_handle = None
2167+
self._active_handle = None
21802168
if self.drag_from_anywhere and self._contains(event):
21812169
# Check if we've clicked inside the region
2182-
self.active_handle = 'C'
2170+
self._active_handle = 'C'
21832171
self._extents_on_press = self.extents
21842172
else:
2185-
self.active_handle = None
2173+
self._active_handle = None
21862174
return
21872175
else:
21882176
# Closest to an edge handle
2189-
self.active_handle = self._edge_order[e_idx]
2177+
self._active_handle = self._edge_order[e_idx]
21902178

21912179
# Save coordinates of rectangle at the start of handle movement.
21922180
self._extents_on_press = self.extents
@@ -2511,7 +2499,7 @@ def onselect(eclick: MouseEvent, erelease: MouseEvent)
25112499

25122500
_api.check_in_list(['data', 'pixels'], spancoords=spancoords)
25132501
self.spancoords = spancoords
2514-
self.drawtype = drawtype
2502+
self._drawtype = drawtype
25152503

25162504
self.maxdist = maxdist
25172505

@@ -2536,7 +2524,7 @@ def onselect(eclick: MouseEvent, erelease: MouseEvent)
25362524
marker_props=props,
25372525
useblit=self.useblit)
25382526

2539-
self.active_handle = None
2527+
self._active_handle = None
25402528

25412529
self.artists = [self._to_draw, self._center_handle.artist,
25422530
self._corner_handles.artist,
@@ -2547,10 +2535,11 @@ def onselect(eclick: MouseEvent, erelease: MouseEvent)
25472535

25482536
self._extents_on_press = None
25492537

2550-
@_api.deprecated("3.5")
2551-
@property
2552-
def to_draw(self):
2553-
return self._to_draw
2538+
to_draw = _api.deprecate_privatize_attribute("3.5")
2539+
2540+
drawtype = _api.deprecate_privatize_attribute("3.5")
2541+
2542+
active_handle = _api.deprecate_privatize_attribute("3.5")
25542543

25552544
def _press(self, event):
25562545
"""Button press event handler."""
@@ -2559,9 +2548,9 @@ def _press(self, event):
25592548
if self.interactive and self._to_draw.get_visible():
25602549
self._set_active_handle(event)
25612550
else:
2562-
self.active_handle = None
2551+
self._active_handle = None
25632552

2564-
if self.active_handle is None or not self.interactive:
2553+
if self._active_handle is None or not self.interactive:
25652554
# Clear previous rectangle before drawing new rectangle.
25662555
self.update()
25672556

@@ -2601,7 +2590,7 @@ def _release(self, event):
26012590
spancoords=self.spancoords)
26022591
# check if drawn distance (if it exists) is not too small in
26032592
# either x or y-direction
2604-
if (self.drawtype != 'none'
2593+
if (self._drawtype != 'none'
26052594
and (self.minspanx is not None and spanx < self.minspanx
26062595
or self.minspany is not None and spany < self.minspany)):
26072596
for artist in self.artists:
@@ -2618,15 +2607,15 @@ def _release(self, event):
26182607
def _onmove(self, event):
26192608
"""Motion notify event handler."""
26202609
# resize an existing shape
2621-
if self.active_handle and self.active_handle != 'C':
2610+
if self._active_handle and self._active_handle != 'C':
26222611
x0, x1, y0, y1 = self._extents_on_press
2623-
if self.active_handle in ['E', 'W'] + self._corner_order:
2612+
if self._active_handle in ['E', 'W'] + self._corner_order:
26242613
x1 = event.xdata
2625-
if self.active_handle in ['N', 'S'] + self._corner_order:
2614+
if self._active_handle in ['N', 'S'] + self._corner_order:
26262615
y1 = event.ydata
26272616

26282617
# move existing shape
2629-
elif (('move' in self.state or self.active_handle == 'C' or
2618+
elif (('move' in self.state or self._active_handle == 'C' or
26302619
(self.drag_from_anywhere and self._contains(event))) and
26312620
self._extents_on_press is not None):
26322621
x0, x1, y0, y1 = self._extents_on_press
@@ -2673,7 +2662,7 @@ def _onmove(self, event):
26732662

26742663
@property
26752664
def _rect_bbox(self):
2676-
if self.drawtype == 'box':
2665+
if self._drawtype == 'box':
26772666
x0 = self._to_draw.get_x()
26782667
y0 = self._to_draw.get_y()
26792668
width = self._to_draw.get_width()
@@ -2742,13 +2731,13 @@ def _draw_shape(self, extents):
27422731
xmax = min(xmax, xlim[1])
27432732
ymax = min(ymax, ylim[1])
27442733

2745-
if self.drawtype == 'box':
2734+
if self._drawtype == 'box':
27462735
self._to_draw.set_x(xmin)
27472736
self._to_draw.set_y(ymin)
27482737
self._to_draw.set_width(xmax - xmin)
27492738
self._to_draw.set_height(ymax - ymin)
27502739

2751-
elif self.drawtype == 'line':
2740+
elif self._drawtype == 'line':
27522741
self._to_draw.set_data([xmin, xmax], [ymin, ymax])
27532742

27542743
def _set_active_handle(self, event):
@@ -2759,34 +2748,34 @@ def _set_active_handle(self, event):
27592748
m_idx, m_dist = self._center_handle.closest(event.x, event.y)
27602749

27612750
if 'move' in self.state:
2762-
self.active_handle = 'C'
2751+
self._active_handle = 'C'
27632752
self._extents_on_press = self.extents
27642753
# Set active handle as closest handle, if mouse click is close enough.
27652754
elif m_dist < self.maxdist * 2:
27662755
# Prioritise center handle over other handles
2767-
self.active_handle = 'C'
2756+
self._active_handle = 'C'
27682757
elif c_dist > self.maxdist and e_dist > self.maxdist:
27692758
# Not close to any handles
27702759
if self.drag_from_anywhere and self._contains(event):
27712760
# Check if we've clicked inside the region
2772-
self.active_handle = 'C'
2761+
self._active_handle = 'C'
27732762
self._extents_on_press = self.extents
27742763
else:
2775-
self.active_handle = None
2764+
self._active_handle = None
27762765
return
27772766
elif c_dist < e_dist:
27782767
# Closest to a corner handle
2779-
self.active_handle = self._corner_order[c_idx]
2768+
self._active_handle = self._corner_order[c_idx]
27802769
else:
27812770
# Closest to an edge handle
2782-
self.active_handle = self._edge_order[e_idx]
2771+
self._active_handle = self._edge_order[e_idx]
27832772

27842773
# Save coordinates of rectangle at the start of handle movement.
27852774
x0, x1, y0, y1 = self.extents
27862775
# Switch variables so that only x1 and/or y1 are updated on move.
2787-
if self.active_handle in ['W', 'SW', 'NW']:
2776+
if self._active_handle in ['W', 'SW', 'NW']:
27882777
x0, x1 = x1, event.xdata
2789-
if self.active_handle in ['N', 'NW', 'NE']:
2778+
if self._active_handle in ['N', 'NW', 'NE']:
27902779
y0, y1 = y1, event.ydata
27912780
self._extents_on_press = x0, x1, y0, y1
27922781

@@ -2858,7 +2847,7 @@ def _draw_shape(self, extents):
28582847
a = (xmax - xmin) / 2.
28592848
b = (ymax - ymin) / 2.
28602849

2861-
if self.drawtype == 'box':
2850+
if self._drawtype == 'box':
28622851
self._to_draw.center = center
28632852
self._to_draw.width = 2 * a
28642853
self._to_draw.height = 2 * b
@@ -2870,7 +2859,7 @@ def _draw_shape(self, extents):
28702859

28712860
@property
28722861
def _rect_bbox(self):
2873-
if self.drawtype == 'box':
2862+
if self._drawtype == 'box':
28742863
x, y = self._to_draw.center
28752864
width = self._to_draw.width
28762865
height = self._to_draw.height

0 commit comments

Comments
 (0)