Skip to content

Deprecate DraggableBase.artist_picker. #16107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/api/next_api_changes/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,8 @@ The change from "nonpos" to "nonpositive" also affects `~.scale.LogTransform`,

To use *different* bases for the x-axis and y-axis of a `~.Axes.loglog` plot,
use e.g. ``ax.set_xscale("log", base=10); ax.set_yscale("log", base=2)``.

``DraggableBase.artist_picker``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This method is deprecated. If you previously reimplemented it in a subclass,
set the artist's picker instead with `.Artist.set_picker`.
20 changes: 14 additions & 6 deletions lib/matplotlib/offsetbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -1694,11 +1694,7 @@ def update_offset(self, dx, dy):
the point where the mouse drag started.
'''

Optionally, you may override the following methods::

def artist_picker(self, artist, evt):
'''The picker method that will be used.'''
return self.ref_artist.contains(evt)
Optionally, you may override the following method::

def finalize_offset(self):
'''Called when the mouse is released.'''
Expand All @@ -1719,7 +1715,18 @@ def __init__(self, ref_artist, use_blit=False):
c2 = self.canvas.mpl_connect('pick_event', self.on_pick)
c3 = self.canvas.mpl_connect('button_release_event', self.on_release)

ref_artist.set_picker(self.artist_picker)
if not ref_artist.pickable():
ref_artist.set_picker(True)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally, I left the previous picker in place if the user already configured their own.

with cbook._suppress_matplotlib_deprecation_warning():
if self.artist_picker != DraggableBase.artist_picker.__get__(self):
overridden_picker = self.artist_picker
else:
overridden_picker = None
if overridden_picker is not None:
cbook.warn_deprecated(
"3.3", name="artist_picker", obj_type="method",
addendum="Directly set the artist's picker if desired.")
ref_artist.set_picker(overridden_picker)
self.cids = [c2, c3]

def on_motion(self, evt):
Expand Down Expand Up @@ -1786,6 +1793,7 @@ def disconnect(self):
else:
self.canvas.mpl_disconnect(c1)

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

Expand Down