From 0538ea74b80a097f0a0827a7549fdf523da5a682 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Fri, 8 May 2020 12:27:59 +0200 Subject: [PATCH] Remove status bars in toolmanager mode as well. --- doc/api/api_changes_3.3/deprecations.rst | 6 +++++ lib/matplotlib/backend_bases.py | 33 +++++++++++++++++------- lib/matplotlib/backends/_backend_tk.py | 10 ++++--- lib/matplotlib/backends/backend_gtk3.py | 25 +++++++----------- lib/matplotlib/backends/backend_qt5.py | 22 ++++++++++------ lib/matplotlib/backends/backend_wx.py | 11 ++++++-- 6 files changed, 69 insertions(+), 38 deletions(-) diff --git a/doc/api/api_changes_3.3/deprecations.rst b/doc/api/api_changes_3.3/deprecations.rst index fcc692be2da0..b31fe3096a63 100644 --- a/doc/api/api_changes_3.3/deprecations.rst +++ b/doc/api/api_changes_3.3/deprecations.rst @@ -559,3 +559,9 @@ which did not reorder the properties passed to it. Passing multiple keys as a single comma-separated string or multiple arguments to `.ToolManager.update_keymap` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This is deprecated; pass keys as a list of strings instead. + +Statusbar classes and attributes +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +The ``statusbar`` attribute of `.FigureManagerBase`, `.StatusbarBase` and all +its subclasses, and ``StatusBarWx``, are deprecated, as messages are now +displayed in the toolbar instead. diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index 1a957b212e96..854eae006e45 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -23,9 +23,6 @@ `ToolContainerBase` The base class for the Toolbar class of each interactive backend. - -`StatusbarBase` - The base class for the messaging area. """ from contextlib import contextmanager @@ -2614,6 +2611,11 @@ def notify_axes_change(fig): if self.toolmanager is None and self.toolbar is not None: self.toolbar.update() + @cbook.deprecated("3.3") + @property + def statusbar(self): + return None + def show(self): """ For GUI backends, show the figure window and redraw. @@ -3188,8 +3190,12 @@ class ToolContainerBase: def __init__(self, toolmanager): self.toolmanager = toolmanager - self.toolmanager.toolmanager_connect('tool_removed_event', - self._remove_tool_cbk) + toolmanager.toolmanager_connect( + 'tool_message_event', + lambda event: self.set_message(event.message)) + toolmanager.toolmanager_connect( + 'tool_removed_event', + lambda event: self.remove_toolitem(event.tool.name)) def _tool_toggled_cbk(self, event): """ @@ -3224,10 +3230,6 @@ def add_tool(self, tool, group, position=-1): if tool.toggled: self.toggle_toolitem(tool.name, True) - def _remove_tool_cbk(self, event): - """Capture the 'tool_removed_event' signal and removes the tool.""" - self.remove_toolitem(event.tool.name) - def _get_image_filename(self, image): """Find the image based on its name.""" if not image: @@ -3312,7 +3314,19 @@ def remove_toolitem(self, name): """ raise NotImplementedError + def set_message(self, s): + """ + Display a message on the toolbar. + Parameters + ---------- + s : str + Message text. + """ + raise NotImplementedError + + +@cbook.deprecated("3.3") class StatusbarBase: """Base class for the statusbar.""" def __init__(self, toolmanager): @@ -3333,7 +3347,6 @@ def set_message(self, s): s : str Message text. """ - pass class _Backend: diff --git a/lib/matplotlib/backends/_backend_tk.py b/lib/matplotlib/backends/_backend_tk.py index 5ad4698202ca..46913dfa8c2a 100644 --- a/lib/matplotlib/backends/_backend_tk.py +++ b/lib/matplotlib/backends/_backend_tk.py @@ -414,13 +414,10 @@ def __init__(self, canvas, num, window): self.toolbar = self._get_toolbar() self.canvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=1) - self.statusbar = None - if self.toolmanager: backend_tools.add_tools_to_manager(self.toolmanager) if self.toolbar: backend_tools.add_tools_to_container(self.toolbar) - self.statusbar = StatusbarTk(self.window, self.toolmanager) self._shown = False @@ -714,6 +711,9 @@ def __init__(self, toolmanager, window): tk.Frame.__init__(self, master=window, width=int(width), height=int(height), borderwidth=2) + self._message = tk.StringVar(master=self) + self._message_label = tk.Label(master=self, textvariable=self._message) + self._message_label.pack(side=tk.RIGHT) self._toolitems = {} self.pack(side=tk.TOP, fill=tk.X) self._groups = {} @@ -758,7 +758,11 @@ def remove_toolitem(self, name): toolitem.pack_forget() del self._toolitems[name] + def set_message(self, s): + self._message.set(s) + +@cbook.deprecated("3.3") class StatusbarTk(StatusbarBase, tk.Frame): def __init__(self, window, *args, **kwargs): StatusbarBase.__init__(self, *args, **kwargs) diff --git a/lib/matplotlib/backends/backend_gtk3.py b/lib/matplotlib/backends/backend_gtk3.py index c60177698f05..618e57fab93c 100644 --- a/lib/matplotlib/backends/backend_gtk3.py +++ b/lib/matplotlib/backends/backend_gtk3.py @@ -347,7 +347,6 @@ def __init__(self, canvas, num): h = int(self.canvas.figure.bbox.height) self.toolbar = self._get_toolbar() - self.statusbar = None def add_widget(child): child.show() @@ -359,9 +358,6 @@ def add_widget(child): backend_tools.add_tools_to_manager(self.toolmanager) if self.toolbar: backend_tools.add_tools_to_container(self.toolbar) - self.statusbar = StatusbarGTK3(self.toolmanager) - h += add_widget(self.statusbar) - h += add_widget(Gtk.HSeparator()) if self.toolbar is not None: self.toolbar.show() @@ -433,9 +429,6 @@ def resize(self, width, height): if self.toolbar: toolbar_size = self.toolbar.size_request() height += toolbar_size.height - if self.statusbar: - statusbar_size = self.statusbar.size_request() - height += statusbar_size.height canvas_size = self.canvas.get_allocation() if canvas_size.width == canvas_size.height == 1: # A canvas size of (1, 1) cannot exist in most cases, because @@ -623,12 +616,10 @@ class ToolbarGTK3(ToolContainerBase, Gtk.Box): def __init__(self, toolmanager): ToolContainerBase.__init__(self, toolmanager) Gtk.Box.__init__(self) - self.set_property("orientation", Gtk.Orientation.VERTICAL) - - self._toolarea = Gtk.Box() - self._toolarea.set_property('orientation', Gtk.Orientation.HORIZONTAL) - self.pack_start(self._toolarea, False, False, 0) - self._toolarea.show_all() + self.set_property('orientation', Gtk.Orientation.HORIZONTAL) + self._message = Gtk.Label() + self.pack_end(self._message, False, False, 0) + self.show_all() self._groups = {} self._toolitems = {} @@ -661,7 +652,7 @@ def _add_button(self, button, group, position): self._add_separator() toolbar = Gtk.Toolbar() toolbar.set_style(Gtk.ToolbarStyle.ICONS) - self._toolarea.pack_start(toolbar, False, False, 0) + self.pack_start(toolbar, False, False, 0) toolbar.show_all() self._groups[group] = toolbar self._groups[group].insert(button, position) @@ -691,10 +682,14 @@ def remove_toolitem(self, name): def _add_separator(self): sep = Gtk.Separator() sep.set_property("orientation", Gtk.Orientation.VERTICAL) - self._toolarea.pack_start(sep, False, True, 0) + self.pack_start(sep, False, True, 0) sep.show_all() + def set_message(self, s): + self._message.set_label(s) + +@cbook.deprecated("3.3") class StatusbarGTK3(StatusbarBase, Gtk.Statusbar): def __init__(self, *args, **kwargs): StatusbarBase.__init__(self, *args, **kwargs) diff --git a/lib/matplotlib/backends/backend_qt5.py b/lib/matplotlib/backends/backend_qt5.py index 87a4b00aca0e..e33bcb83a306 100644 --- a/lib/matplotlib/backends/backend_qt5.py +++ b/lib/matplotlib/backends/backend_qt5.py @@ -543,18 +543,13 @@ def __init__(self, canvas, num): self.window._destroying = False self.toolbar = self._get_toolbar(self.canvas, self.window) - self.statusbar = None if self.toolmanager: backend_tools.add_tools_to_manager(self.toolmanager) if self.toolbar: backend_tools.add_tools_to_container(self.toolbar) - self.statusbar = StatusbarQt(self.window, self.toolmanager) - sbs_height = self.statusbar.sizeHint().height() - else: - sbs_height = 0 - if self.toolbar is not None: + if self.toolbar: self.window.addToolBar(self.toolbar) tbs_height = self.toolbar.sizeHint().height() else: @@ -564,7 +559,7 @@ def __init__(self, canvas, num): # requested size: cs = canvas.sizeHint() cs_height = cs.height() - height = cs_height + tbs_height + sbs_height + height = cs_height + tbs_height self.window.resize(cs.width(), height) self.window.setCentralWidget(self.canvas) @@ -888,6 +883,13 @@ def __init__(self, toolmanager, parent): QtWidgets.QToolBar.__init__(self, parent) self.setAllowedAreas( QtCore.Qt.TopToolBarArea | QtCore.Qt.BottomToolBarArea) + message_label = QtWidgets.QLabel("") + message_label.setAlignment( + QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) + message_label.setSizePolicy( + QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, + QtWidgets.QSizePolicy.Ignored)) + self._message_action = self.addWidget(message_label) self._toolitems = {} self._groups = {} @@ -915,7 +917,7 @@ def handler(): def _add_to_group(self, group, name, button, position): gr = self._groups.get(group, []) if not gr: - sep = self.addSeparator() + sep = self.insertSeparator(self._message_action) gr.append(sep) before = gr[position] widget = self.insertWidget(before, button) @@ -935,7 +937,11 @@ def remove_toolitem(self, name): button.setParent(None) del self._toolitems[name] + def set_message(self, s): + self.widgetForAction(self._message_action).setText(s) + +@cbook.deprecated("3.3") class StatusbarQt(StatusbarBase, QtWidgets.QLabel): def __init__(self, window, *args, **kwargs): StatusbarBase.__init__(self, *args, **kwargs) diff --git a/lib/matplotlib/backends/backend_wx.py b/lib/matplotlib/backends/backend_wx.py index f57979366130..f3021acddaea 100644 --- a/lib/matplotlib/backends/backend_wx.py +++ b/lib/matplotlib/backends/backend_wx.py @@ -931,7 +931,6 @@ def __init__(self, num, fig): self.toolbar = self._get_toolbar() if self.figmgr.toolmanager: - self.SetStatusBar(StatusbarWx(self, self.figmgr.toolmanager)) backend_tools.add_tools_to_manager(self.figmgr.toolmanager) if self.toolbar: backend_tools.add_tools_to_container(self.toolbar) @@ -1313,6 +1312,7 @@ def set_history_buttons(self): self.EnableTool(self.wx_ids['Forward'], can_forward) +@cbook.deprecated("3.3") class StatusBarWx(wx.StatusBar): """ A status bar is added to _FigureFrame to allow measurements and the @@ -1333,6 +1333,9 @@ class ToolbarWx(ToolContainerBase, wx.ToolBar): def __init__(self, toolmanager, parent, style=wx.TB_HORIZONTAL): ToolContainerBase.__init__(self, toolmanager) wx.ToolBar.__init__(self, parent, -1, style=style) + self._space = self.AddStretchableSpace() + self._label_text = wx.StaticText(self) + self.AddControl(self._label_text) self._toolitems = {} self._groups = {} @@ -1369,7 +1372,7 @@ def handler(event): def _add_to_group(self, group, name, position): gr = self._groups.get(group, []) if not gr: - sep = self.AddSeparator() + sep = self.InsertSeparator(self.GetToolPos(self._space.Id)) gr.append(sep) before = gr[position] self._groups[group] = gr @@ -1390,7 +1393,11 @@ def remove_toolitem(self, name): self.DeleteTool(tool.Id) del self._toolitems[name] + def set_message(self, s): + self._label_text.SetLabel(s) + +@cbook.deprecated("3.3") class StatusbarWx(StatusbarBase, wx.StatusBar): """For use with ToolManager.""" def __init__(self, parent, *args, **kwargs):