Skip to content

Commit e82fc97

Browse files
committed
Don't create a statusbar in Qt, wx backends.
Display the coordinates text on the right of the toolbar, consistently with the GTK3, wx, and (I think?) macosx backends. This helps when embedding Matplotlib in larger GUIs, because Matplotlib may not necessarily control the statusbar (which is typically global for the whole window) but controls the toolbar if there's one. If we decide to go this route we could probably also kill the status bar for toolmanager.
1 parent 47a15d9 commit e82fc97

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed

doc/api/api_changes_3.3/behaviour.rst

+6
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,9 @@ The default method used to format `.Slider` values has been changed to use a
163163
values are displayed with an appropriate number of significant digits even if
164164
they are much smaller or much bigger than 1. To restore the old behavior,
165165
explicitly pass a "%1.2f" as the *valfmt* parameter to `.Slider`.
166+
167+
Qt and wx backends no longer create a status bar by default
168+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
169+
The coordinates information is now displayed in the toolbar, consistently with
170+
the other backends. This is intended to simplify embedding of Matplotlib in
171+
larger GUIs, where Matplotlib may control the toolbar but not the status bar.

lib/matplotlib/backend_bases.py

+1
Original file line numberDiff line numberDiff line change
@@ -2847,6 +2847,7 @@ def mouse_move(self, event):
28472847
if data_str is not None:
28482848
s = s + ' ' + data_str
28492849

2850+
s = s.rstrip()
28502851
if len(self.mode):
28512852
self.set_message('%s, %s' % (self.mode, s))
28522853
else:

lib/matplotlib/backends/backend_qt5.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -555,23 +555,21 @@ def __init__(self, canvas, num):
555555
if self.toolbar:
556556
backend_tools.add_tools_to_container(self.toolbar)
557557
self.statusbar = StatusbarQt(self.window, self.toolmanager)
558+
sbs_height = self.statusbar.sizeHint().height()
559+
else:
560+
sbs_height = 0
558561

559562
if self.toolbar is not None:
560563
self.window.addToolBar(self.toolbar)
561-
if not self.toolmanager:
562-
# add text label to status bar
563-
statusbar_label = QtWidgets.QLabel()
564-
self.window.statusBar().addWidget(statusbar_label)
565-
self.toolbar.message.connect(statusbar_label.setText)
566564
tbs_height = self.toolbar.sizeHint().height()
567565
else:
568566
tbs_height = 0
569567

570568
# resize the main window so it will display the canvas with the
571569
# requested size:
572570
cs = canvas.sizeHint()
573-
sbs = self.window.statusBar().sizeHint()
574-
height = cs.height() + tbs_height + sbs.height()
571+
cs_height = cs.height()
572+
height = cs_height + tbs_height + sbs_height
575573
self.window.resize(cs.width(), height)
576574

577575
self.window.setCentralWidget(self.canvas)
@@ -604,7 +602,7 @@ def _get_toolbar(self, canvas, parent):
604602
# must be inited after the window, drawingArea and figure
605603
# attrs are set
606604
if matplotlib.rcParams['toolbar'] == 'toolbar2':
607-
toolbar = NavigationToolbar2QT(canvas, parent, False)
605+
toolbar = NavigationToolbar2QT(canvas, parent, True)
608606
elif matplotlib.rcParams['toolbar'] == 'toolmanager':
609607
toolbar = ToolbarQt(self.toolmanager, self.window)
610608
else:

lib/matplotlib/backends/backend_wx.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -936,9 +936,8 @@ def __init__(self, num, fig):
936936
# of the frame - so appearance is closer to GTK version
937937

938938
self.toolmanager = self._get_toolmanager()
939-
statusbar = (StatusbarWx(self, self.toolmanager)
940-
if self.toolmanager else StatusBarWx(self))
941-
self.SetStatusBar(statusbar)
939+
if self.toolmanager:
940+
self.SetStatusBar(StatusbarWx(self, self.toolmanager))
942941
self.toolbar = self._get_toolbar()
943942

944943
if self.toolmanager:
@@ -1151,6 +1150,10 @@ def _init_toolbar(self):
11511150
self.Bind(wx.EVT_TOOL, getattr(self, callback),
11521151
id=self.wx_ids[text])
11531152

1153+
self.AddStretchableSpace()
1154+
self._label_text = wx.StaticText(self)
1155+
self.AddControl(self._label_text)
1156+
11541157
self.Realize()
11551158

11561159
def zoom(self, *args):
@@ -1307,9 +1310,7 @@ def statbar(self):
13071310
return self.GetTopLevelParent().GetStatusBar()
13081311

13091312
def set_message(self, s):
1310-
status_bar = self.GetTopLevelParent().GetStatusBar()
1311-
if status_bar is not None:
1312-
status_bar.set_function(s)
1313+
self._label_text.SetLabel(s)
13131314

13141315
def set_history_buttons(self):
13151316
can_backward = self._nav_stack._pos > 0

0 commit comments

Comments
 (0)