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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
import gtk
import gobject
import math
from parser import parser
from sintetizar import sintetizar
DELAY = 1300
LENGHT = 4
class MyGUI:
def __init__( self, title):
self.window = gtk.Window()
self.title = title
self.window.set_title(title)
self._pressButton_counter = 0
self.window.set_size_request( 260, -1)
self.window.connect("destroy", self.destroy)
self.listaSecciones = []
parser(self.listaSecciones)
print self.listaSecciones[1]
self.lenghtSecciones = int(math.sqrt(len(self.listaSecciones)))
self.hbox = gtk.HBox()
self.table = gtk.Table(LENGHT, LENGHT, True)
self.indiceSecciones = 0
self.create_interior(self.table, self.listaSecciones)
self.window.add(self.hbox)
self.window.show_all()
self._button_index = 0
self._button_index_2 = 0
self._indice = 0
self._button_list = []
gobject.timeout_add(DELAY, self.__timeout_cb, self.table)
def create_interior( self, table, listaSecciones):
self.hbox.add(table)
inicio_left = 0
fin_right = 1
inicio_top = 0
fin_bottom = 1
for colu in range(LENGHT):
for fila in range(LENGHT):
boton = gtk.Button(str(fila)+"-"+str(colu))
boton.connect('key-press-event', self.__pressButton_count)
table.attach(boton, inicio_left, fin_right, inicio_top, fin_bottom)
boton.show()
inicio_top = inicio_top + 1
fin_bottom = fin_bottom + 1
inicio_top = 0
fin_bottom = 1
inicio_left = inicio_left + 1
fin_right = fin_right + 1
#self.table.attach(child, left_attach, right_attach, top_attach, bottom_attach)
table.show()
def __timeout_cb(self, table):
buttons = table.get_children()
buttons.reverse()
if (self._pressButton_counter == 1):
self._button_index_2 = (self._button_index_2 + 1) % len(self._button_list)
self._button_list[self._button_index_2].grab_focus()
self._button_list[self._button_index_2].modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color('red'))
self._button_list[self._button_index_2 - 1].modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color('green'))
elif (self._pressButton_counter == 0):
self._button_index = (self._button_index) % len(buttons)
self._button_list = buttons[self._button_index:self._button_index+LENGHT]
for i in self._button_list:
i.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color('green'))
for cero in range(self._button_index):
buttons[cero].modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color('gray'))
self._button_index = self._button_index + LENGHT
indice = self._button_index
while indice < len(buttons):
buttons[indice].modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color('gray'))
indice = indice + 1
else:
self._pressButton_counter = 0
self.__newWindow(self._button_list[self._button_index_2], self._button_list[self._button_index_2].get_label())
return True
def __pressButton_count(self, table, arg):
self._pressButton_counter = self._pressButton_counter + 1
def __newWindow(self, button, button_label):
#self.hbox.remove(self.table)
#label = gtk.Label()
#label.set_text(button_label)
#self.hbox.add(label)
#label.show()
#self.hbox.show()
sintetizar(button_label)
def main( self):
gtk.main()
def destroy(self, w):
gtk.main_quit()
if __name__ == "__main__":
m = MyGUI( "Table example")
m.main()
|