[gcompris] lang activity: added a finded activity which is played when all the triplets have been seen.



commit df4e48da30897a51fd639ab1e6b1df02548a7576
Author: Bruno Coudoin <bruno coudoin free fr>
Date:   Tue Nov 22 01:13:22 2011 +0100

    lang activity: added a finded activity which is played when all the triplets have been seen.

 src/lang-activity/findit.py |  105 +++++++++++++++++++++++++++++++++++++++++++
 src/lang-activity/lang.py   |   35 +++++++++++++-
 2 files changed, 137 insertions(+), 3 deletions(-)
---
diff --git a/src/lang-activity/findit.py b/src/lang-activity/findit.py
new file mode 100644
index 0000000..61c8581
--- /dev/null
+++ b/src/lang-activity/findit.py
@@ -0,0 +1,105 @@
+#  gcompris - findit.py
+#
+# Copyright (C) 2010 Bruno Coudoin
+#
+#   This program is free software; you can redistribute it and/or modify
+#   it under the terms of the GNU General Public License as published by
+#   the Free Software Foundation; either version 3 of the License, or
+#   (at your option) any later version.
+#
+#   This program is distributed in the hope that it will be useful,
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#   GNU General Public License for more details.
+#
+#   You should have received a copy of the GNU General Public License
+#   along with this program; if not, see <http://www.gnu.org/licenses/>.
+#
+# lang activity.
+import gtk
+import gtk.gdk
+import gcompris
+import gcompris.utils
+import gcompris.skin
+import gcompris.sound
+import goocanvas
+import pango
+import random
+
+from gcompris import gcompris_gettext as _
+from langLib import *
+
+class Findit:
+    """An exercice that given a lesson asks the children to find"""
+    """the good anwer from a source text, a target text or a voice"""
+
+    def __init__(self, lang, parentitem, lesson):
+        self.lang = lang
+        self.lesson = lesson
+        self.triplets = list(lesson.getTriplets())
+        random.shuffle(self.triplets)
+        self.rootitem = goocanvas.Group( parent = parentitem )
+        self.gameroot = None
+        self.currentIndex = 0
+        self.tripletToFind = None
+
+    def start(self):
+
+        if self.currentIndex >= len(self.triplets):
+            self.stop()
+            self.lang.next_level()
+            return
+
+        self.gameroot = goocanvas.Group( parent = self.rootitem )
+
+        self.tripletToFind = self.triplets[self.currentIndex]
+        self.lang.playVoice(self.tripletToFind)
+        self.currentIndex += 1
+        # Display the triplet to find
+        goocanvas.Text(
+            parent = self.gameroot,
+            x = gcompris.BOARD_WIDTH / 2,
+            y = gcompris.BOARD_HEIGHT / 4,
+            fill_color = "black",
+            font = gcompris.skin.get_font("gcompris/subtitle"),
+            text = self.tripletToFind.description,
+            anchor = gtk.ANCHOR_CENTER,
+            alignment = pango.ALIGN_CENTER,
+            width = 300
+            )
+
+        # Propose some triplet including the good one
+        triplets2 = list(self.lesson.getTriplets())
+        triplets2.remove(self.tripletToFind)
+        random.shuffle(triplets2)
+        numberOfItem = 3
+        y = gcompris.BOARD_HEIGHT / 2
+        triplets2 = triplets2[:numberOfItem-1]
+        triplets2.insert(random.randint(0, numberOfItem-1),
+                         self.tripletToFind)
+        for i in range(0, numberOfItem):
+            item = goocanvas.Text(
+                parent = self.gameroot,
+                x = gcompris.BOARD_WIDTH / 2,
+                y = y,
+                fill_color = "black",
+                font = gcompris.skin.get_font("gcompris/subtitle"),
+                text = triplets2[i].description,
+                anchor = gtk.ANCHOR_CENTER,
+                alignment = pango.ALIGN_CENTER,
+                width = 300
+                )
+            item.connect("button_press_event", self.ok, triplets2[i])
+            y += 30
+
+
+    def stop(self):
+        self.rootitem.remove()
+
+    def ok(self, event, target, item, triplet):
+        if self.tripletToFind == triplet:
+            self.gameroot.remove()
+            self.start()
+        else:
+            self.triplets.append(self.tripletToFind)
+
diff --git a/src/lang-activity/lang.py b/src/lang-activity/lang.py
index 8e722e2..ff89356 100644
--- a/src/lang-activity/lang.py
+++ b/src/lang-activity/lang.py
@@ -27,6 +27,7 @@ import pango
 
 from gcompris import gcompris_gettext as _
 from langLib import *
