Statusbar

A Statusbar is positioned at the bottom of some application windows to provide status messages and information about an applications current process. For example, it can be used to indicate the line and column number within a text editor or which website a hyperlink directs to in a web browser.

Messages on a Statusbar are stored in a stack, with the first message pushed on to the Statusbar being the last message to be popped from it.

Note

Statusbar widgets should be used to display messages of low-importance. If a user must see a message, a MessageDialog or InfoBar is the recommended widget to use.

Constructor

The Statusbar can be constructed using:

statusbar = Gtk.Statusbar()

Methods

Before messages can be displayed on the Statusbar, a context identifier needs to be retrieved. This context identifier is a string which identifies particular message types, for example; errors and warnings. This can be retrived with:

statusbar.get_context_id(context)

The context parameter is simply a string describing the context (purpose) of the message. The method returns the context id which is used to push, pop and remove messages.

To push a message onto the Statusbar call:

statusbar.push(context, text)

When calling the .push() method, a message id is returned. This value is unique and identifies a particular message within the Statusbar.

Messages can be popped from the list with:

statusbar.pop(context)

Alternatively, if a message is to be completely removed from the Statusbar stack, call:

statusbar.remove(context, message)

The context is the one specified before calling the .push() method. The message parameter takes the message id for the message to be removed, and must be specified.

Alternatively, to remove all messages within a particular context use:

statusbar.remove_all(context)

In some cases, it can be useful to add widgets such as ComboBox widgets to a Statusbar to provide quick setting selection as well as providing information. To retrieve the container, which can then be added to use:

statusbar.get_message_area()

The .get_message_area() method returns a Box with horizontal orientation.

Signals

The commonly used signals of an Statusbar are:

"text-pushed" (context, text)
"text-popped" (context, text)

The text-pushed and text-popped signals emit when a message is pushed to or popped from the Statusbar. Both signals return the context id of the message and the textual content.

Example

Below is an example of a Statusbar:

#!/usr/bin/env python3

from gi.repository import Gtk

class Statusbar(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self)
        self.connect("destroy", Gtk.main_quit)

        grid = Gtk.Grid()
        grid.set_column_spacing(5)
        self.add(grid)

        buttonPush = Gtk.Button("Push")
        buttonPush.connect("clicked", self.on_push_clicked)
        grid.attach(buttonPush, 0, 0, 1, 1)

        buttonPop = Gtk.Button("Pop")
        buttonPop.connect("clicked", self.on_pop_clicked)
        grid.attach(buttonPop, 1, 0, 1, 1)

        buttonRemove = Gtk.Button("Remove All")
        buttonRemove.connect("clicked", self.on_remove_all_clicked)
        grid.attach(buttonRemove, 2, 0, 1, 1)

        self.statusbar = Gtk.Statusbar()
        self.context = self.statusbar.get_context_id("example")
        grid.attach(self.statusbar, 0, 1, 3, 1)

        self.count = 0

    def on_push_clicked(self, button):
        self.count += 1

        message = "Message number %i" % (self.count)
        self.statusbar.push(self.context, message)

    def on_pop_clicked(self, button):
        self.statusbar.pop(self.context)

    def on_remove_all_clicked(self, button):
        self.statusbar.remove_all(self.context)

window = Statusbar()
window.show_all()

Gtk.main()

Download: Statusbar