| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
Should perhaps change the backends to pass inn their coordinates as well. As for now the fix is having else:
x = None
y = None
in FigureCanvasBase.enter_notify_event, as in the commit. grep "FigureCanvasBase.enter_notify_event" *py backend_gtk3.py: FigureCanvasBase.enter_notify_event(self, event) backend_gtk.py: FigureCanvasBase.enter_notify_event(self, event, xy=(x, y)) backend_qt5.py: FigureCanvasBase.enter_notify_event(self, guiEvent=event) backend_wx.py: FigureCanvasBase.enter_notify_event(self, guiEvent=evt) |
Sorry, something went wrong.
|
Thanks for the PR. You'll probably get more testers if you give us a sample script to try that shows this works better. |
Sorry, something went wrong.
|
wow, that is a pretty big likely long standing bug! |
Sorry, something went wrong.
|
ok, so it looks like the sub-classes of FigureCanvasBase that over-ride enter_notify_event are changing the signature / purpose a bit (gtk, gtk3, tk). The method on FigureCanvasBase generates the Event instance that Matplotlib uses internally and turns the crank on our callbacks where as the methods of the sub-classes are registered as callbacks into the underlying GUI event handling frame work which has it's own required signature (if you look at the Qt5, Wx and Webagg backends they use a differently method to register into the GUI framework callback system). Doing this from scratch I think the second pattern is better, but it is probably not worth the effort to deprecate and rename the bridge methods in {gtk,gtk3, tk} (the work would be to create new methods rename the methods to _on_enter, shim the behavior back into enter_notify_event and warn about usage. In a future release we would remove the methods on the sub-classes and just let it fallback to the base class behavior). |
Sorry, something went wrong.
|
The method name enter_notify_event (gtk, gtk3, tk) I believe was the initial usage. After a while when changing the signature of the FigureCanvasBase.enter_notify_event to use add xy coordinates or LocationEvent something must have been missed out. The bridge method for tk enter_notify_event I added in commit cb3146d was for consistency of the naming scheme used in the class. |
Sorry, something went wrong.
There was a problem hiding this comment.
Some minor comments, but 👍 as-is
Tested on
Sorry, something went wrong.
| def enterEvent(self, event): | ||
| FigureCanvasBase.enter_notify_event(self, guiEvent=event) | ||
| x, y = self.mouseEventCoords(event.pos()) | ||
| FigureCanvasBase.enter_notify_event(self, guiEvent=event, xy=(x, y)) |
There was a problem hiding this comment.
This can just be self.enter_notif_event(guiEvent=event, xy=(x, y))
Sorry, something went wrong.
There was a problem hiding this comment.
Could do but that would break some inconsistency with the other event as well. For example
def wheelEvent(self, event):
x, y = self.mouseEventCoords(event)
# from QWheelEvent::delta doc
if event.pixelDelta().x() == 0 and event.pixelDelta().y() == 0:
steps = event.angleDelta().y() / 120
else:
steps = event.pixelDelta().y()
if steps:
FigureCanvasBase.scroll_event(self, x, y, steps, guiEvent=event)
def keyPressEvent(self, event):
key = self._get_key(event)
if key is not None:
FigureCanvasBase.key_press_event(self, key, guiEvent=event)
def keyReleaseEvent(self, event):
key = self._get_key(event)
if key is not None:
FigureCanvasBase.key_release_event(self, key, guiEvent=event)
Sorry, something went wrong.
There was a problem hiding this comment.
Fair. I suppose those could also all be changed to normal method calls, but that is beyond the scope of this PR.
Sorry, something went wrong.
| if xy is not None: | ||
| x, y = xy | ||
| self._lastx, self._lasty = x, y | ||
| else: |
There was a problem hiding this comment.
Can you add a warning here like
warnings.warn('enter_notify_event expects a location but your backend did not pass one. '
'This may become mandatory in the future', stacklevel=2)?
Sorry, something went wrong.
There was a problem hiding this comment.
cbook.warn_deprecated?
Sorry, something went wrong.
| x = evt.GetX() | ||
| y = self.figure.bbox.height - evt.GetY() | ||
| evt.Skip() | ||
| FigureCanvasBase.enter_notify_event(self, guiEvent=evt, xy=(x, y)) |
There was a problem hiding this comment.
This can also just be self.enter_notify_event.
Sorry, something went wrong.
| y = self.figure.bbox.height - event.y | ||
| FigureCanvasBase.motion_notify_event(self, x, y, guiEvent=event) | ||
|
|
||
| def enter_notify_event(self, event): |
There was a problem hiding this comment.
This is probably better named something else (as it is new)
Sorry, something went wrong.
There was a problem hiding this comment.
Could but breaks naming scheme used in the class.
Sorry, something went wrong.
|
@tacaswell Will this get merged soon or there need more testing? |
Sorry, something went wrong.
|
This one has gone too long @tacaswell . I needed to strip some commits since there where some confilics with the master branch and I simple do not have the time to solve the merge conflics. |
Sorry, something went wrong.
|
@lkjell Sorry this has sat for so long, I assure you it is not personal! I am confused by your comment though as it looks like have fixed the merge conflicts (as the tests are running). |
Sorry, something went wrong.
| else: | ||
| x = None | ||
| y = None | ||
| warn_deprecated('2.2', 'enter_notify_event expects a location but your backend did not pass one.') |
There was a problem hiding this comment.
Can this be changed to '3.0' ?
Sorry, something went wrong.
|
Can you also add an entry in https://github.com/matplotlib/matplotlib/tree/master/doc/users/next_whats_new (so people know they can use this!) |
Sorry, something went wrong.
|
This is a bug fix. https://matplotlib.org/users/event_handling.html |
Sorry, something went wrong.
|
🐑 your right, that is what I get for reading from the bottom! |
Sorry, something went wrong.
|
If I understand correctly, the original PR included fixes to backends; the present version of this PR adds a warning, but does not have any fixes to the backends. Therefore, if this PR is merged, an attempt to use the figure enter/leave events will generate the deprecation warnings until another PR provides the backend fixes. It is unfortunate that those original fixes were wiped out because they needed to be rebased. Am I correct, or hopelessly confused? |
Sorry, something went wrong.
|
@efiring something like that. If memory serve right some backend did pass in None, None. Some did not register an Enter event(gtk). The backend fix had merge confict and you need to edit the super to python3 only. |
Sorry, something went wrong.
This is now consistent with the documentation: https://matplotlib.org/users/event_handling.html
|
My fault for not looking into deeper. I restored the non-conflicting commits. The only conflicting backend is tk. It appears that file was renamed to _backend_tk.py |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
PR Summary
In the documentation 1 figure_enter_event uses LocationEvent. However, previously it just uses the base class Event. This cause some problem when trying to access LocationEvent attributes because they did not exist. This addresses issue #9812.
Fix also an issue that tkagg backend does not have a figure_enter_event.
gtk3, Qt5 and wx pass in coordinates when entering figure.
The tkagg backend did not have a figure_leave_event. Enabling that as well.
Sample script using Qt5 backend. Move the cursor in and out of the figure.
import matplotlib matplotlib.use("Qt5Agg") import matplotlib.pyplot as plt import numpy as np x = range(100) fig, ax = plt.subplots() ax.plot(np.random.rand(10)) def stat(event): print("axes: {}, x: {}, y: {}".format(event.inaxes, event.x, event.y)) cid = fig.canvas.mpl_connect('figure_enter_event', stat) cid = fig.canvas.mpl_connect('figure_leave_event', stat) plt.show()PR Checklist