From 67aafa9febc2183106c33cecad913c6a2c1c2d58 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 21 Jul 2020 17:25:45 -0400 Subject: [PATCH 1/2] Use separators in toolmanager consistent with toolbar. --- lib/matplotlib/backends/_backend_tk.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/matplotlib/backends/_backend_tk.py b/lib/matplotlib/backends/_backend_tk.py index 7c1ff265aea3..7701efa9207c 100644 --- a/lib/matplotlib/backends/_backend_tk.py +++ b/lib/matplotlib/backends/_backend_tk.py @@ -747,8 +747,7 @@ def _get_groupframe(self, group): return self._groups[group] def _add_separator(self): - separator = tk.Frame(master=self, bd=5, width=1, bg='black') - separator.pack(side=tk.LEFT, fill=tk.Y, padx=2) + return NavigationToolbar2Tk._Spacer(self) def _button_click(self, name): self.trigger_tool(name) From 9ac3474503883fa15bdc7736a80e5cf36d0d1684 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 21 Jul 2020 18:07:44 -0400 Subject: [PATCH 2/2] Sync ToolManager status message to toolbar's. They are almost the same code, but fell a little out of sync, with the toolbar using two lines in some cases, while ToolManager used the old single-line message. --- lib/matplotlib/backend_bases.py | 15 ++++++++++----- lib/matplotlib/backend_tools.py | 25 ++++--------------------- 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index 23773cca6ab6..2e1051a9fbc3 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -2984,11 +2984,9 @@ def _wait_cursor_for_draw_cm(self): else: yield - def mouse_move(self, event): - self._update_cursor(event) - + @staticmethod + def _mouse_event_to_message(event): if event.inaxes and event.inaxes.get_navigate(): - try: s = event.inaxes.format_coord(event.xdata, event.ydata) except (ValueError, OverflowError): @@ -3005,7 +3003,14 @@ def mouse_move(self, event): data_str = a.format_cursor_data(data).rstrip() if data_str: s = s + '\n' + data_str - self.set_message(s) + return s + + def mouse_move(self, event): + self._update_cursor(event) + + s = self._mouse_event_to_message(event) + if s is not None: + self.set_message(s) else: self.set_message(self.mode) diff --git a/lib/matplotlib/backend_tools.py b/lib/matplotlib/backend_tools.py index cf8438bb4aff..e4bf0ec68729 100644 --- a/lib/matplotlib/backend_tools.py +++ b/lib/matplotlib/backend_tools.py @@ -339,27 +339,10 @@ def send_message(self, event): if self.toolmanager.messagelock.locked(): return - message = ' ' - - if event.inaxes and event.inaxes.get_navigate(): - try: - s = event.inaxes.format_coord(event.xdata, event.ydata) - except (ValueError, OverflowError): - pass - else: - artists = [a for a in event.inaxes._mouseover_set - if a.contains(event) and a.get_visible()] - - if artists: - a = cbook._topmost_artist(artists) - if a is not event.inaxes.patch: - data = a.get_cursor_data(event) - if data is not None: - data_str = a.format_cursor_data(data) - if data_str is not None: - s = s + ' ' + data_str - - message = s + from matplotlib.backend_bases import NavigationToolbar2 + message = NavigationToolbar2._mouse_event_to_message(event) + if message is None: + message = ' ' self.toolmanager.message_event(message, self)