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

Skip to content

Commit c7f5923

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 9e20541 commit c7f5923

File tree

4 files changed

+21
-16
lines changed

4 files changed

+21
-16
lines changed

doc/api/api_changes_3.3/behaviour.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,3 +274,9 @@ instead of ::
274274

275275
<a list of 3 Lists of Patches objects> # "bar", "barstacked"
276276
<a list of 3 Lists of Patches objects> # "step", "stepfilled"
277+
278+
Qt and wx backends no longer create a status bar by default
279+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
280+
The coordinates information is now displayed in the toolbar, consistently with
281+
the other backends. This is intended to simplify embedding of Matplotlib in
282+
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
@@ -2893,6 +2893,7 @@ def mouse_move(self, event):
28932893
if data_str is not None:
28942894
s = s + ' ' + data_str
28952895

2896+
s = s.rstrip()
28962897
if len(self.mode):
28972898
self.set_message('%s, %s' % (self.mode, s))
28982899
else:

lib/matplotlib/backends/backend_qt5.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -550,23 +550,21 @@ def __init__(self, canvas, num):
550550
if self.toolbar:
551551
backend_tools.add_tools_to_container(self.toolbar)
552552
self.statusbar = StatusbarQt(self.window, self.toolmanager)
553+
sbs_height = self.statusbar.sizeHint().height()
554+
else:
555+
sbs_height = 0
553556

554557
if self.toolbar is not None:
555558
self.window.addToolBar(self.toolbar)
556-
if not self.toolmanager:
557-
# add text label to status bar
558-
statusbar_label = QtWidgets.QLabel()
559-
self.window.statusBar().addWidget(statusbar_label)
560-
self.toolbar.message.connect(statusbar_label.setText)
561559
tbs_height = self.toolbar.sizeHint().height()
562560
else:
563561
tbs_height = 0
564562

565563
# resize the main window so it will display the canvas with the
566564
# requested size:
567565
cs = canvas.sizeHint()
568-
sbs = self.window.statusBar().sizeHint()
569-
height = cs.height() + tbs_height + sbs.height()
566+
cs_height = cs.height()
567+
height = cs_height + tbs_height + sbs_height
570568
self.window.resize(cs.width(), height)
571569

572570
self.window.setCentralWidget(self.canvas)
@@ -599,7 +597,7 @@ def _get_toolbar(self, canvas, parent):
599597
# must be inited after the window, drawingArea and figure
600598
# attrs are set
601599
if matplotlib.rcParams['toolbar'] == 'toolbar2':
602-
toolbar = NavigationToolbar2QT(canvas, parent, False)
600+
toolbar = NavigationToolbar2QT(canvas, parent, True)
603601
elif matplotlib.rcParams['toolbar'] == 'toolmanager':
604602
toolbar = ToolbarQt(self.toolmanager, self.window)
605603
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)
@@ -1300,9 +1302,7 @@ def statbar(self):
13001302
return self.GetTopLevelParent().GetStatusBar()
13011303

13021304
def set_message(self, s):
1303-
status_bar = self.GetTopLevelParent().GetStatusBar()
1304-
if status_bar is not None:
1305-
status_bar.set_function(s)
1305+
self._label_text.SetLabel(s)
13061306

13071307
def set_history_buttons(self):
13081308
can_backward = self._nav_stack._pos > 0

0 commit comments

Comments
 (0)