8000 Deprecate DraggableBase.artist_picker. · matplotlib/matplotlib@5e98493 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5e98493

Browse files
committed
Deprecate DraggableBase.artist_picker.
This method could previously be overridden in order to customize the artist's picker function when dragging it. However, the default picker of all artists is already checking whether the artist contain()s the event; moreover the picker is "global" for the artist so it stays set on it even after making it undraggable. Hence it is really just an artist's property and the user should just call artist.set_picker() if desired.
1 parent 68d5e2f commit 5e98493

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

doc/api/next_api_changes/deprecations.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,8 @@ The following parameters do not have any effect and are deprecated:
124124
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
125125
This method is deprecated. Use
126126
``ax.dataLim.set(Bbox.union([ax.dataLim, bounds]))`` instead.
127+
128+
``DraggableBase.artist_picker``
129+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
130+
This method is deprecated. If you previously reimplemented it in a subclass,
131+
set the artist's picker instead with `.Artist.set_picker`.

lib/matplotlib/offsetbox.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1697,11 +1697,7 @@ def update_offset(self, dx, dy):
16971697
the point where the mouse drag started.
16981698
'''
16991699
1700-
Optionally, you may override the following methods::
1701-
1702-
def artist_picker(self, artist, evt):
1703-
'''The picker method that will be used.'''
1704-
return self.ref_artist.contains(evt)
1700+
Optionally, you may override the following method::
17051701
17061702
def finalize_offset(self):
17071703
'''Called when the mouse is released.'''
@@ -1722,7 +1718,18 @@ def __init__(self, ref_artist, use_blit=False):
17221718
c2 = self.canvas.mpl_connect('pick_event', self.on_pick)
17231719
c3 = self.canvas.mpl_connect('button_release_event', self.on_release)
17241720

1725-
ref_artist.set_picker(self.artist_picker)
1721+
if not ref_artist.pickable():
1722+
ref_artist.set_picker(True)
1723+
with cbook._suppress_matplotlib_deprecation_warning():
1724+
if self.artist_picker != DraggableBase.artist_picker.__get__(self):
1725+
overridden_picker = self.artist_picker
1726+
else:
1727+
overridden_picker = None
1728+
if overridden_picker is not None:
1729+
cbook.warn_deprecated(
1730+
"3.3", name="artist_picker", obj_type="method",
1731+
addendum="Directly set the artist's picker if desired.")
1732+
ref_artist.set_picker(overridden_picker)
17261733
self.cids = [c2, c3]
17271734

17281735
def on_motion(self, evt):
@@ -1789,6 +1796,7 @@ def disconnect(self):
17891796
else:
17901797
self.canvas.mpl_disconnect(c1)
17911798

1799+
@cbook.deprecated("3.3", alternative="self.ref_artist.contains")
17921800
def artist_picker(self, artist, evt):
17931801
return self.ref_artist.contains(evt)
17941802

0 commit comments

Comments
 (0)
0