FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

figure_enter_event uses now LocationEvent instead of Event. Fix issue #9812. by lkjell · Pull Request #9814 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (5) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
8 changes: 7 additions & 1 deletion lib/matplotlib/backend_bases.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This can also just be self.enter_notify_event.



class FigureCanvasWx(_FigureCanvasWxBase):
Expand Down

Back | FazBrowse Home | New Git URL