-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Remove visibility changes in draw for *Cursor widgets #19763
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
``Cursor`` and ``MultiCursor`` event handlers are now private | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
Access to the event handlers for the `.Cursor` and `.MultiCursor` widgets is | ||
now deprecated. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1600,8 +1600,8 @@ def __init__(self, ax, horizOn=True, vertOn=True, useblit=False, | |
**lineprops): | ||
super().__init__(ax) | ||
|
||
self.connect_event('motion_notify_event', self.onmove) | ||
self.connect_event('draw_event', self.clear) | ||
self.connect_event('motion_notify_event', self._onmove) | ||
self.connect_event('draw_event', self._clear) | ||
|
||
self.visible = True | ||
self.horizOn = horizOn | ||
|
@@ -1616,16 +1616,25 @@ def __init__(self, ax, horizOn=True, vertOn=True, useblit=False, | |
self.background = None | ||
self.needclear = False | ||
|
||
@_api.deprecated('3.5') | ||
def clear(self, event): | ||
"""Internal event handler to clear the cursor.""" | ||
self._clear(event) | ||
if self.ignore(event): | ||
return | ||
if self.useblit: | ||
self.background = self.canvas.copy_from_bbox(self.ax.bbox) | ||
self.linev.set_visible(False) | ||
self.lineh.set_visible(False) | ||
|
||
def onmove(self, event): | ||
def _clear(self, event): | ||
"""Internal event handler to clear the cursor.""" | ||
if self.ignore(event): | ||
return | ||
if self.useblit: | ||
self.background = self.canvas.copy_from_bbox(self.ax.bbox) | ||
|
||
onmove = _api.deprecate_privatize_attribute('3.5') | ||
|
||
def _onmove(self, event): | ||
"""Internal event handler to draw the cursor when the mouse moves.""" | ||
if self.ignore(event): | ||
return | ||
|
@@ -1640,15 +1649,15 @@ def onmove(self, event): | |
self.needclear = False | ||
return | ||
self.needclear = True | ||
if not self.visible: | ||
return | ||
|
||
self.linev.set_xdata((event.xdata, event.xdata)) | ||
self.linev.set_visible(self.visible and self.vertOn) | ||
|
||
self.lineh.set_ydata((event.ydata, event.ydata)) | ||
self.linev.set_visible(self.visible and self.vertOn) | ||
self.lineh.set_visible(self.visible and self.horizOn) | ||
|
||
self._update() | ||
if self.visible and (self.vertOn or self.horizOn): | ||
self._update() | ||
|
||
def _update(self): | ||
if self.useblit: | ||
|
@@ -1749,8 +1758,8 @@ def connect(self): | |
"""Connect events.""" | ||
for canvas, info in self._canvas_infos.items(): | ||
info["cids"] = [ | ||
canvas.mpl_connect('motion_notify_event', self.onmove), | ||
canvas.mpl_connect('draw_event', self.clear), | ||
canvas.mpl_connect('motion_notify_event', self._onmove), | ||
canvas.mpl_connect('draw_event', self._clear), | ||
] | ||
|
||
def disconnect(self): | ||
|
@@ -1760,24 +1769,31 @@ def disconnect(self): | |
canvas.mpl_disconnect(cid) | ||
info["cids"].clear() | ||
|
||
@_api.deprecated('3.5') | ||
def clear(self, event): | ||
"""Clear the cursor.""" | ||
if self.ignore(event): | ||
return | ||
self._clear(event) | ||
for line in self.vlines + self.hlines: | ||
line.set_visible(False) | ||
|
||
def _clear(self, event): | ||
"""Clear the cursor.""" | ||
if self.ignore(event): | ||
return | ||
if self.useblit: | ||
for canvas, info in self._canvas_infos.items(): | ||
info["background"] = canvas.copy_from_bbox(canvas.figure.bbox) | ||
for line in self.vlines + self.hlines: | ||
line.set_visible(False) | ||
|
||
def onmove(self, event): | ||
onmove = _api.deprecate_privatize_attribute('3.5') | ||
|
||
def _onmove(self, event): | ||
if (self.ignore(event) | ||
or event.inaxes not in self.axes | ||
or not event.canvas.widgetlock.available(self)): | ||
return | ||
self.needclear = True | ||
if not self.visible: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why drop this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we want to keep this short-circuit to avoid going to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If that's the case, we might want to clarify that for our future selves with a comment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, we want to remove it from here so that the later There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I see now. We used to always make the lines not visible so if Do we need some more careful logic on this like to call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I re-added a condition on the |
||
return | ||
if self.vertOn: | ||
for line in self.vlines: | ||
line.set_xdata((event.xdata, event.xdata)) | ||
|
@@ -1786,7 +1802,8 @@ def onmove(self, event): | |
for line in self.hlines: | ||
line.set_ydata((event.ydata, event.ydata)) | ||
line.set_visible(self.visible) | ||
self._update() | ||
if self.visible and (self.vertOn or self.horizOn): | ||
self._update() | ||
|
||
def _update(self): | ||
if self.useblit: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sidenote but as far as I can tell
self.needclear
is never actually used inMultiCursor