Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Darío Giménez <jgimenez@localhost.localdomain>2010-05-25 02:11:09 (GMT)
committer José Darío Giménez <jgimenez@localhost.localdomain>2010-05-25 02:11:09 (GMT)
commite39007a9c8dab6f3dea126a2e0ebc75b9de44fa8 (patch)
treeb12683590676592768a6dc3f67a2c117b5a41b2e
parent2130a90777f47bfdf4f56d449d32eaaa38d8b6ba (diff)
Changes made to the activity to work for 1 puzzle, it evaluates the answer in a case-comparision
-rw-r--r--Controller.py24
-rw-r--r--PuzzleView.py10
-rw-r--r--Toolbar.py46
-rw-r--r--View.py33
-rw-r--r--[-rwxr-xr-x]activity.py6
-rw-r--r--controller.py45
-rwxr-xr-x[-rw-r--r--]doc/collaboration-diagram.diabin2950 -> 2950 bytes
-rw-r--r--puzzle.py67
-rw-r--r--puzzleView.py7
-rwxr-xr-xpuzzles/1/Matematica/prueba.txt7
-rwxr-xr-xscript01.svg8
-rw-r--r--session.py36
-rw-r--r--toolbar.py46
-rw-r--r--view.py53
14 files changed, 252 insertions, 136 deletions
diff --git a/Controller.py b/Controller.py
deleted file mode 100644
index 06bab5a..0000000
--- a/Controller.py
+++ /dev/null
@@ -1,24 +0,0 @@
-# -*- coding: utf-8 -*-
-import View
-class Controller():
- def __init__(self,activity):
- self.activity=activity
- view=View(self)
-
- def evaluateAnswer(answer):
- pass
-
- def nextPuzzle():
- pass
-
- def newGame(difficulty,topic):
- pass
-
- def end():
- pass
-
- def pause():
- pass
-
- def getClue():
- pass \ No newline at end of file
diff --git a/PuzzleView.py b/PuzzleView.py
deleted file mode 100644
index ff19cc3..0000000
--- a/PuzzleView.py
+++ /dev/null
@@ -1,10 +0,0 @@
-# -*- coding: utf-8 -*-
-import gtk
-import Controller
-class PuzzleView():
- def __init__(self,controller):
- #contenedor = gtk.EventBox()
- #imagen = gtk.Image()
- #imagen.setFromFile("script01.svg")
- #imagen.show()
- return image
diff --git a/Toolbar.py b/Toolbar.py
deleted file mode 100644
index 4f38195..0000000
--- a/Toolbar.py
+++ /dev/null
@@ -1,46 +0,0 @@
-# -*- coding: utf-8 -*-
-import gtk
-import Controller
-class Toolbar():
- def __init__(self,contoller):
- toolbox=activity.ActivityToolbox(controller.activity)
- toolbox.show()
- controller.activity.set_toolbox(toolbox)
- #El Layout inicial
-
- #encabezado = gtk.Label(' El encabezado, categoria y dificultad')
- #encabezado.show()
-
- #Preparando el menu
- menu = gtk.HBox()
- alineacion = gtk.Alignment(0.5, 1, 0.5, 1)
- categoriaL = gtk.Label("Categoria:")
- categoriaL.show()
- categorias = gtk.combo_box_new_text()
- categorias.insert_text(0,"Todas")
- categorias.insert_text(1,"Matematica")
- categorias.insert_text(2,"Historia")
- categorias.insert_text(3,"Castellano")
- categorias.set_active(0)
- categorias.show()
- dificultadL = gtk.Label("Dificultad:")
- dificultadL.show()
- dificultades = gtk.combo_box_new_text()
- dificultades.insert_text(0,"nivel 1")
- dificultades.insert_text(1,"nivel 2")
- dificultades.insert_text(2, "nivel 3")
- dificultades.set_active(0)
- dificultades.show()
- iniciarB = gtk.Button("Inicio")
- iniciarB.show()
- finalizarB = gtk.Button("Terminar")
- finalizarB.show()
- menu.pack_start(alineacion)
- menu.pack_start(categoriaL)
- menu.pack_start(categorias)
- menu.pack_start(dificultadL)
- menu.pack_start(dificultades)
- menu.pack_start(iniciarB)
- menu.pack_start(finalizarB)
- menu.show()
- return menu
diff --git a/View.py b/View.py
deleted file mode 100644
index 18f3a72..0000000
--- a/View.py
+++ /dev/null
@@ -1,33 +0,0 @@
-# -*- coding: utf-8 -*-
-import gtk
-import Controller
-class View()
- def __init__(self, controller):
- menu=Toolbar(controller)
- image=PuzzleView(controller)
-
- #respuesta
- respuesta = gtk.HBox()
- respL = gtk.Label("Respuesta:")
- respL.show()
- respT = gtk.Entry()
- respT.show()
- respB = gtk.Button("Respuesta")
- respB.show()
- sgteB = gtk.Button("Siguiente")
- sgteB.show()
- respuesta.pack_start(respL, False, False, 0)
- respuesta.pack_start(respT)
- respuesta.pack_start(respB)
- respuesta.pack_start(sgteB)
- respuesta.show()
-
- l1 = gtk.VBox()
- #agrupo todo
- #l1.pack_start(encabezado)
- l1.pack_start(menu, False, False, 4)
- l1.pack_start(respuesta, False, False, 360)
- #l1.pack_start(imagen)
-
- l1.show()
- controller.activity.set_canvas(l1) \ No newline at end of file
diff --git a/activity.py b/activity.py
index a87514d..2abc797 100755..100644
--- a/activity.py
+++ b/activity.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
from sugar.activity import activity
import logging
-import Controller
+import controller
class SugarBrainActivity(activity.Activity):
def __init__(self, handle):
- activity.Activity.__init__(activity, handle)
- controller=Controller(self) \ No newline at end of file
+ activity.Activity.__init__(self, handle)
+ self.controller=controller.Controller(self)
diff --git a/controller.py b/controller.py
new file mode 100644
index 0000000..3c9cde5
--- /dev/null
+++ b/controller.py
@@ -0,0 +1,45 @@
+# -*- coding: utf-8 -*-
+import view
+import session
+class Controller():
+ def __init__(self,activity):
+ self.activity=activity
+ self.view=view.View(self)
+
+ def newGame(self,widget):
+ self.session=session.Session(self.get_active_text(self.view.toolbar.categorias),self.get_active_text(self.view.toolbar.dificultades))
+ self.view.refreshQuestion()
+
+ def evaluateAnswer(self,widget):
+ if self.session.currentPuzzle().answered:
+ if self.session.currentPuzzle().evaluateAnswer(self.view.respT.get_text()):
+ status='Correcto.'
+ else:
+ status='Incorrecto.'
+ self.view.showAnswer(status)
+
+ def hasClue(self,widget):
+ return self.session.currentPuzzle().hasClue()
+
+ def getClue(self,widget):
+ return self.session.currentPuzzle().getClue()
+
+ def nextPuzzle(self,widget):
+ if self.session.currentPuzzle().answered:
+ return self.session.nextPuzzle()
+ else:
+ return self.evaluateAnswer(widget)
+
+ def pause(self,widget):
+ return self.session.pause()
+
+ def end(self,widget):
+ return self.session.end()
+
+ def get_active_text(self,combobox):
+ model = combobox.get_model()
+ active = combobox.get_active()
+ if active < 0:
+ return None
+ return model[active][0]
+
diff --git a/doc/collaboration-diagram.dia b/doc/collaboration-diagram.dia
index 53ffbc0..53ffbc0 100644..100755
--- a/doc/collaboration-diagram.dia
+++ b/doc/collaboration-diagram.dia
Binary files differ
diff --git a/puzzle.py b/puzzle.py
index 6a3b067..9834d2e 100644
--- a/puzzle.py
+++ b/puzzle.py
@@ -1,22 +1,49 @@
+# -*- coding: utf-8 -*-
+import sys
+
+difficulties = { 'facil': 1, 'medio': 2, 'dificil': 3 }
+topics = ['matematica', 'logica', 'memoria']
+
+class Topic:
+ def __init__(self, new):
+ self.name = new
+
+class Difficulty:
+ def __init__(self, name):
+ self.name = name
+ self.level = difficulties[name]
class Puzzle:
-
- class Topic:
- def __init__(self, new):
- self.name = new
- class Difficulty:
- def __init__(self, new):
- self.name = new
-
- def __init__(self, archivo):
- try:
- dic = {}
- exec(open(archivo).read(), dic)
- self.question = dic['question']
- self.answer = dic['answer']
- self.topic = Topic(dic['topic'])
- self.difficulty = Difficulty(dic['difficulty'])
- self.score = int(dic['score'])
- except:
- print "Error"
-
+ def __init__(self, archivo):
+ try:
+ dic = {}
+ exec(open(archivo).read(), dic)
+ self.question = dic['question']
+ self.answer = dic['answer']
+ self.image = dic['image']
+ self.topic = Topic(dic['topic'])
+ self.difficulty = Difficulty(dic['difficulty'])
+ self.score = int(dic['score'])
+ if 'clue' in dic:
+ self.clue=dic['clue']
+ else:
+ self.clue=''
+ self.answered=False
+ except KeyError:
+ print 'Falta un atributo.'
+ except:
+ print "Error"
+ print sys.exc_info()[0]
+
+ def __str__(self):
+ return self.question
+
+ def evaluateAnswer(self,answer):
+ self.answered=True
+ return self.answer==answer
+
+ def hasClue(self):
+ self.clue!=''
+
+ def getClue(self):
+ return self.clue
diff --git a/puzzleView.py b/puzzleView.py
new file mode 100644
index 0000000..3840338
--- /dev/null
+++ b/puzzleView.py
@@ -0,0 +1,7 @@
+# -*- coding: utf-8 -*-
+import gtk
+class PuzzleView():
+ def __init__(self,view):
+ self.imagen = gtk.Image()
+ self.imagen.set_from_file("script01.svg")
+ self.imagen.show()
diff --git a/puzzles/1/Matematica/prueba.txt b/puzzles/1/Matematica/prueba.txt
new file mode 100755
index 0000000..95c3996
--- /dev/null
+++ b/puzzles/1/Matematica/prueba.txt
@@ -0,0 +1,7 @@
+question = 'La pregunta'
+image = '/home/algo.svg'
+answer = 'La respuesta'
+topic = 'matematica'
+difficulty = 'facil'
+score = '5'
+
diff --git a/script01.svg b/script01.svg
new file mode 100755
index 0000000..d5b42fe
--- /dev/null
+++ b/script01.svg
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [
+ <!ENTITY stroke_color "#666666">
+ <!ENTITY fill_color "#FFFFFF">
+]>
+<svg xmlns="http://www.w3.org/2000/svg" width="55" height="55">
+ <rect x="5" y="5" width="45" height="45" stroke="#666666" fill="#FFFFFF" stroke-width="3.5"/>
+</svg>
diff --git a/session.py b/session.py
new file mode 100644
index 0000000..81fc3b3
--- /dev/null
+++ b/session.py
@@ -0,0 +1,36 @@
+# -*- coding: utf-8 -*-
+import random
+import os
+import datetime
+from puzzle import *
+
+
+class Session:
+ def __init__(self, topic, difficulty):
+ self.topic = topic
+ self.difficulty = difficulty
+ #obtener puzzles
+ list_files = os.listdir('./puzzles/' + str(self.difficulty) + '/' + self.topic)
+ print list_files
+ self.list_puzzles = []
+ for item in list_files:
+ self.list_puzzles.append(Puzzle('./puzzles/' + str(self.difficulty) + '/' + self.topic + '/' + item))
+ self.time = datetime.datetime.now()
+ self.old_puzzles = []
+ self.nextPuzzle()
+
+ def nextPuzzle(self):
+ l=len(self.list_puzzles)
+ if l>0:
+ i = random.randrange(0, l)
+ self.old_puzzles.append(self.list_puzzles[i])
+ self.current=self.list_puzzles.pop(i)
+ return self.current
+ else:
+ return False
+
+ def currentPuzzle(self):
+ return self.current
+
+ def __str__(self):
+ return 'Sesión de topico = ' + str(self.topic) + ' y dificultad = ' + str(self.difficulty)
diff --git a/toolbar.py b/toolbar.py
new file mode 100644
index 0000000..5d4aab5
--- /dev/null
+++ b/toolbar.py
@@ -0,0 +1,46 @@
+# -*- coding: utf-8 -*-
+import gtk
+from sugar.activity import activity
+class Toolbar():
+ def __init__(self,view):
+ self.toolbox=activity.ActivityToolbox(view.controller.activity)
+ self.toolbox.show()
+ view.controller.activity.set_toolbox(self.toolbox)
+ #El Layout inicial
+
+ #encabezado = gtk.Label(' El encabezado, categoria y dificultad')
+ #encabezado.show()
+
+ #Preparando el menu
+ self.menu = gtk.HBox()
+ self.alineacion = gtk.Alignment(0.5, 1, 0.5, 1)
+ self.categoriaL = gtk.Label("Categoria:")
+ self.categoriaL.show()
+ self.categorias = gtk.combo_box_new_text()
+ self.categorias.insert_text(0,"Todas")
+ self.categorias.insert_text(1,"Matematica")
+ self.categorias.insert_text(2,"Historia")
+ self.categorias.insert_text(3,"Castellano")
+ self.categorias.set_active(0)
+ self.categorias.show()
+ self.dificultadL = gtk.Label("Dificultad:")
+ self.dificultadL.show()
+ self.dificultades = gtk.combo_box_new_text()
+ self.dificultades.insert_text(0,"1")
+ self.dificultades.insert_text(1,"2")
+ self.dificultades.insert_text(2,"3")
+ self.dificultades.set_active(0)
+ self.dificultades.show()
+ self.iniciarB = gtk.Button("Inicio")
+ self.iniciarB.connect("clicked", view.controller.newGame)
+ self.iniciarB.show()
+ self.finalizarB = gtk.Button("Terminar")
+ self.finalizarB.show()
+ self.menu.pack_start(self.alineacion)
+ self.menu.pack_start(self.categoriaL)
+ self.menu.pack_start(self.categorias)
+ self.menu.pack_start(self.dificultadL)
+ self.menu.pack_start(self.dificultades)
+ self.menu.pack_start(self.iniciarB)
+ self.menu.pack_start(self.finalizarB)
+ self.menu.show()
diff --git a/view.py b/view.py
new file mode 100644
index 0000000..c1fa4c8
--- /dev/null
+++ b/view.py
@@ -0,0 +1,53 @@
+# -*- coding: utf-8 -*-
+import gtk
+import toolbar
+import puzzleView
+class View():
+ def __init__(self, controller):
+ self.controller=controller
+ self.toolbar=toolbar.Toolbar(self)
+ self.puzzleView=puzzleView.PuzzleView(self)
+
+ #pregunta
+ self.question=gtk.Label("")
+
+ #respuesta
+ self.answer=gtk.Label("")
+
+ #respuesta
+ self.respuesta = gtk.HBox()
+ self.respL = gtk.Label("Respuesta:")
+ self.respL.show()
+ self.respT = gtk.Entry()
+ self.respT.show()
+ self.respB = gtk.Button("Respuesta")
+ self.respB.connect("clicked", self.controller.evaluateAnswer)
+ self.respB.show()
+ self.sgteB = gtk.Button("Siguiente")
+ self.sgteB.connect("clicked", self.controller.nextPuzzle)
+ self.sgteB.show()
+ self.respuesta.pack_start(self.respL, False, False, 0)
+ self.respuesta.pack_start(self.respT)
+ self.respuesta.pack_start(self.respB)
+ self.respuesta.pack_start(self.sgteB)
+ self.respuesta.show()
+
+ self.l1 = gtk.VBox()
+ #agrupo todo
+ #l1.pack_start(encabezado)
+ self.l1.pack_start(self.toolbar.menu, False, False, 4)
+ self.l1.pack_start(self.question, False, False, 4)
+ self.l1.pack_start(self.puzzleView.imagen, False, False, 4)
+ self.l1.pack_start(self.answer, False, False, 4)
+ self.l1.pack_start(self.respuesta, False, False, 360)
+
+ self.l1.show()
+ self.controller.activity.set_canvas(self.l1)
+
+ def refreshQuestion(self):
+ self.question.set_text(self.controller.session.currentPuzzle().question)
+ self.question.show()
+
+ def showAnswer(self,status):
+ self.answer.set_text(status+' La respuesta correcta es:'+self.controller.session.currentPuzzle().answer)
+ self.answer.show()