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

Skip to content

figure_enter_event uses now LocationEvent instead of Event. Fix issue #9812. #9814

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 4 commits into from
Mar 5, 2018
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
8 changes: 7 additions & 1 deletion lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2010,8 +2010,14 @@ def enter_notify_event(self, guiEvent=None, xy=None):
if xy is not None:
x, y = xy
self._lastx, self._lasty = x, y
else:
Copy link
Member

Choose a reason for hiding this comment

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

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)

?

Copy link
Contributor

Choose a reason for hiding this comment

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

cbook.warn_deprecated?

x = None
y = None
cbook.warn_deprecated('3.0', 'enter_notify_event expects a '
'location but '
'your backend did not pass one.')

event = Event('figure_enter_event', self, guiEvent)
event = LocationEvent('figure_enter_event', self, x, y, guiEvent)
self.callbacks.process('figure_enter_event', event)

@cbook.deprecated("2.1")
Expand Down
7 changes: 7 additions & 0 deletions lib/matplotlib/backends/_backend_tk.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ def __init__(self, figure, master=None, resize_callback=None):
self._tkcanvas.bind("<Configure>", self.resize)
self._tkcanvas.bind("<Key>", self.key_press)
self._tkcanvas.bind("<Motion>", self.motion_notify_event)
self._tkcanvas.bind("<Enter>", self.enter_notify_event)
self._tkcanvas.bind("<Leave>", self.leave_notify_event)
self._tkcanvas.bind("<KeyRelease>", self.key_release)
for name in "<Button-1>", "<Button-2>", "<Button-3>":
self._tkcanvas.bind(name, self.button_press_event)
Expand Down Expand Up @@ -326,6 +328,11 @@ def motion_notify_event(self, event):
y = self.figure.bbox.height - event.y
FigureCanvasBase.motion_notify_event(self, x, y, guiEvent=event)

def enter_notify_event(self, event):
x = event.x
# flipy so y=0 is bottom of canvas
y = self.figure.bbox.height - event.y
FigureCanvasBase.enter_notify_event(self, guiEvent=event, xy=(x, y))

def button_press_event(self, event, dblclick=False):
x = event.x
Expand Down
5 changes: 4 additions & 1 deletion lib/matplotlib/backends/backend_gtk3.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,10 @@ def leave_notify_event(self, widget, event):
FigureCanvasBase.leave_notify_event(self, event)

def enter_notify_event(self, widget, event):
FigureCanvasBase.enter_notify_event(self, event)
x = event.x
# flipy so y=0 is bottom of canvas
y = self.get_allocation().height - event.y
FigureCanvasBase.enter_notify_event(self, guiEvent=event, xy=(x, y))

def size_allocate(self, widget, allocation):
dpival = self.figure.dpi
Expand Down
3 changes: 2 additions & 1 deletion lib/matplotlib/backends/backend_qt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ def get_width_height(self):
return int(w / self._dpi_ratio), int(h / self._dpi_ratio)

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))
Copy link
Member

Choose a reason for hiding this comment

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

This can just be self.enter_notif_event(guiEvent=event, xy=(x, y))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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)

Copy link
Member

Choose a reason for hiding this comment

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

Fair. I suppose those could also all be changed to normal method calls, but that is beyond the scope of this PR.


def leaveEvent(self, event):
QtWidgets.QApplication.restoreOverrideCursor()
Expand Down
5 changes: 4 additions & 1 deletion lib/matplotlib/backends/backend_wx.py
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,10 @@ def _onLeave(self, evt):

def _onEnter(self, evt):
"""Mouse has entered the window."""
FigureCanvasBase.enter_notify_event(self, guiEvent=evt)
x = evt.GetX()
y = self.figure.bbox.height - evt.GetY()
evt.Skip()
FigureCanvasBase.enter_notify_event(self, guiEvent=evt, xy=(x, y))
Copy link
Member

Choose a reason for hiding this comment

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

This can also just be self.enter_notify_event.



class FigureCanvasWx(_FigureCanvasWxBase):
Expand Down