Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/CalculArte.activity/activity.py~
diff options
context:
space:
mode:
Diffstat (limited to 'CalculArte.activity/activity.py~')
-rw-r--r--CalculArte.activity/activity.py~124
1 files changed, 81 insertions, 43 deletions
diff --git a/CalculArte.activity/activity.py~ b/CalculArte.activity/activity.py~
index 377dc4e..87fd14d 100644
--- a/CalculArte.activity/activity.py~
+++ b/CalculArte.activity/activity.py~
@@ -14,7 +14,7 @@
# 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."""
+"""CalculArteActivity: Calculadora que realiza operaciones basicas disenhada para personas con problemas de motricidad fisica."""
import gtk
import gobject
@@ -40,10 +40,10 @@ DELAY = 1000
class CalculArteActivity(activity.Activity):
- """HelloWorldActivity class as specified in activity.info"""
+ """CalculArteActivity class as specified in activity.info"""
def __init__(self, handle):
- """Set up the HelloWorld activity."""
+ """Set up the CalculArte activity."""
activity.Activity.__init__(self, handle)
# we do not have collaboration features
@@ -77,64 +77,69 @@ class CalculArteActivity(activity.Activity):
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)
+ hbox = gtk.HBox(True)
+ self.label_historial = gtk.Label()
+ self.label_historial.set_line_wrap(True)
+ self.entry_visor = gtk.Entry()
+ self.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.label_historial.set_text('Ultimo resultado:')
self.set_canvas(hbox)
hbox.add(vbox)
- hbox.add(label_historial)
- vbox.add(entry_visor)
- vbox.add(table)
+ hbox.add(self.label_historial)
+ vbox.add(self.entry_visor)
+ vbox.add(self.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)
+ button.connect('activate', self.__button_cb, self.entry_visor, boton, self.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)
+ self.table.attach(button, i, i+3, j, j+1)
break
else:
- table.attach(button, i, i+1, j, j+1)
-
+ self.table.attach(button, i, i+1, j, j+1)
hbox.show_all()
- #boton.show(False)
-
- #window.grab_focus()
-
- #table.set_focus()
+ boton.hide()
+
OPTIONS.reverse()
self._filas_index = 0
self._columnas_index = 0
self._flag_fila_columna = 0
- gobject.timeout_add(DELAY, self.__timeout_cb, table)
+ gobject.timeout_add(DELAY, self.__timeout_cb, self.table)
def __button_cb(self, button, entry, boton, label):
+ """ Callback que maneja el evento activate """
+
if (button.get_label() == 'Aceptar'):
- resultado = str(eval(entry.get_text()))
- label.set_label('Ultimo resultado:\n' + entry.get_text() + ': ' + resultado)
+ try:
+
+ resultado = str(eval(entry.get_text()))
+ label.set_label('Ultimo resultado:\n' + entry.get_text() + ': ' + resultado)
+ except ZeroDivisionError:
+ label.set_label('Ultimo resultado:\n Error: Division por cero [' + entry.get_text()+']' )
+ entry.set_text("")
+
+ except:
+ label.set_label('Ultimo resultado:\n Imposible de realizar la operacion. Intente nuevamente')
+ entry.set_text("")
+
+
+ entry.set_text("")
+ elif (button.get_label() == 'Borrar'):
+ entry.set_text(entry.get_text()[0:entry.get_text_length()-1])
+
else:
entry.set_text(entry.get_text() + button.get_label())
self._flag_fila_columna = 0
@@ -144,10 +149,8 @@ class CalculArteActivity(activity.Activity):
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()
+ """ Callback que realiza el barrido automatico"""
+
if self._flag_fila_columna == 0:
self._filas_index = (self._filas_index) % OPT_FILAS
buttons = table.get_children()
@@ -170,17 +173,52 @@ class CalculArteActivity(activity.Activity):
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):
+ """ Callback para cambiar valor del flag que verifica si corresponde a una fila o columna"""
self._flag_fila_columna = 1
+
+
+ def read_file(self, tmp_file):
+
+ # resume metadata
+ try:
+ self.label_historial.set_label(self.metadata['entry'])
+ self._filas_index = int(self.metadata['fila'])
+ self._columnas_index = int(self.metadata['columna'])
+ self._flag_fila_columna = int(self.metadata['flag'])
+ buttons = self.table.get_children()
+ buttons.reverse()
+ buttons_focus = buttons[(self._filas_index-1)*OPT_LENGHT:(self._filas_index-1)*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'))
+ except KeyError:
+ logging.error("No entry metadata")
+
+ # resume data
+ data = open(tmp_file, "r")
+ buffer = self.entry_visor
+ buffer.set_text(data.read())
+ data.close()
+
+ def write_file(self, tmp_file):
+
+ # save metadata
+ self.metadata['entry'] = self.label_historial.get_label()
+ self.metadata['fila'] = self._filas_index
+ self.metadata['columna'] = self._columnas_index
+ self.metadata['flag'] = self._flag_fila_columna
+
+ # save data
+ data = open(tmp_file, "w")
+ buffer = self.entry_visor.get_text()
+ data.write(buffer)
+ data.close()