/usr/share/gcompris/python/langFindit.py is in gcompris-data 13.11-1.
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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | # gcompris - langFindit.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 exercice.
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, mode):
rootitem = goocanvas.Group( parent = parentitem )
self.width = 380
self.height = 100
# The background
fill_color_off = 0xCCCCCCEEL
fill_color_on = 0xEEEFFEEEL
itembg = \
goocanvas.Rect( parent = rootitem,
x = x,
y = y,
width = self.width,
height = self.height,
radius_x = 5,
radius_y = 5,
stroke_color_rgba = 0x333333FFL,
fill_color_rgba = fill_color_off,
line_width = 2.0 )
itembg.connect("button_press_event", callback, triplet)
itembg.connect("enter_notify_event",
(lambda s,e,t,i: i.set_properties(fill_color_rgba = fill_color_on)),
itembg )
itembg.connect("leave_notify_event",
(lambda s,e,t,i: i.set_properties(fill_color_rgba = fill_color_off)),
itembg )
# The text description
textx = 120
if mode & Findit.WITH_TEXT:
item = goocanvas.Rect(
parent = rootitem,
x = x + textx,
y = y,
width = self.width - textx,
height = self.height,
fill_color_rgba = 0x22115566L,
stroke_color_rgba = 0x11111100L,
line_width = 2.0,
radius_x = 3,
radius_y = 3)
item.connect("button_press_event", callback, triplet)
item.connect("enter_notify_event",
(lambda s,e,t,i: i.set_properties(fill_color_rgba = fill_color_on)),
itembg )
item.connect("leave_notify_event",
(lambda s,e,t,i: i.set_properties(fill_color_rgba = fill_color_off)),
itembg )
item = goocanvas.Text(
parent = rootitem,
x = x + textx + 5,
y = y + 10,
fill_color = "white",
font = gcompris.skin.get_font("gcompris/subtitle"),
text = triplet.descriptionTranslated,
anchor = gtk.ANCHOR_NW,
alignment = pango.ALIGN_LEFT,
width = self.width - textx - 15
)
item.connect("button_press_event", callback, triplet)
item.connect("enter_notify_event",
(lambda s,e,t,i: i.set_properties(fill_color_rgba = fill_color_on)),
itembg )
item.connect("leave_notify_event",
(lambda s,e,t,i: i.set_properties(fill_color_rgba = fill_color_off)),
itembg )
# The image
if triplet.image and (mode & Findit.WITH_IMAGE):
pixbuf = gcompris.utils.load_pixmap(gcompris.DATA_DIR + "/" +
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)
item.connect("enter_notify_event",
(lambda s,e,t,i: i.set_properties(fill_color_rgba = fill_color_on)),
itembg )
item.connect("leave_notify_event",
(lambda s,e,t,i: i.set_properties(fill_color_rgba = fill_color_off)),
itembg )
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"""
WITH_QUESTION = 0x4
WITH_TEXT = 0x2
WITH_IMAGE = 0x1
def __init__(self, lang, parentitem, lesson, mode):
self.lang = lang
self.lesson = lesson
self.mode = mode
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.win()
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
if self.mode & Findit.WITH_QUESTION:
goocanvas.Rect(
parent = self.gameroot,
x = gcompris.BOARD_WIDTH / 4,
y = 75,
width = gcompris.BOARD_WIDTH / 2,
height = 50,
fill_color_rgba = 0x999999BBL,
stroke_color_rgba = 0x111111AAL,
line_width = 2.0,
radius_x = 3,
radius_y = 3)
goocanvas.Text(
parent = self.gameroot,
x = gcompris.BOARD_WIDTH / 2,
y = 100,
fill_color = "white",
font = gcompris.skin.get_font("gcompris/title"),
text = self.tripletToFind.descriptionTranslated,
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,
self.mode)
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)
self.lang.loose()
def repeat(self):
self.lang.playVoice(self.tripletToFind)
def key_press(self, keyval, commit_str, preedit_str):
pass
|