Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAna Belén Trinidad Candia <belentwi@localhost.localdomain>2013-01-30 05:32:02 (GMT)
committer Ana Belén Trinidad Candia <belentwi@localhost.localdomain>2013-01-30 05:32:02 (GMT)
commitf5ac5389cf8c339b9d7e258336b0bc0f251d9cd5 (patch)
tree90945187307fbf1aa2b8512589bce31d8b2683d4
parent6fc4da37d973031122278d5481fe7d632eed1c5a (diff)
Version casi final
-rw-r--r--activity.py284
-rw-r--r--config.ini10
2 files changed, 198 insertions, 96 deletions
diff --git a/activity.py b/activity.py
index 7e15a1a..4791381 100644
--- a/activity.py
+++ b/activity.py
@@ -16,6 +16,7 @@
import gtk
import logging
+import random
from gettext import gettext as _
@@ -71,18 +72,13 @@ class AudioPatternActivity(activity.Activity):
jugarButton = gtk.Button()
principalVbox.pack_start(cabeceraHbox, fill=False)
jugarButton.set_label('JUGAR')
- jugarButton.connect('focus-in-event', self.__say_text)
+
+
+ labels_generados = ''
+
cabeceraHbox.pack_start(jugarButton, fill=False)
jugarButton.set_size_request(150, 50)
- #jugarButton.connect('clicked', self.__button_clicked_cb, 'CLICKED')
- #jugarButton.connect('enter', self.__button_clicked_cb, 'ENTER')
- #jugarButton.connect('activate', self.__button_clicked_cb, 'ACTIVATE')
- #jugarButton.connect('leave', self.__button_clicked_cb, 'LEAVE')
- #jugarButton.connect('pressed', self.__button_clicked_cb, 'PRESSED')
- #jugarButton.connect('released', self.__button_clicked_cb, 'RELEASED')
- #jugarButton.connect('BUTTON_PRESS', self.__button_clicked_cb, 'BUTTON_PRESS')
- #key_press_event
cancelarButton = gtk.Button()
cancelarButton.set_label('CANCELAR')
@@ -92,69 +88,40 @@ class AudioPatternActivity(activity.Activity):
cuerpoHbox = gtk.HBox(False, 20)
cancelarButton.set_size_request(150, 50)
- self.connect('key-press-event', self.__on_key_press_event)
-
- parser = SafeConfigParser()
- parser.read('config.ini')
-
seleccionadosTable = gtk.Table(4, 1, True)
seleccionadoUnoButton = gtk.Button()
- #seleccionadosTable.pack_start(seleccionadoUnoButton, fill=False)
-
-
seleccionadoDosButton = gtk.Button()
seleccionadoTresButton = gtk.Button()
+ self.resultadoButton = gtk.Button()
+
seleccionadosTable.set_size_request(200, 400)
- #resultadoButton = gtk.Button()
- seleccionadoUnoButton.connect('focus-in-event', self.__say_text)
- seleccionadoDosButton.connect('focus-in-event', self.__say_text)
- seleccionadoTresButton.connect('focus-in-event', self.__say_text)
opcionesTable = gtk.Table(3,3, True)
- opcionUno = gtk.Button()
-
- opcionDos = gtk.Button()
- opcionTres = gtk.Button()
- opcionCuatro = gtk.Button()
- opcionCinco = gtk.Button()
- opcionSeis = gtk.Button()
- opcionSiete = gtk.Button()
- opcionOcho = gtk.Button()
- opcionNueve = gtk.Button()
-
- opcionUno.connect('focus-in-event', self.__say_text)
- opcionDos.connect('focus-in-event', self.__say_text)
- opcionTres.connect('focus-in-event', self.__say_text)
- opcionCuatro.connect('focus-in-event', self.__say_text)
- opcionCinco.connect('focus-in-event', self.__say_text)
- opcionSeis.connect('focus-in-event', self.__say_text)
- opcionSiete.connect('focus-in-event', self.__say_text)
- opcionOcho.connect('focus-in-event', self.__say_text)
- opcionNueve.connect('focus-in-event', self.__say_text)
-
- uno = parser.get('cantidad', 'tres') + ' ' + parser.get('elemento', 'leones') + ' de ' + parser.get('material', 'metal')
- opcionUno.set_label(uno)
- dos = parser.get('cantidad', 'cuatro') + ' ' + parser.get('elemento', 'jirafas') + ' de ' + parser.get('material', 'madera')
- opcionDos.set_label(dos)
- tres = parser.get('cantidad', 'cinco') + ' ' + parser.get('elemento', 'monos') + ' de ' + parser.get('material', 'vidrio')
- opcionTres.set_label(tres)
- cuatro = parser.get('cantidad', 'cuatro') + ' ' + parser.get('elemento', 'leones') + ' de ' + parser.get('material', 'madera')
- opcionCuatro.set_label(cuatro)
- cinco = parser.get('cantidad', 'cinco') + ' ' + parser.get('elemento', 'jirafas') + ' de ' + parser.get('material', 'metal')
- opcionCinco.set_label(cinco)
- seis = parser.get('cantidad', 'tres') + ' ' + parser.get('elemento', 'monos') + ' de ' + parser.get('material', 'vidrio')
- opcionSeis.set_label(seis)
- siete = parser.get('cantidad', 'tres') + ' ' + parser.get('elemento', 'leones') + ' de ' + parser.get('material', 'madera')
- opcionSiete.set_label(siete)
- ocho = parser.get('cantidad', 'cuatro') + ' ' + parser.get('elemento', 'monos') + ' de ' + parser.get('material', 'metal')
- opcionOcho.set_label(ocho)
- nueve = parser.get('cantidad', 'cinco') + ' ' + parser.get('elemento', 'leones') + ' de ' + parser.get('material', 'vidrio')
- opcionNueve.set_label(nueve)
-
- self.set_canvas(principalVbox)
-
+ self.opcionUno = gtk.Button()
+
+ self.opcionDos = gtk.Button()
+ self.opcionTres = gtk.Button()
+ self.opcionCuatro = gtk.Button()
+ self.opcionCinco = gtk.Button()
+ self.opcionSeis = gtk.Button()
+ self.opcionSiete = gtk.Button()
+ self.opcionOcho = gtk.Button()
+ self.opcionNueve = gtk.Button()
+
+ self.opcionUno.connect('focus-in-event', self.__say_text)
+ self.opcionDos.connect('focus-in-event', self.__say_text)
+ self.opcionTres.connect('focus-in-event', self.__say_text)
+ self.opcionCuatro.connect('focus-in-event', self.__say_text)
+ self.opcionCinco.connect('focus-in-event', self.__say_text)
+ self.opcionSeis.connect('focus-in-event', self.__say_text)
+ self.opcionSiete.connect('focus-in-event', self.__say_text)
+ self.opcionOcho.connect('focus-in-event', self.__say_text)
+ self.opcionNueve.connect('focus-in-event', self.__say_text)
+
+ self.set_canvas(principalVbox)
+ self.connect('key-press-event', self.__on_key_press_event, seleccionadoUnoButton, seleccionadoDosButton, seleccionadoTresButton, jugarButton)
cabeceraHbox.add(jugarButton)
cabeceraHbox.add(cancelarButton)
@@ -174,56 +141,83 @@ class AudioPatternActivity(activity.Activity):
seleccionadosTable.attach(seleccionadoTresButton, 0, 1, 2, 3, 10, 20, 10, 5)
seleccionadoTresButton.set_size_request(180, 80)
- #seleccionadosTable.attach(selecionadoUnoButton, 0, 1
+
+ seleccionadosTable.attach(self.resultadoButton, 0, 1, 3 , 4, 10, 20, 10, 5)
+ self.resultadoButton.set_size_request(180, 80)
seleccionadosTable.set_row_spacings(5)
seleccionadosTable.set_col_spacings(10)
- opcionesTable.attach( opcionUno, 0, 1, 0, 1, 10, 10)
- opcionUno.set_size_request(180, 80)
+ opcionesTable.attach( self.opcionUno, 0, 1, 0, 1, 10, 10)
+ self.opcionUno.set_size_request(180, 80)
- opcionesTable.attach( opcionDos, 1, 2, 0, 1, 10, 10)
- opcionDos.set_size_request(180, 80)
+ opcionesTable.attach( self.opcionDos, 1, 2, 0, 1, 10, 10)
+ self.opcionDos.set_size_request(180, 80)
- opcionesTable.attach( opcionTres, 2, 3, 0, 1, 10, 10)
- opcionTres.set_size_request(180, 80)
+ opcionesTable.attach( self.opcionTres, 2, 3, 0, 1, 10, 10)
+ self.opcionTres.set_size_request(180, 80)
- opcionesTable.attach( opcionCuatro, 0, 1, 1, 2, 10, 10)
- opcionCuatro.set_size_request(180, 80)
+ opcionesTable.attach( self.opcionCuatro, 0, 1, 1, 2, 10, 10)
+ self.opcionCuatro.set_size_request(180, 80)
- opcionesTable.attach( opcionCinco, 1, 2, 1, 2, 10, 10)
- opcionCinco.set_size_request(180, 80)
+ opcionesTable.attach( self.opcionCinco, 1, 2, 1, 2, 10, 10)
+ self.opcionCinco.set_size_request(180, 80)
- opcionesTable.attach( opcionSeis, 2, 3, 1, 2, 10, 10)
- opcionSeis.set_size_request(180, 80)
+ opcionesTable.attach( self.opcionSeis, 2, 3, 1, 2, 10, 10)
+ self.opcionSeis.set_size_request(180, 80)
- opcionesTable.attach( opcionSiete, 0, 1, 2, 3, 10, 10)
- opcionSiete.set_size_request(180, 80)
+ opcionesTable.attach( self.opcionSiete, 0, 1, 2, 3, 10, 10)
+ self.opcionSiete.set_size_request(180, 80)
- opcionesTable.attach( opcionOcho, 1, 2, 2, 3, 10, 10)
- opcionOcho.set_size_request(180, 80)
+ opcionesTable.attach( self.opcionOcho, 1, 2, 2, 3, 10, 10)
+ self.opcionOcho.set_size_request(180, 80)
- opcionesTable.attach( opcionNueve, 2, 3, 2, 3, 10, 10)
- opcionNueve.set_size_request(180, 80)
+ opcionesTable.attach( self.opcionNueve, 2, 3, 2, 3, 10, 10)
+ self.opcionNueve.set_size_request(180, 80)
opcionesTable.set_row_spacings(50)
opcionesTable.set_col_spacings(10)
principalVbox.show_all()
- #window.show_all()
- #def destroy(self, window, data=None):
- #gtk.main_quit()
def __button_clicked_cb(self, window, data=None):
print(data)
- def __on_key_press_event(self, widget, event):
- keyname = gtk.gdk.keyval_name(event.keyval)
- #print "Key %s (%d) was pressed" % (keyname, event.keyval)
- # if keyname == 'Left' or keyname == 'Right' or keyname == 'Up' or keyname == 'Down':
- # widget_focus = widget.get_focus()
- # logging.debug(widget_focus.get_label())
+ def __on_key_press_event(self, widget, event, uno, dos, tres, jugar):
+ keyname = gtk.gdk.keyval_name(event.keyval)
+ widget_focus = widget.get_focus()
+ label = widget_focus.get_label()
+ if keyname == 'space' and label != '' and label != 'JUGAR' and label != 'CANCELAR' and widget_focus != uno and widget_focus != dos and widget_focus != tres:
+ # if keyname == 'space' and label != '' and label!= 'CANCELAR' and label!= 'JUGAR':
+ logging.debug(label)
+ if uno.get_label() == None:
+ uno.set_label(label)
+ widget_focus.set_label('')
+ else:
+ if dos.get_label() == None:
+ dos.set_label(label)
+ widget_focus.set_label('')
+ else:
+ if tres.get_label() == None:
+ tres.set_label(label)
+ widget_focus.set_label('')
+ self.__verificar_resultado(uno.get_label(), dos.get_label(), tres.get_label())
+
+ elif keyname == 'Return' and label == 'JUGAR':
+ labels_generados = []
+ labels_generados = self.__cargar_labels()
+
+ self.opcionUno.set_label(labels_generados[0])
+ self.opcionDos.set_label(labels_generados[1])
+ self.opcionTres.set_label(labels_generados[2])
+ self.opcionCuatro.set_label(labels_generados[3])
+ self.opcionCinco.set_label(labels_generados[4])
+ self.opcionSeis.set_label(labels_generados[5])
+ self.opcionSiete.set_label(labels_generados[6])
+ self.opcionOcho.set_label(labels_generados[7])
+ self.opcionNueve.set_label(labels_generados[8])
+
def __on_enter_event(self, widget, event):
widget_focus = widget.get_focus()
@@ -236,3 +230,111 @@ class AudioPatternActivity(activity.Activity):
def say(self, text):
Popen(['espeak', '-v', 'es', text])
+
+ def __generar_labels(self):
+ parser = SafeConfigParser()
+ parser.read('config.ini')
+
+ lista = []
+ secciones = parser.sections()
+ combinaciones = []
+ for i in range (9):
+ for section_name in secciones:
+ opciones = parser.options(section_name)
+ indice = random.randint(0, len(opciones) - 1)
+ lista.append(opciones[indice])
+
+ combinaciones.append(lista)
+ lista = []
+ return combinaciones
+
+
+ def __verificar_combinaciones(self, combinacionesUno, combinacionesDos, CombinacionesTres):
+ bandera = False
+ for fila in range(6):
+ if(combinacionesUno[0]== combinacionesDos[0] and combinacionesUno[0]== CombinacionesTres[0] or
+ combinacionesUno[1]== combinacionesDos[1] and combinacionesUno[1]== CombinacionesTres[1] or
+ combinacionesUno[2]== combinacionesDos[2] and combinacionesUno[2]== CombinacionesTres[2]):
+
+
+
+#combinaciones[fila][0]== combinaciones[fila+1][0] and combinaciones[fila][0]== combinaciones[fila+2][0] or
+ # combinaciones[fila][1]== combinaciones[fila+1][1] and combinaciones[fila][1]== combinaciones[fila+2][1] or
+ # combinaciones[fila][2]== combinaciones[fila+1][2] and combinaciones[fila][2]== combinaciones[fila+2][2]):
+
+ #logging.debug(combinaciones[fila][0] +' ' + combinaciones[fila][1] + ' ' + combinaciones[fila][2])
+ #logging.debug(combinaciones[fila+1][0] +' ' + combinaciones[fila+1][1] + ' ' + combinaciones[fila+1][2])
+ #logging.debug(combinaciones[fila+2][0] +' ' + combinaciones[fila+2][1] + ' ' + combinaciones[fila+2][2])
+ bandera = True
+
+ elif ((combinacionesUno[0]!= combinacionesDos[0] and combinacionesUno[0]!= CombinacionesTres[0] and
+ combinacionesDos[0] != CombinacionesTres[0]) and (combinacionesUno[1]!= combinacionesDos[1] and
+ combinacionesUno[1]!= CombinacionesTres[1] and combinacionesDos[1] != CombinacionesTres[1]) and
+ (combinacionesUno[2]!= combinacionesDos[2] and combinacionesUno[2]!= CombinacionesTres[2]) and
+ combinacionesDos[2] != CombinacionesTres[2]):
+
+ #(combinaciones[fila][0]!= combinaciones[fila+1][0] and combinaciones[fila][0]!= combinaciones[fila+2][0] and
+ #combinaciones[fila+2][1] != combinaciones[fila+2][0]) and (combinaciones[fila][1]!= combinaciones[fila+1][1] and #combinaciones[fila][1]!= combinaciones[fila+2][1] and combinaciones[fila+1][1] != combinaciones[fila+2][1]) and # (combinaciones[fila][2]!= combinaciones[fila+1][2] and combinaciones[fila][2]!= combinaciones[fila+2][2]) and
+ # combinaciones[fila+1][2] != combinaciones[fila+2][2]):
+ #logging.debug(combinaciones[fila][0] +' ' + combinaciones[fila][1] + ' ' + combinaciones[fila][2])
+ #logging.debug(combinaciones[fila+1][0] +' ' + combinaciones[fila+1][1] + ' ' + combinaciones[fila+1][2])
+ #logging.debug(combinaciones[fila+2][0] +' ' + combinaciones[fila+2][1] + ' ' + combinaciones[fila+2][2])
+ bandera = True
+
+ return bandera
+
+
+
+ def __cargar_labels(self):
+
+ combinaciones = self.__generar_labels()
+
+ #recibo = ''
+ #bandera =
+ #bandera = self.__verificar_combinaciones(combinaciones)
+ #for fila in range(6):
+
+# logging.debug('FILA ')
+ # logging.debug(combinaciones[fila])
+ bandera = False
+ fila = 0
+ while(bandera != True and fila < 6 ):
+ combinaciones = self.__generar_labels()
+
+ bandera = self.__verificar_combinaciones(combinaciones[fila], combinaciones[fila +1 ], combinaciones[fila +2 ] )
+ fila = fila +1
+
+ labels_generados = []
+ cadena_label = ''
+
+
+ for i in range (9):
+ cadena_label = combinaciones[i][0] + ' ' + combinaciones[i][1] + ' de ' + combinaciones[i][2]
+ labels_generados.append(cadena_label)
+ cadena_label = ''
+ return labels_generados
+
+ def __verificar_resultado(self, uno, dos, tres):
+ logging.debug(uno)
+ logging.debug(dos)
+ logging.debug(tres)
+ unoLista = uno.split(' ')
+ unoLista.remove('de')
+ dosLista = dos.split(' ')
+ dosLista.remove('de')
+ tresLista = tres.split(' ')
+ tresLista.remove('de')
+
+ bandera = self.__verificar_combinaciones(unoLista, dosLista, tresLista)
+
+ if(bandera):
+ self.resultadoButton.set_label('Ganaste!')
+ else:
+ self.resultadoButton.set_label('Intentalo de Nuevo!')
+
+
+
+
+
+
+
diff --git a/config.ini b/config.ini
index 8792440..10b58eb 100644
--- a/config.ini
+++ b/config.ini
@@ -1,13 +1,13 @@
-[elemento]
-leones = leones
-jirafas = jirafas
-monos = monos
-
[cantidad]
tres = 3
cuatro = 4
cinco = 5
+[elemento]
+leones = leones
+jirafas = jirafas
+monos = monos
+
[material]
metal = metal
madera = madera