1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#!/usr/bin/python
import gtk
import gobject
OPTIONS = ['a', 'b', 'c', 'd']
OPT_LENGHT = 4
DELAY = 1000
class MyApp():
def __init__(self):
window = gtk.Window()
vbox = gtk.VBox()
hbox = gtk.HBox()
label = gtk.Label()
window.connect('destroy', self.destroy)
window.add(vbox)
vbox.add(label)
vbox.add(hbox)
for option in OPTIONS:
button = gtk.Button()
button.set_label(option)
button.connect('activate', self.__button_cb, label, option)
hbox.add(button)
window.show_all()
self._button_index = 0
gobject.timeout_add(DELAY, self.__timeout_cb, hbox)
def destroy(self, window, data=None):
gtk.main_quit()
def __button_cb(self, button, label, option):
label.set_text(option)
def __timeout_cb(self, hbox):
self._button_index = (self._button_index + 1) % OPT_LENGHT
buttons = hbox.get_children()
button = buttons[self._button_index]
button.grab_focus()
return True
if __name__ == "__main__":
my_app = MyApp()
gtk.main()
|