From add1a847e772d698eb6509b5891ca5b8830622e3 Mon Sep 17 00:00:00 2001 From: Cecilia Date: Fri, 25 Jan 2013 20:51:50 +0000 Subject: Depuracion de codigo y cambio de icono --- diff --git a/CalculArte.activity/activity.py b/CalculArte.activity/activity.py index 85436e2..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,33 +77,24 @@ 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(True) self.label_historial = gtk.Label() self.label_historial.set_line_wrap(True) self.entry_visor = gtk.Entry() - table = gtk.Table(5,5, True) + self.table = gtk.Table(5,5, True) boton = gtk.Button('boton falso') - #window.connect('destroy', self.destroy) - self.label_historial.set_text('Ultimo resultado:') - #label_historial.justify() - - - #window.add(hbox) self.set_canvas(hbox) hbox.add(vbox) hbox.add(self.label_historial) vbox.add(self.entry_visor) - vbox.add(table) + 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() @@ -113,26 +104,24 @@ class CalculArteActivity(activity.Activity): #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.hide() - - #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) + 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'): try: @@ -160,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() @@ -190,29 +177,25 @@ class CalculArteActivity(activity.Activity): 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): - """ datastore high-level interaction to read - logging.debug("The tmp_file is at %s, for reading", tmp_file)""" # resume metadata try: self.label_historial.set_label(self.metadata['entry']) - self._filas_index = int(self.metadata['fila']) + self._filas_index = int(self.metadata['fila']) self._columnas_index = int(self.metadata['columna']) self._flag_fila_columna = int(self.metadata['flag']) - buttons = table.get_children() + buttons = self.table.get_children() buttons.reverse() - buttons_focus = buttons[self._filas_index*OPT_LENGHT:self._filas_index*OPT_LENGHT+OPT_LENGHT] + 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: @@ -227,8 +210,6 @@ class CalculArteActivity(activity.Activity): data.close() def write_file(self, tmp_file): - """ datastore high-level interaction to write - logging.debug("The tmp_file is at %s, for writing", tmp_file)""" # save metadata self.metadata['entry'] = self.label_historial.get_label() diff --git a/CalculArte.activity/activity.pyc b/CalculArte.activity/activity.pyc index 4bc96b1..630b20c 100644 --- a/CalculArte.activity/activity.pyc +++ b/CalculArte.activity/activity.pyc Binary files differ 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() diff --git a/CalculArte.activity/activity/activity.info b/CalculArte.activity/activity/activity.info index 7ba9d8b..36a67d4 100644 --- a/CalculArte.activity/activity/activity.info +++ b/CalculArte.activity/activity/activity.info @@ -3,5 +3,5 @@ name = CalculArte activity_version = 1 bundle_id = org.calcularte.CalculArte exec = sugar-activity activity.CalculArteActivity -icon = activity-helloworld +icon = icon-abacus license = GPLv2+ diff --git a/CalculArte.activity/activity/activity.info~ b/CalculArte.activity/activity/activity.info~ index 4aa4f7f..7ba9d8b 100644 --- a/CalculArte.activity/activity/activity.info~ +++ b/CalculArte.activity/activity/activity.info~ @@ -1,7 +1,7 @@ [Activity] -name = HelloWorld -activity_version = 3 -bundle_id = org.sugarlabs.HelloWorld -exec = sugar-activity activity.HelloWorldActivity +name = CalculArte +activity_version = 1 +bundle_id = org.calcularte.CalculArte +exec = sugar-activity activity.CalculArteActivity icon = activity-helloworld license = GPLv2+ diff --git a/CalculArte.activity/activity/icon-abacus.svg b/CalculArte.activity/activity/icon-abacus.svg new file mode 100644 index 0000000..f26b42f --- /dev/null +++ b/CalculArte.activity/activity/icon-abacus.svg @@ -0,0 +1,79 @@ + + + + + + + Part of the Flat Icon Collection (Wed Aug 25 23:23:49 2004) + + + + hash + + application + computer + icons + theme + + + + + Danny Allen + + + + + Danny Allen + + + + + Danny Allen + + + + image/svg+xml + + + en + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file -- cgit v0.9.1