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

Skip to content

Commit e210502

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 912e814 commit e210502

4 files changed

Lines changed: 21 additions & 16 deletions

File tree

doc/api/api_changes_3.3/behaviour.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,9 @@ Upper case color strings
214214

215215
Support for passing single-letter colors (one of "rgbcmykw") as UPPERCASE
216216
characters is removed; these colors are now case-sensitive (lowercase).
217+
218+
Qt and wx backends no longer create a status bar by default
219+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
220+
The coordinates information is now displayed in the toolbar, consistently with
221+
the other backends. This is intended to simplify embedding of Matplotlib in
222+
larger GUIs, where Matplotlib may control the toolbar but not the status bar.

lib/matplotlib/backend_bases.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2889,6 +2889,7 @@ def mouse_move(self, event):
28892889
if data_str is not None:
28902890
s = s + ' ' + data_str
28912891

2892+
s = s.rstrip()
28922893
if len(self.mode):
28932894
self.set_message('%s, %s' % (self.mode, s))
28942895
else:

lib/matplotlib/backends/backend_qt5.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -539,23 +539,21 @@ def __init__(self, canvas, num):
539539
if self.toolbar:
540540
backend_tools.add_tools_to_container(self.toolbar)
541541
self.statusbar = StatusbarQt(self.window, self.toolmanager)
542+
sbs_height = self.statusbar.sizeHint().height()
543+
else:
544+
sbs_height = 0
542545

543546
if self.toolbar is not None:
544547
self.window.addToolBar(self.toolbar)
545-
if not self.toolmanager:
546-
# add text label to status bar
547-
statusbar_label = QtWidgets.QLabel()
548-
self.window.statusBar().addWidget(statusbar_label)
549-
self.toolbar.message.connect(statusbar_label.setText)
550548
tbs_height = self.toolbar.sizeHint().height()
551549
else:
552550
tbs_height = 0
553551

554552
# resize the main window so it will display the canvas with the
555553
# requested size:
556554
cs = canvas.sizeHint()
557-
sbs = self.window.statusBar().sizeHint()
558-
height = cs.height() + tbs_height + sbs.height()
555+
cs_height = cs.height()
556+
height = cs_height + tbs_height + sbs_height
559557
self.window.resize(cs.width(), height)
560558

561559
self.window.setCentralWidget(self.canvas)
@@ -588,7 +586,7 @@ def _get_toolbar(self, canvas, parent):
588586
# must be inited after the window, drawingArea and figure
589587
# attrs are set
590588
if matplotlib.rcParams['toolbar'] == 'toolbar2':
591-
toolbar = NavigationToolbar2QT(canvas, parent, False)
589+
toolbar = NavigationToolbar2QT(canvas, parent, True)
592590
elif matplotlib.rcParams['toolbar'] == 'toolmanager':
593591
toolbar = ToolbarQt(self.toolmanager, self.window)
594592
else:

lib/matplotlib/backends/backend_wx.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -928,13 +928,11 @@ def __init__(self, num, fig):
928928

929929
self.figmgr = FigureManagerWx(self.canvas, num, self)
930930

931-
statusbar = (StatusbarWx(self, self.toolmanager)
932-
if self.toolmanager else StatusBarWx(self))
933-
self.SetStatusBar(statusbar)
934931
self.toolbar = self._get_toolbar()
935932

936-
if self.toolmanager:
937-
backend_tools.add_tools_to_manager(self.toolmanager)
933+
if self.figmgr.toolmanager:
934+
self.SetStatusBar(StatusbarWx(self, self.figmgr.toolmanager))
935+
backend_tools.add_tools_to_manager(self.figmgr.toolmanager)
938936
if self.toolbar:
939937
backend_tools.add_tools_to_container(self.toolbar)
940938

@@ -1122,6 +1120,10 @@ def __init__(self, canvas):
11221120
self.Bind(wx.EVT_TOOL, getattr(self, callback),
11231121
id=self.wx_ids[text])
11241122

1123+
self.AddStretchableSpace()
1124+
self._label_text = wx.StaticText(self)
1125+
self.AddControl(self._label_text)
1126+
11251127
self.Realize()
11261128

11271129
NavigationToolbar2.__init__(self, canvas)
@@ -1292,9 +1294,7 @@ def statbar(self):
12921294
return self.GetTopLevelParent().GetStatusBar()
12931295

12941296
def set_message(self, s):
1295-
status_bar = self.GetTopLevelParent().GetStatusBar()
1296-
if status_bar is not None:
1297-
status_bar.set_function(s)
1297+
self._label_text.SetLabel(s)
12981298

12991299
def set_history_buttons(self):
13001300
can_backward = self._nav_stack._pos > 0

0 commit comments

Comments
 (0)