Blame platform-demos/C/samples/statusbar.py

Packit 1470ea
from gi.repository import Gtk
Packit 1470ea
from gi.repository import Gdk
Packit 1470ea
import sys
Packit 1470ea
Packit 1470ea
Packit 1470ea
class MyWindow(Gtk.ApplicationWindow):
Packit 1470ea
    # a window
Packit 1470ea
Packit 1470ea
    def __init__(self, app):
Packit 1470ea
        Gtk.Window.__init__(self, title="StatusBar Example", application=app)
Packit 1470ea
        self.set_default_size(200, 100)
Packit 1470ea
Packit 1470ea
        # a label
Packit 1470ea
        label = Gtk.Label(label="Press any key or ")
Packit 1470ea
Packit 1470ea
        # a button
Packit 1470ea
        button = Gtk.Button(label="click me.")
Packit 1470ea
        # connected to a callback
Packit 1470ea
        button.connect("clicked", self.button_clicked_cb)
Packit 1470ea
Packit 1470ea
        # the statusbar
Packit 1470ea
        self.statusbar = Gtk.Statusbar()
Packit 1470ea
        # its context_id - not shown in the UI but needed to uniquely identify
Packit 1470ea
        # the source of a message
Packit 1470ea
        self.context_id = self.statusbar.get_context_id("example")
Packit 1470ea
        # we push a message onto the statusbar's stack
Packit 1470ea
        self.statusbar.push(
Packit 1470ea
            self.context_id, "Waiting for you to do something...")
Packit 1470ea
Packit 1470ea
        # a grid to attach the widgets
Packit 1470ea
        grid = Gtk.Grid()
Packit 1470ea
        grid.set_column_spacing(5)
Packit 1470ea
        grid.set_column_homogeneous(True)
Packit 1470ea
        grid.set_row_homogeneous(True)
Packit 1470ea
        grid.attach(label, 0, 0, 1, 1)
Packit 1470ea
        grid.attach_next_to(button, label, Gtk.PositionType.RIGHT, 1, 1)
Packit 1470ea
        grid.attach(self.statusbar, 0, 1, 2, 1)
Packit 1470ea
Packit 1470ea
        # add the grid to the window
Packit 1470ea
        self.add(grid)
Packit 1470ea
Packit 1470ea
    # callback function for the button clicked
Packit 1470ea
    # if the button is clicked the event is signaled to the statusbar
Packit 1470ea
    # onto which we push a new status
Packit 1470ea
    def button_clicked_cb(self, button):
Packit 1470ea
        self.statusbar.push(self.context_id, "You clicked the button.")
Packit 1470ea
Packit 1470ea
    # event handler
Packit 1470ea
    def do_key_press_event(self, event):
Packit 1470ea
    # any signal from the keyboard is signaled to the statusbar
Packit 1470ea
    # onto which we push a new status with the symbolic name
Packit 1470ea
    # of the key pressed
Packit 1470ea
        self.statusbar.push(self.context_id, Gdk.keyval_name(event.keyval) +
Packit 1470ea
                            " key was pressed.")
Packit 1470ea
        # stop the signal emission
Packit 1470ea
        return True
Packit 1470ea
Packit 1470ea
Packit 1470ea
class MyApplication(Gtk.Application):
Packit 1470ea
Packit 1470ea
    def __init__(self):
Packit 1470ea
        Gtk.Application.__init__(self)
Packit 1470ea
Packit 1470ea
    def do_activate(self):
Packit 1470ea
        win = MyWindow(self)
Packit 1470ea
        win.show_all()
Packit 1470ea
Packit 1470ea
    def do_startup(self):
Packit 1470ea
        Gtk.Application.do_startup(self)
Packit 1470ea
Packit 1470ea
app = MyApplication()
Packit 1470ea
exit_status = app.run(sys.argv)
Packit 1470ea
sys.exit(exit_status)