Gtk.Statusbar


Gtk.Statusbar — Report messages of minor importance to the user

Object Hierarchy:

    GObject
    ╰── GInitiallyUnowned
        ╰── Gtk.Widget
            ╰── Gtk.Container
                ╰── Gtk.Box
                    ╰── Gtk.Statusbar

Functions:


Signals:

  • “text-popped” (statusbar, context_id, text, user_data)
  • “text-pushed” (statusbar, context_id, text, user_data)

Description:

A Gtk.Statusbar is usually placed along the bottom of an application's main Gtk.Window. It may provide a regular commentary of the application's status (as is usually the case in a web browser, for example), or may be used to simply output a message when the status changes, (when an upload is complete in an FTP client, for example).

Status bars in GTK+ maintain a stack of messages. The message at the top of the each bar’s stack is the one that will currently be displayed.

Any messages added to a statusbar’s stack must specify a context id that is used to uniquely identify the source of a message. This context id can be generated by Gtk.Statusbar::get_context_id(), given a message and the statusbar that it will be added to. Note that messages are stored in a stack, and when choosing which message to display, the stack structure is adhered to, regardless of the context identifier of a message.

One could say that a statusbar maintains one stack of messages for display purposes, but allows multiple message producers to maintain sub-stacks of the messages they produced (via context ids).

Status bars are created using Gtk.Statusbar::new().

Messages are added to the bar’s stack with Gtk.Statusbar::push().

The message at the top of the stack can be removed using Gtk.Statusbar::pop(). A message can be removed from anywhere in the stack if its message id was recorded at the time it was added. This is done using Gtk.Statusbar::remove().


Function Details:

new()

new () -> Gtk.Widget

Creates a new Gtk.Statusbar ready for messages.

  • Returns: the new Gtk.Statusbar

get_context_id()

get_context_id (self, context_description:str) -> int

Returns a new context identifier, given a description of the actual context. Note that the description is not shown in the UI.

  • Returns: an integer id

push()

push (self, context_id:int, text:str) -> int

Pushes a new message onto a statusbar’s stack.

  • Returns: a message id that can be used withGtk.Statusbar:remove().

pop()

pop (self, context_id:int)

Removes the first message in the Gtk.Statusbar’s stackwith the given context id. Note that this may not change the displayed message, if the message at the top of the stack has a different context id.


remove()

remove (self, context_id:int, message_id:int)

Forces the removal of a message from a statusbar’s stack. The exact context_id and message_id must be specified.


remove_all()

remove_all (self, context_id:int)

Forces the removal of all messages from a statusbar'sstack with the exact context_id.

  • Since: 2.22

get_message_area()

get_message_area (self) -> Gtk.Box

Retrieves the box containing the label widget.

  • Returns: a Gtk.Box.

  • Since: 2.20


Example:

import gi
gi.require_version('Gtk', '3.0')
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()

results matching ""

    No results matching ""