Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ef0a308

Browse files
authored
Merge pull request #17362 from anntzer/toolmanstatbar
Remove status bars in toolmanager mode as well.
2 parents 370ad44 + 0538ea7 commit ef0a308

File tree

6 files changed

+69
-38
lines changed

6 files changed

+69
-38
lines changed

doc/api/api_changes_3.3/deprecations.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,3 +559,9 @@ which did not reorder the properties passed to it.
559559
Passing multiple keys as a single comma-separated string or multiple arguments to `.ToolManager.update_keymap`
560560
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
561561
This is deprecated; pass keys as a list of strings instead.
562+
563+
Statusbar classes and attributes
564+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
565+
The ``statusbar`` attribute of `.FigureManagerBase`, `.StatusbarBase` and all
566+
its subclasses, and ``StatusBarWx``, are deprecated, as messages are now
567+
displayed in the toolbar instead.

lib/matplotlib/backend_bases.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
2424
`ToolContainerBase`
2525
The base class for the Toolbar class of each interactive backend.
26-
27-
`StatusbarBase`
28-
The base class for the messaging area.
2926
"""
3027

3128
from contextlib import contextmanager
@@ -2614,6 +2611,11 @@ def notify_axes_change(fig):
26142611
if self.toolmanager is None and self.toolbar is not None:
26152612
self.toolbar.update()
26162613

2614+
@cbook.deprecated("3.3")
2615+
@property
2616+
def statusbar(self):
2617+
return None
2618+
26172619
def show(self):
26182620
"""
26192621
For GUI backends, show the figure window and redraw.
@@ -3188,8 +3190,12 @@ class ToolContainerBase:
31883190

31893191
def __init__(self, toolmanager):
31903192
self.toolmanager = toolmanager
3191-
self.toolmanager.toolmanager_connect('tool_removed_event',
3192-
self._remove_tool_cbk)
3193+
toolmanager.toolmanager_connect(
3194+
'tool_message_event',
3195+
lambda event: self.set_message(event.message))
3196+
toolmanager.toolmanager_connect(
3197+
'tool_removed_event',
3198+
lambda event: self.remove_toolitem(event.tool.name))
31933199

31943200
def _tool_toggled_cbk(self, event):
31953201
"""
@@ -3224,10 +3230,6 @@ def add_tool(self, tool, group, position=-1):
32243230
if tool.toggled:
32253231
self.toggle_toolitem(tool.name, True)
32263232

3227-
def _remove_tool_cbk(self, event):
3228-
"""Capture the 'tool_removed_event' signal and removes the tool."""
3229-
self.remove_toolitem(event.tool.name)
3230-
32313233
def _get_image_filename(self, image):
32323234
"""Find the image based on its name."""
32333235
if not image:
@@ -3312,7 +3314,19 @@ def remove_toolitem(self, name):
33123314
"""
33133315
raise NotImplementedError
33143316

