Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/calcularte_app.py
blob: e61ee26f9e49ecd8af8bbbf7c671c73c0306b380 (plain)
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
119
120
121
122
123
#!/usr/bin/python
import gtk
import gobject


OPTIONS = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '-', '*', '/', 'Borrar', '(', ')', 'Aceptar']
OPT_LENGHT = 5
OPT_FILAS = 4
DELAY = 1000


class CalcularteApp():

    def __init__(self):
        window = gtk.Window()
        vbox = gtk.VBox()
        hbox = gtk.HBox()
        label_historial = gtk.Label()
        entry_visor = gtk.Entry()
        table = gtk.Table(5,5, True)
        boton = gtk.Button('boton falso')
        window.connect('destroy', self.destroy)

        label_historial.set_text('Historial')      
        #label_historial.justify()  
        
        
        window.add(hbox)
        hbox.add(vbox)
        hbox.add(label_historial)
        vbox.add(entry_visor)
        vbox.add(table)
        vbox.add(boton)

        OPTIONS.reverse()
        for j in range(4):
            
            for i in range(OPT_LENGHT):
                button = gtk.Button()
                option = OPTIONS.pop()
                button.set_label(option)
                button.connect('activate', self.__button_cb, entry_visor, boton, label_historial)
                window.connect('key-press-event', self.__barrido_columnas_cb)
                if option == 'Aceptar':
                    table.attach(button, i, i+3, j, j+1)
                    break
                else:
                    table.attach(button, i, i+1, j, j+1)
                
        window.show_all()
        window.grab_focus()

        #table.set_focus()
        OPTIONS.reverse()
        
        self._filas_index = 0
        self._columnas_index = 0
        self._flag_fila_columna = 0
        gobject.timeout_add(DELAY, self.__timeout_cb, table)

    def destroy(self, window, data=None):
        gtk.main_quit()

    def __button_cb(self, button, entry, boton, label):
        if (button.get_label() == 'Aceptar'):
            label.set_label(str(eval(entry.get_text())))
        else:    
            entry.set_text(entry.get_text() + button.get_label())
        self._flag_fila_columna = 0
        self._filas_index = 0
        self._columnas_index = 0
        boton.grab_focus()


    def __timeout_cb(self, table):
        #self._button_index = (self._button_index + 1) % OPT_LENGHT
        #buttons = hbox.get_children()
        #button = buttons[self._button_index]
        #button.grab_focus()
        if self._flag_fila_columna == 0:
            self._filas_index = (self._filas_index) % OPT_FILAS
            buttons = table.get_children()
            buttons.reverse()
            buttons_focus = buttons[self._filas_index*OPT_LENGHT:self._filas_index*OPT_LENGHT+OPT_LENGHT]
            for button in buttons:
                button.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color('gray'))
            for button in buttons_focus:
                button.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color('red'))
            self._filas_index += 1
        else: 
            
            buttons = table.get_children()
            buttons.reverse()

            if self._filas_index == 4:
                self._columnas_index = (self._columnas_index) % 3
                buttons_focus = buttons[(self._filas_index-1)*OPT_LENGHT:(self._filas_index-1)*OPT_LENGHT+3]
            else:
                self._columnas_index = (self._columnas_index) % OPT_LENGHT
                buttons_focus = buttons[(self._filas_index-1)*OPT_LENGHT:(self._filas_index-1)*OPT_LENGHT+OPT_LENGHT]
                
            print self._filas_index
            print self._columnas_index   
            button = buttons_focus[self._columnas_index]
            button.grab_focus()
            
            self._columnas_index += 1
        
        #buttons = table.get(row = self._filas_index)        
        
        
        return True
    
    def __barrido_columnas_cb(self, table, arg):
        self._flag_fila_columna = 1
 

  


if __name__ == "__main__":
    my_app = CalcularteApp()
    gtk.main()