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

Skip to content

Commit 110253f

Browse files
OceanWolffariza
authored andcommitted
Statusbar
1 parent 9da2b13 commit 110253f

File tree

3 files changed

+59
-52
lines changed

3 files changed

+59
-52
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
:class:`ToolContainerBase`
3434
The base class for the Toolbar class of each interactive backend.
3535
36+
:class:`StatusbarBase`
37+
The base class for the messaging area.
3638
"""
3739

3840
from __future__ import (absolute_import, division, print_function,
@@ -3605,15 +3607,9 @@ class ToolContainerBase(object):
36053607

36063608
def __init__(self, navigation):
36073609
self.navigation = navigation
3608-
3609-
self.navigation.nav_connect('tool_message_event', self._message_cbk)
36103610
self.navigation.nav_connect('tool_removed_event',
36113611
self._remove_tool_cbk)
36123612

3613-
def _message_cbk(self, event):
3614-
"""Captures the 'tool_message_event' to set the message on the toolbar"""
3615-
self.set_message(event.message)
3616-
36173613
def _tool_toggled_cbk(self, event):
36183614
"""Captures the 'tool-trigger-toolname
36193615
@@ -3714,17 +3710,6 @@ def add_toolitem(self, name, group, position, image, description, toggle):
37143710

37153711
raise NotImplementedError
37163712

3717-
def set_message(self, s):
3718-
"""Display a message on toolbar or in status bar
3719-
3720-
Parameters
3721-
----------
3722-
s : String
3723-
Message text
3724-
"""
3725-
3726-
pass
3727-
37283713
def toggle_toolitem(self, name, toggled):
37293714
"""Toggle the toolitem without firing event
37303715
@@ -3752,3 +3737,25 @@ def remove_toolitem(self, name):
37523737
"""
37533738

37543739
raise NotImplementedError
3740+
3741+
3742+
class StatusbarBase(object):
3743+
"""Base class for the statusbar"""
3744+
def __init__(self, navigation):
3745+
self.navigation = navigation
3746+
self.navigation.nav_connect('tool_message_event', self._message_cbk)
3747+
3748+
def _message_cbk(self, event):
3749+
"""Captures the 'tool_message_event' and set the message"""
3750+
self.set_message(event.message)
3751+
3752+
def set_message(self, s):
3753+
"""Display a message on toolbar or in status bar
3754+
3755+
Parameters
3756+
----------
3757+
s : str
3758+
Message text
3759+
"""
3760+
3761+
pass

lib/matplotlib/backend_tools.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ def _mouse_move(self, event):
921921
"""Default tools"""
922922

923923
toolbar_tools = [['navigation', ['home', 'back', 'forward']],
924-
['zoompan', ['zoom', 'pan']],
925-
['layout', ['subplots']],
926-
['io', ['save']]]
924+
['zoompan', ['zoom', 'pan']],
925+
['layout', ['subplots']],
926+
['io', ['save']]]
927927
"""Default tools in the toolbar"""

lib/matplotlib/backends/backend_gtk3.py

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ def fn_name(): return sys._getframe(1).f_code.co_name
3030
from matplotlib._pylab_helpers import Gcf
3131
from matplotlib.backend_bases import RendererBase, GraphicsContextBase, \
3232
FigureManagerBase, FigureCanvasBase, NavigationToolbar2, cursors, TimerBase
33-
from matplotlib.backend_bases import ShowBase, ToolContainerBase, NavigationBase
34-
from matplotlib.backend_tools import SaveFigureBase, ConfigureSubplotsBase, \
35-
tools, toolbar_tools, SetCursorBase, RubberbandBase
33+
from matplotlib.backend_bases import (ShowBase, ToolContainerBase,
34+
NavigationBase, StatusbarBase)
35+
from matplotlib.backend_tools import (SaveFigureBase, ConfigureSubplotsBase,
36+
tools, toolbar_tools, SetCursorBase, RubberbandBase)
3637

3738
from matplotlib.cbook import is_string_like, is_writable_file_like
3839
from matplotlib.colors import colorConverter
@@ -416,22 +417,30 @@ def __init__(self, canvas, num):
416417
self.canvas.show()
417418

