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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
# Copyright 2013 Ceci Godoy - Samuel Reyes
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
"""HelloWorld Activity: A case study for developing an activity."""
import gtk
import gobject
import logging
from gettext import gettext as _
from sugar.activity import activity
from sugar.graphics.toolbarbox import ToolbarBox
from sugar.activity.widgets import ActivityButton
from sugar.activity.widgets import ActivityToolbox
from sugar.activity.widgets import TitleEntry
from sugar.activity.widgets import StopButton
from sugar.activity.widgets import ShareButton
OPTIONS = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '-', '*', '/', 'Borrar', '(', ')', 'Aceptar']
OPT_LENGHT = 5
OPT_FILAS = 4
DELAY = 1000
class CalculArteActivity(activity.Activity):
"""HelloWorldActivity class as specified in activity.info"""
def __init__(self, handle):
"""Set up the HelloWorld activity."""
activity.Activity.__init__(self, handle)
# we do not have collaboration features
# make the share option insensitive
self.max_participants = 1
# toolbar with the new toolbar redesign
toolbar_box = ToolbarBox()
activity_button = ActivityButton(self)
toolbar_box.toolbar.insert(activity_button, 0)
activity_button.show()
title_entry = TitleEntry(self)
toolbar_box.toolbar.insert(title_entry, -1)
title_entry.show()
share_button = ShareButton(self)
toolbar_box.toolbar.insert(share_button, -1)
share_button.show()
separator = gtk.SeparatorToolItem()
separator.props.draw = False
separator.set_expand(True)
toolbar_box.toolbar.insert(separator, -1)
separator.show()
stop_button = StopButton(self)
toolbar_box.toolbar.insert(stop_button, -1)
stop_button.show()
self.set_toolbar_box(toolbar_box)
toolbar_box.show()
# label with the text, make the string translatable
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('Ultimo resultado:')
#label_historial.justify()
#window.add(hbox)
self.set_canvas(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)
self.connect('key-press-event', self.__barrido_columnas_cb)
#canvas = self.get_canvas()
#canvas.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)
hbox.show_all()
#boton.show(False)
#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 __button_cb(self, button, entry, boton, label):
if (button.get_label() == 'Aceptar'):
resultado = str(eval(entry.get_text()))
label.set_label('Ultimo resultado:\n' + entry.get_text() + ': ' + resultado)
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('dark gray'))
for button in buttons_focus:
button.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color('light gray'))
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
|