+from findit import *
 
 class MissingImage:
   """This is used to display a missing image"""
@@ -118,11 +119,14 @@ class Gcompris_lang:
         len ( self.chapters.getChapters()[self.currentChapterId].getLessons() )
     gcompris.bar_set_level(self.gcomprisBoard)
 
+    self.currentExercise = None
     self.currentLesson = self.langLib.getLesson(self.currentChapterId,
                                                 self.gcomprisBoard.level - 1)
     self.displayLesson( self.currentLesson )
 
   def end(self):
+    if self.currentExercise:
+      self.currentExercise.stop()
     # Remove the root item removes all the others inside it
     self.rootitem.remove()
 
@@ -188,10 +192,20 @@ class Gcompris_lang:
     print("lang pause. %i" % pause)
 
 
+  def next_level(self):
+    if self.gcomprisBoard.level < self.gcomprisBoard.maxlevel:
+      self.set_level(self.gcomprisBoard.level + 1)
+    else:
+      self.set_level(self.gcomprisBoard.level)
+
   def set_level(self, level):
     self.gcomprisBoard.level = level;
     self.gcomprisBoard.sublevel = 1;
     gcompris.bar_set_level(self.gcomprisBoard)
+
+    if self.currentExercise:
+      self.currentExercise.stop()
+
     self.currentLesson = self.langLib.getLesson(self.currentChapterId,
                                                 self.gcomprisBoard.level - 1)
     self.displayLesson( self.currentLesson )
@@ -204,6 +218,10 @@ class Gcompris_lang:
 
   def displayLesson(self, lesson):
 
+    # Keep the triplet shown to the user to know when
+    # we can move to the exercices
+    self.tripletSeen = set()
+
     try:
       self.lessonroot.remove()
     except:
@@ -232,7 +250,8 @@ class Gcompris_lang:
       fill_color = "black",
       font = gcompris.skin.get_font("gcompris/title"),
       anchor = gtk.ANCHOR_CENTER,
-      alignment = pango.ALIGN_CENTER
+      alignment = pango.ALIGN_CENTER,
+      width = 300
       )
 
     goocanvas.Text(
@@ -243,7 +262,8 @@ class Gcompris_lang:
       fill_color = "black",
       font = gcompris.skin.get_font("gcompris/subtitle"),
       anchor = gtk.ANCHOR_CENTER,
-      alignment = pango.ALIGN_CENTER
+      alignment = pango.ALIGN_CENTER,
+      width = 600
       )
 
     # Previous Button
@@ -289,7 +309,8 @@ class Gcompris_lang:
       fill_color = "black",
       font = gcompris.skin.get_font("gcompris/subtitle"),
       anchor = gtk.ANCHOR_CENTER,
-      alignment = pango.ALIGN_CENTER
+      alignment = pango.ALIGN_CENTER,
+      width = 300
       )
     self.displayImage( lesson.getTriplets()[self.currentTripletId] )
 
@@ -298,6 +319,14 @@ class Gcompris_lang:
       gcompris.sound.play_ogg("voices/$LOCALE/" + triplet.voice)
 
   def displayImage(self, triplet):
+
+    if len(self.tripletSeen) == len(self.currentLesson.getTriplets()):
+      self.clearLesson()
+      self.currentExercise = Findit(self, self.rootitem, self.currentLesson)
+      self.currentExercise.start()
+      return
+
+    self.tripletSeen.add(triplet)
     self.playVoice( triplet )
     self.descriptionitem.set_properties (
       text = triplet.description,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]