/usr/share/gcompris/python/langFindit.py is in gcompris-data 12.01-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | # 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 SpotTarget:
"""Display a triplet"""
def __init__(self, parentitem, x, y, triplet, callback):
rootitem = goocanvas.Group( parent = parentitem )
self.width = 380
self.height = 100
# The background
item = goocanvas.Rect( parent = rootitem,
x = x,
y = y,
width = self.width,
height = self.height,
radius_x = 5,
radius_y = 5,
stroke_color_rgba = 0x666666FFL,
fill_color_rgba = 0x33333366L,
line_width = 2.0 )
item.connect("button_press_event", callback, triplet)
# The text description
textx = 100
item = goocanvas.Text(
parent = rootitem,
x = x + textx,
y = y + 10,
fill_color = "black",
font = gcompris.skin.get_font("gcompris/subtitle"),
text = triplet.description,
anchor = gtk.ANCHOR_NW,
alignment = pango.ALIGN_LEFT,
width = self.width - textx - 10
)
item.connect("button_press_event", callback, triplet)
# The image
if triplet.image:
pixbuf = gcompris.utils.load_pixmap(gcompris.DATA_DIR + "/lang/" +
triplet.image)
item = goocanvas.Image( parent = rootitem,
pixbuf = pixbuf,
x = x + 5,
y = y + 5,
width = 110,
height = 90
)
item.connect("button_press_event", callback, triplet)
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 = 100,
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 = 4
y_start = 200
y = y_start
x = 10
triplets2 = triplets2[:numberOfItem-1]
triplets2.insert(random.randint(0, numberOfItem-1),
self.tripletToFind)
for i in range(0, numberOfItem):
spot = SpotTarget(self.gameroot, x, y, triplets2[i], self.ok)
y += spot.height + 20
if (i+1) % 2 == 0:
y = y_start
x = gcompris.BOARD_WIDTH / 2 + 10
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)
|