1from gi.repository import Gtk 2from gi.repository import Gdk 3import sys 4 5 6class MyWindow(Gtk.ApplicationWindow): 7 # a window 8 9 def __init__(self, app): 10 Gtk.Window.__init__(self, title="Spinner Example", application=app) 11 self.set_default_size(200, 200) 12 self.set_border_width(30) 13 14 # a spinner 15 self.spinner = Gtk.Spinner() 16 # that by default spins 17 self.spinner.start() 18 # add the spinner to the window 19 self.add(self.spinner) 20 21 # event handler 22 # a signal from the keyboard (space) controls if the spinner stops/starts 23 def do_key_press_event(self, event): 24 # keyname is the symbolic name of the key value given by the event 25 keyname = Gdk.keyval_name(event.keyval) 26 # if it is "space" 27 if keyname == "space": 28 # and the spinner is active 29 if self.spinner.get_property("active"): 30 # stop the spinner 31 self.spinner.stop() 32 # if the spinner is not active 33 else: 34 # start it again 35 self.spinner.start() 36 # stop the signal emission 37 return True 38 39 40class MyApplication(Gtk.Application): 41 42 def __init__(self): 43 Gtk.Application.__init__(self) 44 45 def do_activate(self): 46 win = MyWindow(self) 47 win.show_all() 48 49 def do_startup(self): 50 Gtk.Application.do_startup(self) 51 52app = MyApplication() 53exit_status = app.run(sys.argv) 54sys.exit(exit_status) 55