diff options
author | Pablo Moleri <pmoleri@PABLOMOLERI-PC.(none)> | 2009-07-08 22:09:40 (GMT) |
---|---|---|
committer | Pablo Moleri <pmoleri@PABLOMOLERI-PC.(none)> | 2009-07-08 22:09:40 (GMT) |
commit | 4b3895d65773defd7f47b8241bba8762ccdb486a (patch) | |
tree | 687b56735801208eabc979ade6f8ec745673d039 | |
parent | dd5e480d25adcb295833e84609fb8fa73f3b4c0d (diff) |
Se cambia el main a parentesis.py para correr standalone.
Se agrega ParentesisActivity.py para correr como actividad.
Se modifica activity.info para llamar a ParentesisActivity.
-rw-r--r-- | parentesis.activity/ParentesisActivity.py | 26 | ||||
-rw-r--r-- | parentesis.activity/activity/activity.info | 5 | ||||
-rw-r--r-- | parentesis.activity/activity/activity.info~ | 5 | ||||
-rw-r--r-- | parentesis.activity/parentesis.py | 317 | ||||
-rw-r--r-- | parentesis.activity/parentesis.py.bak | 121 | ||||
-rw-r--r-- | parentesis.activity/prueba.txt | 0 | ||||
-rwxr-xr-x | parentesis.activity/setup.py | 6 |
7 files changed, 355 insertions, 125 deletions
diff --git a/parentesis.activity/ParentesisActivity.py b/parentesis.activity/ParentesisActivity.py new file mode 100644 index 0000000..05f7fad --- /dev/null +++ b/parentesis.activity/ParentesisActivity.py @@ -0,0 +1,26 @@ +from sugar.activity import activity + +class ParentesisActivity(activity.Activity): + def __init__(self, handle): + activity.Activity.__init__(self, handle) + self.connect('destroy', self._cleanup_cb) + + self.gamename = 'Parentesis' + self.set_title("Parentesis") + + # connect to the in/out events + self.connect('focus_in_event', self._focus_in) + self.connect('focus_out_event', self._focus_out) + + # The activity is a subclass of Window, so it passses itself to the init function + parentesis.init(False, self) + + def _cleanup_cb(self, data=None): + return + + # We could use these methods to conserve power by having the activity stop processing when it is in the background. + def _focus_in(self, event, data=None): + return + + def _focus_out(self, event, data=None): + return diff --git a/parentesis.activity/activity/activity.info b/parentesis.activity/activity/activity.info index 3048f03..99a6dc4 100644 --- a/parentesis.activity/activity/activity.info +++ b/parentesis.activity/activity/activity.info @@ -1,9 +1,10 @@ [Activity] -name = (P*A+R*E+N*T+E*S+I*S) +name = (P*A+R*E+N*T+E*S+I*S) bundle_id = org.ceibaljam.parentesis -class = parentesis.Parentesis +class = ParentesisActivity.ParentesisActivity icon = parentesis-icon activity_version = 1 host_version = 1 show_launcher = no license = GPLv2+ + diff --git a/parentesis.activity/activity/activity.info~ b/parentesis.activity/activity/activity.info~ index 405fe9f..3b5b49e 100644 --- a/parentesis.activity/activity/activity.info~ +++ b/parentesis.activity/activity/activity.info~ @@ -1,9 +1,10 @@ [Activity] name = (P*A+R*E+N*T+E*S+I*S) bundle_id = org.ceibaljam.parentesis -class = parentesis.Parentesis -icon = activity-imageviewer +class = ParentesisActivity.ParentesisActivity +icon = parentesis-icon activity_version = 1 host_version = 1 show_launcher = no license = GPLv2+ + diff --git a/parentesis.activity/parentesis.py b/parentesis.activity/parentesis.py new file mode 100644 index 0000000..41389b8 --- /dev/null +++ b/parentesis.activity/parentesis.py @@ -0,0 +1,317 @@ +#!/usr/bin/env python
+# -*- coding: cp1252 -*-
+
+# example-start buttons buttons.py
+
+import pygtk
+pygtk.require('2.0')
+import gtk
+import pango
+import logica
+
+ESTADO_VACIO = 0
+ESTADO_IZQ = 1
+ESTADO_DER = 2
+
+IGUAL = "="
+
+class Controlador:
+ def __init__(self):
+ print "CONTROLADOR INICIADO!"
+ #self.serie = logica.generarCasos() # obtiene una serie o el conjunto de casos a resolver
+ #self.total_casos = len(self.serie) # los casos totales de la serie
+ #self.total_casos_pasados = 0 # cuenta los casos resueltos
+ self.siguienteSerie()
+
+ def siguienteSerie(self):
+ self.serie = logica.generarCasos()
+ self.total_casos = len(self.serie) # los casos totales de la serie
+ self.total_casos_pasados = 0 # cuenta los casos resueltos
+ self.casoActual = self.serie.pop()
+ self.resActual = eval(self.casoActual)
+ self.fraccion_pbar = 1.0 / self.total_casos # calculo cuanto tiene que avanzar la barra en base a los casos totales
+ self.listaCasosResueltos = []
+
+ def siguienteCaso(self):
+ """Obtiene el siguiente caso, si no hay mas casos, genera una serie"""
+ self.total_casos_pasados += 1
+ if self.serie: ## si quedan casos
+ self.casoActual = self.serie.pop()
+ self.resActual = eval(self.casoActual)
+
+ def imprimirEstado(self):
+ """Da un resumen de las variables del controlador - Es para DEBUGGEO"""
+ print ""
+ print "############## ESTADO DEL CONTROLADOR ###################"
+ print "Serie actual:", self.serie
+ print "Total Casos :", self.total_casos_pasados, "/", self.total_casos
+ print "Caso actual :", self.casoActual
+ print "Res actual :", self.resActual
+ print "Casos res :", self.listaCasosResueltos
+ print "############## -------o-------------- ###################"
+ print ""
+
+ def disclaimer(self):
+ print "Esta es una version de desarrollo! :)"
+
+class Vista:
+ def crear_ventana_principal(self, w):
+ w.set_title("PARENTESIS BETA! - CeibalJam - Montevideo - Uruguay - ")
+ w.connect("destroy", lambda wid: gtk.main_quit())
+ w.connect("delete_event", lambda a1, a2:gtk.main_quit())
+ w.set_border_width(10)
+ w.resize(SCREENSIZE[0], SCREENSIZE[1])
+
+ return w
+
+ def crear_combo_box_niveles(self):
+ cbox = gtk.combo_box_entry_new_text() ## Funcion ULTRAMAGICA sacada de internet!. Ver manual para mas informacion.
+ cbox.append_text('Nivel 1 (no sirve)')
+ cbox.append_text('Nivel 2 (no sirve)')
+ cbox.append_text('Nivel 3 (no sirve)')
+ cbox.set_active(0)
+
+ return cbox
+
+ def __init__(self, toplevel_window):
+ # Create a new window
+ self.window = self.crear_ventana_principal(toplevel_window)
+ self.contr = Controlador()
+ self.contr.disclaimer()
+ self.contr.imprimirEstado()
+
+ self.contr.siguienteSerie() ## Creo una serie para poder tener datos del problema para desplegar en la VISTA
+ print "EL CASO ACTUAL ES", self.contr.casoActual
+ self.vbox = gtk.VBox()
+ self.vbox.show()
+ self.hbox = gtk.HBox()
+ self.hbox.show()
+ self.et_instruc = self.crear_etiqueta_instrucciones()
+ self.et_instruc.show()
+ self.et_estado = gtk.Label("Aqui van a ir mensajes de feedback")
+ self.et_estado.show()
+
+
+ self.combobox = self.crear_combo_box_niveles()
+ self.combobox.show()
+
+ self.botonAyuda = self.crear_boton_ayuda()
+ self.botonAyuda.show()
+
+ self.hbox_niveles_y_ayuda = gtk.HBox()
+ self.hbox_niveles_y_ayuda.show()
+
+ self.hbox_niveles_y_ayuda.pack_start(self.combobox)
+ self.hbox_niveles_y_ayuda.pack_start(self.botonAyuda)
+
+ self.botonCambiar = self.crear_boton_cambiar()
+ self.botonCambiar.show()
+
+ self.botonSolucion = self.crear_boton_solucion()
+ self.botonSolucion.show()
+
+ self.hbox_cambiar_y_mensajes = gtk.HBox()
+ self.hbox_cambiar_y_mensajes.show()
+ self.hbox_cambiar_y_mensajes.pack_start(self.botonCambiar)
+
+ self.pbar = gtk.ProgressBar()
+ self.pbar.show()
+
+ self.et_sol = gtk.Label("La respuesta es **********")
+ self.et_sol.show()
+
+ self.vbox.pack_start(self.et_instruc)
+ self.vbox.pack_start(self.hbox_niveles_y_ayuda)
+ self.vbox.pack_start(self.hbox)
+ self.vbox.pack_start(self.pbar)
+ self.vbox.pack_start(self.hbox_cambiar_y_mensajes)
+ self.vbox.pack_start(self.botonSolucion)
+ self.vbox.pack_start(self.et_estado)
+ self.vbox.pack_start(self.et_sol)
+
+ self.window.add(self.vbox)
+
+ self.MostrarProblema(self.contr.casoActual)
+ self.window.show()
+
+ def crear_etiqueta_instrucciones(self):
+ et = gtk.Label("Debes poner los parentesis para que el resultado sea " +
+ str(self.contr.resActual))
+ et.show()
+ return et
+
+ def MostrarProblema(self, prob):
+ self.solucion_izquierdos = set()
+ self.solucion_derechos = set()
+ self.et_instruc.set_text("Debes poner los parentesis para que el resultado sea " +
+ str(self.contr.resActual))
+ self.et_sol.set_text("La respuesta es **********")
+
+ for w in self.hbox.get_children():
+ self.hbox.remove(w)
+
+ prob = self.contr.casoActual
+ prob_str = prob
+ prob = list(prob)
+ pos = 0
+ boton = self.crear_boton(pos)
+ self.agregar_widget(boton)
+ while pos < len(prob):
+ car = prob[pos]
+ if car == "(":
+ self.solucion_izquierdos.add(pos)
+ pos = pos + 1
+ elif car == ")":
+ self.solucion_derechos.add(pos)
+ pos = pos + 1
+ else:
+ car_etiqueta = gtk.Label(car)
+ self.agregar_widget(car_etiqueta)
+ pos = pos + 1
+ boton = self.crear_boton(pos)
+ self.agregar_widget(boton)
+
+ igual = self.crear_boton_igual()
+ self.agregar_widget(igual)
+ self.agregar_widget(gtk.Label(eval(prob_str)))
+
+ def agregar_widget(self, widget):
+ ''' Agrega el boton a la lista de botones '''
+ self.hbox.pack_start(widget)
+ widget.show()
+
+ def crear_boton(self, pos):
+ boton = BotonParentesis(pos)
+ boton.connect('clicked', self.boton_activado)
+ return boton
+
+ def crear_boton_igual(self):
+ boton = gtk.Button(IGUAL)
+ boton.connect('clicked', self.boton_igual_activado)
+ return boton
+
+ def crear_boton_cambiar(self):
+ boton = gtk.Button("Cambiar numeros")
+ boton.connect('clicked', self.boton_cambiar_activado)
+ return boton
+
+ def crear_boton_ayuda(self):
+ boton = gtk.Button(stock=gtk.STOCK_HELP)
+ boton.connect('clicked', self.boton_ayuda_activado)
+ return boton
+
+ def crear_boton_solucion(self):
+ boton = gtk.Button("Ver solucion")
+ boton.connect('clicked', self.boton_solucion_activado)
+ return boton
+
+ def crear_dialogo_ayuda(self):
+ dialogo = gtk.Dialog("Ayuda :)") #, parent=None, flags=0, buttons=None)
+ dialogo.resize(800,400)
+ et = gtk.Label("Este es el texto para la ayuda, hay que ver que le ponemos")
+ et.show()
+ dialogo.vbox.pack_start(et)
+ dialogo.show()
+ return dialogo
+
+ def boton_activado(self, boton):
+ boton.iterarEstado()
+
+ def boton_cambiar_activado(self, boton):
+ self.pbar.set_fraction(0.0)
+ self.contr.siguienteSerie()
+ self.MostrarProblema(self.contr.casoActual)
+
+ def boton_solucion_activado(self, boton):
+ self.et_sol.set_text(self.contr.casoActual)
+
+ def boton_ayuda_activado(self, boton):
+ dialog = self.crear_dialogo_ayuda()
+
+ def boton_igual_activado(self, boton):
+ respuesta_izquierdos = set()
+ respuesta_derechos = set()
+ for widget in self.hbox.get_children():
+ if isinstance(widget,BotonParentesis):
+ estado = widget.getEstado()
+ if estado == ESTADO_IZQ:
+ respuesta_izquierdos.add(widget.getPos())
+ if estado == ESTADO_DER:
+ respuesta_derechos.add(widget.getPos())
+
+ if respuesta_izquierdos == self.solucion_izquierdos and respuesta_derechos == self.solucion_derechos:
+ self.et_estado.set_label("Muy bien!")
+ self.contr.listaCasosResueltos.append(self.contr.casoActual)
+ new_val = self.pbar.get_fraction() + self.contr.fraccion_pbar
+ if new_val > 1.0:
+ new_val = 0.0
+
+ self.pbar.set_fraction(new_val)
+
+ self.contr.siguienteCaso()
+ self.contr.imprimirEstado()
+ if self.contr.total_casos_pasados == self.contr.total_casos:
+ self.contr.siguienteSerie()
+ self.pbar.set_fraction(0.0)
+ self.MostrarProblema(self.contr.casoActual)
+ else:
+ self.et_estado.set_label("INCORRECTO!: Esta mal. Muy feo.")
+ ## Si no completo la serie
+ ##Paso al caso siguiente
+ ## ELSE: paso a la SERIE siguiente
+
+class BotonParentesis(gtk.Button):
+
+ def __init__(self, pos):
+ gtk.Button.__init__(self, "")
+ self._pos = pos
+ self._estado = ESTADO_VACIO
+
+ def getPos(self):
+ return self._pos
+
+ def setPos(self, pos):
+ self._pos = pos
+
+ def iterarEstado(self):
+ if self._estado == ESTADO_VACIO:
+ self._estado = ESTADO_IZQ
+ self.set_label("(")
+ elif self._estado == ESTADO_IZQ:
+ self._estado = ESTADO_DER
+ self.set_label(")")
+ elif self._estado == ESTADO_DER:
+ self._estado = ESTADO_VACIO
+ self.set_label("")
+
+ def getEstado(self):
+ return self._estado
+
+# This function is the common entry point for sugar and standalone mode
+# standalone is a boolean indicating Standalone mode or Sugar mode.
+def init(standalone, toplevel_window):
+ # Sets a global variables
+ global standalone_mode, SCREENSIZE, SCALE, FONT_SIZE
+ standalone_mode = standalone
+ if standalone:
+ SCREENSIZE = (600,412)
+ SCALE = (1./2, 1./2)
+ FONT_SIZE = 18
+ font_desc = pango.FontDescription("sans 72")
+ if font_desc:
+ toplevel_window.modify_font(font_desc)
+ else:
+ SCREENSIZE = (1200,825)
+ SCALE = (1, 1)
+ FONT_SIZE = 36
+ Vista(toplevel_window)
+
+# This is the main function in standalone mode
+def main():
+ toplevel_window = gtk.Window(gtk.WINDOW_TOPLEVEL)
+ init(True, toplevel_window)
+ gtk.main()
+ return 0
+
+if __name__ == "__main__":
+ main()
diff --git a/parentesis.activity/parentesis.py.bak b/parentesis.activity/parentesis.py.bak deleted file mode 100644 index fef0bbb..0000000 --- a/parentesis.activity/parentesis.py.bak +++ /dev/null @@ -1,121 +0,0 @@ -# -*- encoding: UTF-8 -*- -import gtk -from sugar.activity.activity import Activity, ActivityToolbox -import logica - -ESTADO_VACIO = 0 -ESTADO_IZQ = 1 -ESTADO_DER = 2 - -IGUAL = "=" - -class Parentesis(Activity): - def __init__(self, handle): - Activity.__init__(self,handle) - - self.toolbox = ActivityToolbox(self) - self.set_toolbox(self.toolbox) - - self.vbox = gtk.VBox() - self.hbox = gtk.HBox() - self.msj = gtk.Label() - self.vbox.pack_start(self.msj) - self.vbox.pack_start(self.hbox) - self.set_canvas(self.vbox) - self.show_all() - - self.solucion_izquierdos = set() - self.solucion_derechos = set() - - self.problemas = logica.generarCasos() - self.MostrarProblema(self.problemas.pop()) - - def MostrarProblema(self, prob): - for w in self.hbox.get_children(): - self.hbox.remove(w) - - prob_str = prob - prob = list(prob) - pos = 0 - boton = self.crear_boton(pos) - self.agregar_widget(boton) - while pos < len(prob): - car = prob[pos] - if car == "(": - self.solucion_izquierdos.add(pos) - pos = pos + 1 - elif car == ")": - self.solucion_derechos.add(pos) - pos = pos + 1 - else: - car_etiqueta = gtk.Label(car) - self.agregar_widget(car_etiqueta) - pos = pos + 1 - boton = self.crear_boton(pos) - self.agregar_widget(boton) - - igual = self.crear_boton_igual() - self.agregar_widget(igual) - self.agregar_widget(gtk.Label(eval('2+1'))) - - def agregar_widget(self, widget): - ''' Agrega el boton a la lista de botones ''' - self.hbox.pack_start(widget) - widget.show() - - def crear_boton(self, pos): - boton = BotonParentesis(pos) - boton.connect('clicked', self.boton_activado) - return boton - - def crear_boton_igual(self): - boton = gtk.Button(IGUAL) - boton.connect('clicked', self.boton_igual_activado) - return boton - - def boton_activado(self, boton): - boton.iterarEstado() - - def boton_igual_activado(self, boton): - respuesta_izquierdos = set() - respuesta_derechos = set() - for widget in self.hbox.get_children(): - if isinstance(widget,BotonParentesis): - estado = widget.getEstado() - if estado == ESTADO_IZQ: - respuesta_izquierdos.add(widget.getPos()) - if estado == ESTADO_DER: - respuesta_derechos.add(widget.getPos()) - - if respuesta_izquierdos == self.solucion_izquierdos and respuesta_derechos == self.solucion_derechos: - self.msj.set_label("Muy Bien!") - self.MostrarProblema(self.problemas.pop()) - else: - self.msj.set_label("Incorrecto") - -class BotonParentesis(gtk.Button): - - def __init__(self, pos): - gtk.Button.__init__(self, "") - self._pos = pos - self._estado = ESTADO_VACIO - - def getPos(self): - return self._pos - - def setPos(self, pos): - self._pos = pos - - def iterarEstado(self): - if self._estado == ESTADO_VACIO: - self._estado = ESTADO_IZQ - self.set_label("(") - elif self._estado == ESTADO_IZQ: - self._estado = ESTADO_DER - self.set_label(")") - elif self._estado == ESTADO_DER: - self._estado = ESTADO_VACIO - self.set_label("") - - def getEstado(self): - return self._estado
\ No newline at end of file diff --git a/parentesis.activity/prueba.txt b/parentesis.activity/prueba.txt deleted file mode 100644 index e69de29..0000000 --- a/parentesis.activity/prueba.txt +++ /dev/null diff --git a/parentesis.activity/setup.py b/parentesis.activity/setup.py new file mode 100755 index 0000000..e8d870b --- /dev/null +++ b/parentesis.activity/setup.py @@ -0,0 +1,6 @@ +#!/usr/bin/env python + +from sugar.activity import bundlebuilder + +bundlebuilder.start() + |