From 8cff8940556974dfbc9355d77d0bd6559a96f6a0 Mon Sep 17 00:00:00 2001 From: Kjell Le Date: Sun, 19 Nov 2017 03:47:35 +0100 Subject: [PATCH 1/4] figure_enter_event uses now LocationEvent instead of Event. This is now consistent with the documentation: https://matplotlib.org/users/event_handling.html --- lib/matplotlib/backend_bases.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index 2fe2ad59ac42..22effd5e721f 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -2010,8 +2010,12 @@ def enter_notify_event(self, guiEvent=None, xy=None): if xy is not None: x, y = xy self._lastx, self._lasty = x, y + else: + x = None + y = None + warn_deprecated('2.2', '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") From ce76875749359148299b797b80acaf8bcc71bd03 Mon Sep 17 00:00:00 2001 From: Kjell Le Date: Sun, 19 Nov 2017 05:51:09 +0100 Subject: [PATCH 2/4] backend gtk3, qt5/qt4 and wx pass in coordinates when entering figure. --- lib/matplotlib/backends/backend_gtk3.py | 5 ++++- lib/matplotlib/backends/backend_qt5.py | 3 ++- lib/matplotlib/backends/backend_wx.py | 5 ++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/backends/backend_gtk3.py b/lib/matplotlib/backends/backend_gtk3.py index 573110aaac1c..0bbab45c0a8b 100644 --- a/lib/matplotlib/backends/backend_gtk3.py +++ b/lib/matplotlib/backends/backend_gtk3.py @@ -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 diff --git a/lib/matplotlib/backends/backend_qt5.py b/lib/matplotlib/backends/backend_qt5.py index b1a75b248dd8..a3757d6000bf 100644 --- a/lib/matplotlib/backends/backend_qt5.py +++ b/lib/matplotlib/backends/backend_qt5.py @@ -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)) def leaveEvent(self, event): QtWidgets.QApplication.restoreOverrideCursor() diff --git a/lib/matplotlib/backends/backend_wx.py b/lib/matplotlib/backends/backend_wx.py index 81b0729b65d8..ada580d0077c 100644 --- a/lib/matplotlib/backends/backend_wx.py +++ b/lib/matplotlib/backends/backend_wx.py @@ -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)) class FigureCanvasWx(_FigureCanvasWxBase): From 3fdd52728771da94bdc65517e2754a1209518938 Mon Sep 17 00:00:00 2001 From: Kjell Le Date: Fri, 2 Mar 2018 13:51:38 +0100 Subject: [PATCH 3/4] bump warnings --- lib/matplotlib/backend_bases.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index 22effd5e721f..e11144ff8f8a 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -2013,7 +2013,9 @@ def enter_notify_event(self, guiEvent=None, xy=None): else: x = None y = None - warn_deprecated('2.2', 'enter_notify_event expects a location but your backend did not pass one.') + cbook.warn_deprecated('3.0', 'enter_notify_event expects a ' + 'location but ' + 'your backend did not pass one.') event = LocationEvent('figure_enter_event', self, x, y, guiEvent) self.callbacks.process('figure_enter_event', event) From 64e37bc574fd9ca0603e1a31c19e8ea55f7ff043 Mon Sep 17 00:00:00 2001 From: Kjell Le Date: Sun, 4 Mar 2018 23:21:58 +0100 Subject: [PATCH 4/4] Enable enter/leave notify for tk --- lib/matplotlib/backends/_backend_tk.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/matplotlib/backends/_backend_tk.py b/lib/matplotlib/backends/_backend_tk.py index e5ef40caf74f..6230511f7361 100644 --- a/lib/matplotlib/backends/_backend_tk.py +++ b/lib/matplotlib/backends/_backend_tk.py @@ -178,6 +178,8 @@ def __init__(self, figure, master=None, resize_callback=None): self._tkcanvas.bind("", self.resize) self._tkcanvas.bind("", self.key_press) self._tkcanvas.bind("", self.motion_notify_event) + self._tkcanvas.bind("", self.enter_notify_event) + self._tkcanvas.bind("", self.leave_notify_event) self._tkcanvas.bind("", self.key_release) for name in "", "", "": self._tkcanvas.bind(name, self.button_press_event) @@ -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