3317+
def set_message(self, s):
3318+
"""
3319+
Display a message on the toolbar.
33153320
3321+
Parameters
3322+
----------
3323+
s : str
3324+
Message text.
3325+
"""
3326+
raise NotImplementedError
3327+
3328+
3329+
@cbook.deprecated("3.3")
33163330
class StatusbarBase:
33173331
"""Base class for the statusbar."""
33183332
def __init__(self, toolmanager):
@@ -3333,7 +3347,6 @@ def set_message(self, s):
33333347
s : str
33343348
Message text.
33353349
"""
3336-
pass
33373350

33383351

33393352
class _Backend:

lib/matplotlib/backends/_backend_tk.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -414,13 +414,10 @@ def __init__(self, canvas, num, window):
414414
self.toolbar = self._get_toolbar()
415415
self.canvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=1)
416416

417-
self.statusbar = None
418-
419417
if self.toolmanager:
420418
backend_tools.add_tools_to_manager(self.toolmanager)
421419
if self.toolbar:
422420
backend_tools.add_tools_to_container(self.toolbar)
423-
self.statusbar = StatusbarTk(self.window, self.toolmanager)
424421

425422
self._shown = False
426423

@@ -714,6 +711,9 @@ def __init__(self, toolmanager, window):
714711
tk.Frame.__init__(self, master=window,
715712
width=int(width), height=int(height),
716713
borderwidth=2)
714+
self._message = tk.StringVar(master=self)
715+
self._message_label = tk.Label(master=self, textvariable=self._message)
716+
self._message_label.pack(side=tk.RIGHT)
717717
self._toolitems = {}
718718
self.pack(side=tk.TOP, fill=tk.X)
719719
self._groups = {}
@@ -758,7 +758,11 @@ def remove_toolitem(self, name):
758758
toolitem.pack_forget()
759759
del self._toolitems[name]
760760

761+
def set_message(self, s):
762+
self._message.set(s)
763+
761764

765+
@cbook.deprecated("3.3")
762766
class StatusbarTk(StatusbarBase, tk.Frame):
763767
def __init__(self, window, *args, **kwargs):
764768
StatusbarBase.__init__(self, *args, **kwargs)

lib/matplotlib/backends/backend_gtk3.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,6 @@ def __init__(self, canvas, num):
347347
h = int(self.canvas.figure.bbox.height)
348348

349349
self.toolbar = self._get_toolbar()
350-
self.statusbar = None
351350

352351
def add_widget(child):
353352
child.show()
@@ -359,9 +358,6 @@ def add_widget(child):
359358
backend_tools.add_tools_to_manager(self.toolmanager)
360359
if self.toolbar:
361360
backend_tools.add_tools_to_container(self.toolbar)
362-
self.statusbar = StatusbarGTK3(self.toolmanager)
363-
h += add_widget(self.statusbar)
364-
h += add_widget(Gtk.HSeparator())
365361

366362
if self.toolbar is not None:
367363
self.toolbar.show()
@@ -433,9 +429,6 @@ def resize(self, width, height):
433429
if self.toolbar:
434430
toolbar_size = self.toolbar.size_request()
435431
height += toolbar_size.height
436-
if self.statusbar:
437-
statusbar_size = self.statusbar.size_request()
438-
height += statusbar_size.height
439432
canvas_size = self.canvas.get_allocation()
440433
if canvas_size.width == canvas_size.height == 1:
441434
# A canvas size of (1, 1) cannot exist in most cases, because
@@ -623,12 +616,10 @@ class ToolbarGTK3(ToolContainerBase, Gtk.Box):
623616
def __init__(self, toolmanager):
624617
ToolContainerBase.__init__(self, toolmanager)
625618
Gtk.Box.__init__(self)
626-
self.set_property("orientation", Gtk.Orientation.VERTICAL)
627-
628-
self._toolarea = Gtk.Box()
629-
self._toolarea.set_property('orientation', Gtk.Orientation.HORIZONTAL)
630-
self.pack_start(self._toolarea, False, False, 0)
631-
self._toolarea.show_all()
619+
self.set_property('orientation', Gtk.Orientation.HORIZONTAL)
620+
self._message = Gtk.Label()
621+
self.pack_end(self._message, False, False, 0)
622+
self.show_all()
632623
self._groups = {}
633624
self._toolitems = {}
634625

@@ -661,7 +652,7 @@ def _add_button(self, button, group, position):
661652
self._add_separator()
662653
toolbar = Gtk.Toolbar()
663654
toolbar.set_style(Gtk.ToolbarStyle.ICONS)
664-
self._toolarea.pack_start(toolbar, False, False, 0)
655+
self.pack_start(toolbar, False, False, 0)
665656
toolbar.show_all()
666657
self._groups[group] = toolbar
667658
self._groups[group].insert(button, position)
@@ -691,10 +682,14 @@ def remove_toolitem(self, name):
691682
def _add_separator(self):
692683
sep = Gtk.Separator()
693684
sep.set_property("orientation", Gtk.Orientation.VERTICAL)
694-
self._toolarea.pack_start(sep, False, True, 0)
685+
self.pack_start(sep, False, True, 0)
695686
sep.show_all()
696687

688+
def set_message(self, s):
689+
self._message.set_label(s)
690+
697691

692+
@cbook.deprecated("3.3")
698693
class StatusbarGTK3(StatusbarBase, Gtk.Statusbar):
699694
def __init__(self, *args, **kwargs):
700695
StatusbarBase.__init__(self, *args, **kwargs)

lib/matplotlib/backends/backend_qt5.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -543,18 +543,13 @@ def __init__(self, canvas, num):
543543
self.window._destroying = False
544544

545545
self.toolbar = self._get_toolbar(self.canvas, self.window)
546-
self.statusbar = None
547546

548547
if self.toolmanager:
549548
backend_tools.add_tools_to_manager(self.toolmanager)
550549
if self.toolbar:
551550
backend_tools.add_tools_to_container(self.toolbar)
552-
self.statusbar = StatusbarQt(self.window, self.toolmanager)
553-
sbs_height = self.statusbar.sizeHint().height()
554-
else:
555-
sbs_height = 0
556551

557-
if self.toolbar is not None:
552+
if self.toolbar:
558553
self.window.addToolBar(self.toolbar)
559554
tbs_height = self.toolbar.sizeHint().height()
560555
else:
@@ -564,7 +559,7 @@ def __init__(self, canvas, num):
564559
# requested size:
565560
cs = canvas.sizeHint()
566561
cs_height = cs.height()
567-
height = cs_height + tbs_height + sbs_height
562+
height = cs_height + tbs_height
568563
self.window.resize(cs.width(), height)
569564

570565
self.window.setCentralWidget(self.canvas)
@@ -888,6 +883,13 @@ def __init__(self, toolmanager, parent):
888883
QtWidgets.QToolBar.__init__(self, parent)
889884
self.setAllowedAreas(
890885
QtCore.Qt.TopToolBarArea | QtCore.Qt.BottomToolBarArea)
886+
message_label = QtWidgets.QLabel("")
887+
message_label.setAlignment(
888+
QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
889+
message_label.setSizePolicy(
890+
QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding,
891+
QtWidgets.QSizePolicy.Ignored))
892+
self._message_action = self.addWidget(message_label)
891893
self._toolitems = {}
892894
self._groups = {}
893895

@@ -915,7 +917,7 @@ def handler():
915917
def _add_to_group(self, group, name, button, position):
916918
gr = self._groups.get(group, [])
917919
if not gr:
918-
sep = self.addSeparator()
920+
sep = self.insertSeparator(self._message_action)
919921
gr.append(sep)
920922
before = gr[position]
921923
widget = self.insertWidget(before, button)
@@ -935,7 +937,11 @@ def remove_toolitem(self, name):
935937
button.setParent(None)
936938
del self._toolitems[name]
937939

940+
def set_message(self, s):
941+
self.widgetForAction(self._message_action).setText(s)
942+
938943

944+
@cbook.deprecated("3.3")
939945
class StatusbarQt(StatusbarBase, QtWidgets.QLabel):
940946
def __init__(self, window, *args, **kwargs):
941947
StatusbarBase.__init__(self, *args, **kwargs)

lib/matplotlib/backends/backend_wx.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,6 @@ def __init__(self, num, fig):
931931
self.toolbar = self._get_toolbar()
932932

933933
if self.figmgr.toolmanager:
934-
self.SetStatusBar(StatusbarWx(self, self.figmgr.toolmanager))
935934
backend_tools.add_tools_to_manager(self.figmgr.toolmanager)
936935
if self.toolbar:
937936
backend_tools.add_tools_to_container(self.toolbar)
@@ -1315,6 +1314,7 @@ def set_history_buttons(self):
13151314
self.EnableTool(self.wx_ids['Forward'], can_forward)
13161315

13171316

1317+
@cbook.deprecated("3.3")
13181318
class StatusBarWx(wx.StatusBar):
13191319
"""
13201320
A status bar is added to _FigureFrame to allow measurements and the
@@ -1335,6 +1335,9 @@ class ToolbarWx(ToolContainerBase, wx.ToolBar):
13351335
def __init__(self, toolmanager, parent, style=wx.TB_HORIZONTAL):
13361336
ToolContainerBase.__init__(self, toolmanager)
13371337
wx.ToolBar.__init__(self, parent, -1, style=style)
1338+
self._space = self.AddStretchableSpace()
1339+
self._label_text = wx.StaticText(self)
1340+
self.AddControl(self._label_text)
13381341
self._toolitems = {}
13391342
self._groups = {}
13401343

@@ -1371,7 +1374,7 @@ def handler(event):
13711374
def _add_to_group(self, group, name, position):
13721375
gr = self._groups.get(group, [])
13731376
if not gr:
1374-
sep = self.AddSeparator()
1377+
sep = self.InsertSeparator(self.GetToolPos(self._space.Id))
13751378
gr.append(sep)
13761379
before = gr[position]
13771380
self._groups[group] = gr
@@ -1392,7 +1395,11 @@ def remove_toolitem(self, name):
13921395
self.DeleteTool(tool.Id)
13931396
del self._toolitems[name]
13941397

1398+
def set_message(self, s):
1399+
self._label_text.SetLabel(s)
1400+
13951401

1402+
@cbook.deprecated("3.3")
13961403
class StatusbarWx(StatusbarBase, wx.StatusBar):
13971404
"""For use with ToolManager."""
13981405
def __init__(self, parent, *args, **kwargs):

0 commit comments

Comments
 (0)