Blame platform-demos/C/samples/spinner.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="Spinner Example", application=app)
Packit 1470ea
        self.set_default_size(200, 200)
Packit 1470ea
        self.set_border_width(30)
Packit 1470ea
Packit 1470ea
        # a spinner
Packit 1470ea
        self.spinner = Gtk.Spinner()
Packit 1470ea
        # that by default spins
Packit 1470ea
        self.spinner.start()
Packit 1470ea
        # add the spinner to the window
Packit 1470ea
        self.add(self.spinner)
Packit 1470ea
Packit 1470ea
    # event handler
Packit 1470ea
    # a signal from the keyboard (space) controls if the spinner stops/starts
Packit 1470ea
    def do_key_press_event(self, event):
Packit 1470ea
        # keyname is the symbolic name of the key value given by the event
Packit 1470ea
        keyname = Gdk.keyval_name(event.keyval)
Packit 1470ea
        # if it is "space"
Packit 1470ea
        if keyname == "space":
Packit 1470ea
            # and the spinner is active
Packit 1470ea
            if self.spinner.get_property("active"):
Packit 1470ea
                # stop the spinner
Packit 1470ea
                self.spinner.stop()
Packit 1470ea
            # if the spinner is not active
Packit 1470ea
            else:
Packit 1470ea
                # start it again
Packit 1470ea
                self.spinner.start()
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)