/usr/share/gcompris/python/lang.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 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 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | # gcompris - lang.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
from gcompris import gcompris_gettext as _
from langLib import *
from langFindit import *
class MissingImage:
"""This is used to display a missing image"""
def __init__(self, rootitem, langActivity):
self.missingroot = goocanvas.Group( parent = rootitem )
width = 280
height = 240
item = goocanvas.Rect( parent = self.missingroot,
x = gcompris.BOARD_WIDTH / 2 - width / 2,
y = gcompris.BOARD_HEIGHT / 2 - height / 2,
width = width,
height = height,
radius_x = 5,
radius_y = 5,
stroke_color_rgba = 0x666666FFL,
fill_color_rgba = 0x33333366L,
line_width = 2.0 )
item.connect("button_press_event", langActivity.next_event, None)
self.missingtext = goocanvas.Text(
parent = self.missingroot,
x = gcompris.BOARD_WIDTH / 2,
y = gcompris.BOARD_HEIGHT / 2,
fill_color = "black",
font = gcompris.skin.get_font("gcompris/subtitle"),
text = _("Missing Image"),
anchor = gtk.ANCHOR_CENTER,
alignment = pango.ALIGN_CENTER
)
def hide(self):
self.missingroot.props.visibility = goocanvas.ITEM_INVISIBLE
def show(self, triplet):
self.missingroot.props.visibility = goocanvas.ITEM_VISIBLE
class Gcompris_lang:
"""Empty gcompris python class"""
def __init__(self, gcomprisBoard):
print "lang init"
# Save the gcomprisBoard, it defines everything we need
# to know from the core
self.gcomprisBoard = gcomprisBoard
# Needed to get key_press
gcomprisBoard.disable_im_context = True
def start(self):
print "lang start"
# init config to default values
self.config_dict = self.init_config()
print "init self.config_dict :", self.config_dict
# change configured values
print "gcompris.get_board_conf() : ", gcompris.get_board_conf()
self.config_dict.update(gcompris.get_board_conf())
print "self.config_dict final :", self.config_dict
if self.config_dict.has_key('locale_sound'):
gcompris.set_locale(self.config_dict['locale_sound'])
# Set the buttons we want in the bar
gcompris.bar_set(gcompris.BAR_LEVEL|gcompris.BAR_REPEAT|gcompris.BAR_CONFIG)
gcompris.bar_location(gcompris.BOARD_WIDTH / 2 - 100, -1, 0.6)
# Set a background image
gcompris.set_default_background(self.gcomprisBoard.canvas.get_root_item())
# Create our rootitem. We put each canvas item in it so at the end we
# only have to kill it. The canvas deletes all the items it contains
# automaticaly.
self.rootitem = goocanvas.Group(parent =
self.gcomprisBoard.canvas.get_root_item())
self.langLib = LangLib(gcompris.DATA_DIR + "/lang/lang.xml")
self.chapters = self.langLib.getChapters()
# FIXME Do not manage Chapter yet
self.currentChapterId = 0
# Manage levels (a level is a lesson in the lang model)
self.gcomprisBoard.level = 1
self.gcomprisBoard.maxlevel = \
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()
def ok(self):
print("lang ok.")
def repeat(self):
self.playVoice( self.currentLesson.getTriplets()[self.currentTripletId] )
def init_config(self):
default_config = { 'locale_sound' : 'NULL' }
return default_config
#mandatory but unused yet
def config_stop(self):
pass
# Configuration function.
def config_start(self, profile):
# keep profile in mind
# profile can be Py_None
self.configuring_profile = profile
# init with default values
self.config_dict = self.init_config()
# get the configured values for that profile
self.config_dict.update(gcompris.get_conf(profile, self.gcomprisBoard))
bconf = gcompris.configuration_window ( \
_('Configuration\n for profile <b>%s</b>')
% ( (profile.name if profile else _("Default") ) ),
self.ok_callback
)
gcompris.combo_locales_asset(bconf, _("Select locale"),
self.config_dict['locale_sound'],
"voices/$LOCALE/colors/red.ogg")
# Callback when the "OK" button is clicked in configuration window
# this get all the _changed_ values
def ok_callback(self, table):
if (table == None):
return True
for key,value in table.iteritems():
gcompris.set_board_conf(self.configuring_profile,
self.gcomprisBoard, key, value)
return True;
def key_press(self, keyval, commit_str, preedit_str):
utf8char = gtk.gdk.keyval_to_unicode(keyval)
strn = u'%c' % utf8char
print("Gcompris_lang key press keyval=%i %s" % (keyval, strn))
def pause(self, pause):
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 )
# -------
def clearLesson(self):
self.lessonroot.remove()
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:
pass
self.currentTripletId = 0
self.lessonroot = goocanvas.Group( parent = self.rootitem )
goocanvas.Rect(
parent = self.lessonroot,
x = 20,
y = 10,
width = gcompris.BOARD_WIDTH - 40,
height = 65,
fill_color_rgba = 0x6666FF33L,
stroke_color_rgba = 0x1111FFAAL,
line_width = 2.0,
radius_x = 0.9,
radius_y = 0.9)
goocanvas.Text(
parent = self.lessonroot,
x = gcompris.BOARD_WIDTH / 2,
y = 25.0,
text = lesson.name,
fill_color = "black",
font = gcompris.skin.get_font("gcompris/title"),
anchor = gtk.ANCHOR_CENTER,
alignment = pango.ALIGN_CENTER,
width = 300
)
goocanvas.Text(
parent = self.lessonroot,
x = gcompris.BOARD_WIDTH / 2,
y = 55.0,
text = lesson.description,
fill_color = "black",
font = gcompris.skin.get_font("gcompris/subtitle"),
anchor = gtk.ANCHOR_CENTER,
alignment = pango.ALIGN_CENTER,
width = 600
)
# Previous Button
item = goocanvas.Svg( parent = self.lessonroot,
svg_handle = gcompris.skin.svg_get(),
svg_id = "#PREVIOUS",
)
gcompris.utils.item_absolute_move(item,
100,
gcompris.BOARD_HEIGHT / 2)
item.connect("button_press_event", self.previous_event, None)
gcompris.utils.item_focus_init(item, None)
# Next Button
item = goocanvas.Svg(parent = self.lessonroot,
svg_handle = gcompris.skin.svg_get(),
svg_id = "#NEXT",
)
gcompris.utils.item_absolute_move(item,
gcompris.BOARD_WIDTH - 130,
gcompris.BOARD_HEIGHT / 2)
item.connect("button_press_event", self.next_event, None)
gcompris.utils.item_focus_init(item, None)
self.counteritem = goocanvas.Text(
parent = self.lessonroot,
x = gcompris.BOARD_WIDTH - 40,
y = gcompris.BOARD_HEIGHT - 40,
fill_color = "black",
font = gcompris.skin.get_font("gcompris/board/tiny"),
anchor = gtk.ANCHOR_CENTER,
alignment = pango.ALIGN_CENTER
)
# The triplet area
self.missingImage = MissingImage(self.lessonroot, self)
self.imageitem = goocanvas.Image( parent = self.lessonroot )
self.imageitem.connect("button_press_event", self.next_event, None)
self.descriptionitem = goocanvas.Text(
parent = self.lessonroot,
x = gcompris.BOARD_WIDTH / 2,
y = gcompris.BOARD_HEIGHT - 100,
fill_color = "black",
font = gcompris.skin.get_font("gcompris/subtitle"),
anchor = gtk.ANCHOR_CENTER,
alignment = pango.ALIGN_CENTER,
width = 300
)
self.displayImage( lesson.getTriplets()[self.currentTripletId] )
def playVoice(self, triplet):
if triplet.voice:
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,
)
self.counteritem.set_properties (
text = str(self.currentTripletId + 1) + "/" \
+ str( len( self.currentLesson.getTriplets() ) ),
)
if triplet.image:
self.missingImage.hide()
self.imageitem.props.visibility = goocanvas.ITEM_VISIBLE
pixbuf = gcompris.utils.load_pixmap(gcompris.DATA_DIR + "/lang/" +
triplet.image)
center_x = pixbuf.get_width()/2
center_y = pixbuf.get_height()/2
self.imageitem.set_properties(pixbuf = pixbuf,
x = gcompris.BOARD_WIDTH / 2 - center_x,
y = gcompris.BOARD_HEIGHT / 2 - center_y )
else:
self.imageitem.props.visibility = goocanvas.ITEM_INVISIBLE
self.missingImage.show(triplet)
def previous_event(self, event, target,item, dummy):
self.currentTripletId -= 1
if self.currentTripletId < 0:
self.currentTripletId = len( self.currentLesson.getTriplets() ) - 1
self.displayImage( self.currentLesson.getTriplets()[self.currentTripletId] )
def next_event(self, event, target, item, dummy):
self.currentTripletId += 1
if self.currentTripletId >= len( self.currentLesson.getTriplets() ):
self.currentTripletId = 0
self.displayImage( self.currentLesson.getTriplets()[self.currentTripletId] )
|