Skip to content

Remove status bars in toolmanager mode as well. #17362

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 1 commit into from
May 16, 2020
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
6 changes: 6 additions & 0 deletions doc/api/api_changes_3.3/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
33 changes: 23 additions & 10 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand All @@ -3333,7 +3347,6 @@ def set_message(self, s):
s : str
Message text.
"""
pass


class _Backend:
Expand Down
10 changes: 7 additions & 3 deletions lib/matplotlib/backends/_backend_tk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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)
Expand Down
25 changes: 10 additions & 15 deletions lib/matplotlib/backends/backend_gtk3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = {}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
22 changes: 14 additions & 8 deletions lib/matplotlib/backends/backend_qt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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 = {}

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
11 changes: 9 additions & 2 deletions lib/matplotlib/backends/backend_wx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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 = {}

Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down