418419
self.vbox.pack_start(self.canvas, True, True, 0)
420+
# calculate size for window
421+
w = int (self.canvas.figure.bbox.width)
422+
h = int (self.canvas.figure.bbox.height)
419423

420424
self.navigation = self._get_navigation()
421425
self.toolbar = self._get_toolbar()
426+
self.statusbar = None
427+
428+
def add_widget(child, expand, fill, padding):
429+
child.show()
430+
self.vbox.pack_end(child, False, False, 0)
431+
size_request = child.size_request()
432+
return size_request.height
433+
422434
if matplotlib.rcParams['toolbar'] == 'navigation':
423435
self.navigation.add_tools(tools)
424436
self.toolbar.add_tools(toolbar_tools)
425-
426-
# calculate size for window
427-
w = int (self.canvas.figure.bbox.width)
428-
h = int (self.canvas.figure.bbox.height)
437+
self.statusbar = StatusbarGTK3(self.navigation)
438+
h += add_widget(self.statusbar, False, False, 0)
439+
h += add_widget(Gtk.HSeparator(), False, False, 0)
429440

430441
if self.toolbar is not None:
431442
self.toolbar.show()
432-
self.vbox.pack_end(self.toolbar, False, False, 0)
433-
size_request = self.toolbar.size_request()
434-
h += size_request.height
443+
h += add_widget(self.toolbar, False, False, 0)
435444

436445
self.window.set_default_size (w, h)
437446

@@ -767,23 +776,6 @@ def __init__(self, navigation):
767776
self.pack_start(self._toolbar, False, False, 0)
768777
self._toolbar.show_all()
769778
self._toolitems = {}
770-
self._setup_message_area()
771-
772-
def _setup_message_area(self):
773-
box = Gtk.Box()
774-
box.set_property("orientation", Gtk.Orientation.HORIZONTAL)
775-
sep = Gtk.Separator()
776-
sep.set_property("orientation", Gtk.Orientation.VERTICAL)
777-
box.pack_start(sep, False, True, 0)
778-
self.message = Gtk.Label()
779-
box.pack_end(self.message, False, False, 0)
780-
self.pack_end(box, False, False, 5)
781-
box.show_all()
782-
783-
sep = Gtk.Separator()
784-
sep.set_property("orientation", Gtk.Orientation.HORIZONTAL)
785-
self.pack_end(sep, False, True, 0)
786-
sep.show_all()
787779

788780
def add_toolitem(self, name, group, position, image_file, description,
789781
toggle):
@@ -811,9 +803,6 @@ def add_toolitem(self, name, group, position, image_file, description,
811803
def _call_tool(self, btn, name):
812804
self.trigger_tool(name)
813805

814-
def set_message(self, s):
815-
self.message.set_label(s)
816-
817806
def toggle_toolitem(self, name, toggled):
818807
if name not in self._toolitems:
819808
return
@@ -824,9 +813,9 @@ def toggle_toolitem(self, name, toggled):
824813

825814
def remove_toolitem(self, name):
826815
if name not in self._toolitems:
827-
self.set_message('%s Not in toolbar' % name)
816+
self.navigation.message_event('%s Not in toolbar' % name, self)
828817
return
829-
for toolitem, signal in self._toolitems[name]:
818+
for toolitem, _signal in self._toolitems[name]:
830819
self._toolbar.remove(toolitem)
831820
del self._toolitems[name]
832821

@@ -837,6 +826,17 @@ def add_separator(self, pos=-1):
837826
return toolitem
838827

839828

829+
class StatusbarGTK3(StatusbarBase, Gtk.Statusbar):
830+
def __init__(self, *args, **kwargs):
831+
StatusbarBase.__init__(self, *args, **kwargs)
832+
Gtk.Statusbar.__init__(self)
833+
self._context = self.get_context_id('message')
834+
835+
def set_message(self, s):
836+
self.pop(self._context)
837+
self.push(self._context, s)
838+
839+
840840
class SaveFigureGTK3(SaveFigureBase):
841841

842842
def get_filechooser(self):

0 commit comments

Comments
 (0)