Commit e50b131e authored by SrishAkaTux's avatar SrishAkaTux

Braille Fun New Activity

parent e55b210e
SUBDIRS =
pythondir = $(PYTHON_PLUGIN_DIR)
dist_python_DATA= braille_fun.py
xmldir = $(pkgdatadir)/@PACKAGE_DATA_DIR@
xml_in_files = \
braille_fun.xml.in
xml_DATA = $(xml_in_files:.xml.in=.xml)
# Do not use the INTLTOOL_XML_RULE, we don't need to embed the translations
# in the file themselves. GCompris pick the translations from the po file at
# runtime.
#
$(xml_DATA): %.xml: %.xml.in
sed -e "s/\(<\{1\}\/*\)_/\1/g" $< > $@
# Use this directive and instead of the one above to embed the translations
# in the xml files directly, this is needed for the tool gcompris2spip
#@INTLTOOL_XML_RULE@
icondir = $(pkgdatadir)/@PACKAGE_DATA_DIR@
icon_DATA = braille_fun.svg
EXTRA_DIST = $(icon_DATA) ${xml_in_files} init_path.sh
CLEANFILES = $(xml_DATA)
# gcompris - braille_fun.py
#
# Copyright (C) 2003, 2008 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/>.
#
# braille_fun activity.
import gtk
import gtk.gdk
import gcompris
import gobject
import gcompris.utils
import gcompris.skin
import gcompris.sound
import gcompris.bonus
import gcompris.score
import goocanvas
import pango
import random
import string
from BrailleChar import *
from BrailleMap import *
from gcompris import gcompris_gettext as _
COLOR_ON = 0X00FFFF
COLOR_OFF = 0X000000
CIRCLE_FILL = "light green"
CIRCLE_STROKE = "black"
CELL_WIDTH = 30
class Gcompris_braille_fun:
"""Empty gcompris python class"""
def __init__(self, gcomprisBoard):
# Save the gcomprisBoard, it defines everything we need
# to know from the core
self.gcomprisBoard = gcomprisBoard
self.gcomprisBoard.level=1
self.gcomprisBoard.sublevel=1
self.gcomprisBoard.number_of_sublevel = 3
self.gcomprisBoard.maxlevel = 5
self.text_color = 0X0000FFFFL
self.counter = 0
self.timerAnim = 0
self.delay = 40
#Boolean variable declaration
self.mapActive = False
# These are used to let us restart only after the bonus is displayed.
# When the bonus is displayed, it call us first with pause(1) and then with pause(0)
self.board_paused = 0
self.gamewon = 0
#Array declaration
self.letter_array = []
self.alphabet_array = []
self.tile_array = []
# Needed to get key_press
gcomprisBoard.disable_im_context = True
def start(self):
# Set the buttons we want in the bar
gcompris.bar_set(gcompris.BAR_LEVEL)
gcompris.bar_location(300,-1,0.6)
gcompris.bar_set_level(self.gcomprisBoard)
#REPEAT ICON
gcompris.bar_set(gcompris.BAR_LEVEL|gcompris.BAR_REPEAT_ICON)
gcompris.bar_location(300,-1,0.7)
# 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.root = goocanvas.Group(parent =
self.gcomprisBoard.canvas.get_root_item())
#Display the sublevel
gcompris.score.start(gcompris.score.STYLE_NOTE, 530, 460,
self.gcomprisBoard.number_of_sublevel)
gcompris.score.set(self.gcomprisBoard.sublevel)
# Set a background image
gcompris.set_background(self.gcomprisBoard.canvas.get_root_item(),
"braille_fun/hillside.svg")
self.display_game(self.gcomprisBoard.level)
def display_game(self, level):
for index in range (level) :
#Select a random letter and append it to self.letter_array
letter = random.choice(string.letters)
self.letter_array.append(letter.upper())
self.alphabet = goocanvas.Text(
parent = self.root,
x=50.0 + 50 * index ,
y=130.0 ,
text=self.letter_array[index],
fill_color="black",
anchor = gtk.ANCHOR_CENTER,
alignment = pango.ALIGN_CENTER,
font = 'SANS 50'
)
self.alphabet_array.append(self.alphabet)
#Display animated or falling letters
self.alphabet.animate(-20 + 30 * index,
410,
1,
1,
True,
30000 + level * 5000,
250,
goocanvas.ANIMATE_FREEZE)
#To call a function when animation finishes
self.alphabet.connect("animation-finished", self.animationFinished)
#Display rectangle for braille tile
goocanvas.Rect(parent=self.root,
x = 300 + 90 * index,
y = 155,
width = 80 ,
height = 100,
stroke_color = "black",
fill_color = "#DfDfDf",
line_width=2.0)
#Naming Objects from Variable Class Names and appending
#to array self.tile_array
self.obj = "self.obj" + str(index)
self.tile_array.append(self.obj)
#Defining Object to BrailleChar Instance to produce braille_tile
self.tile_array[index] = BrailleChar(self.root, 300 + 90 * index , 150, 80,
'',COLOR_ON ,COLOR_OFF, "#DfDfDf","black",
True, True ,True, callback = self.letter_change)
def letter_change(self, letter):
self.letter = letter
for index in range(self.gcomprisBoard.level):
if (self.tile_array[index].get_letter() == self.letter_array[index]):
#print str(index) + ' ' + "letter is created"
#Change the text color of alphabet correctly identified in the braille tile
self.alphabet_array[index].set_property("fill_color_rgba",self.text_color)
if self.alphabet_array[self.counter].get_property("fill_color_rgba") == self.text_color :
self.counter += 1
if (self.counter == self.gcomprisBoard.level) :
self.timerAnim = gobject.timeout_add(40, self.timer_loop)
def timer_loop(self):
self.delay -= 1
if(self.delay == 0):
self.gamewon = 1
gcompris.bonus.display(gcompris.bonus.WIN,gcompris.bonus.SMILEY)
self.delay = 40
if self.delay < 40 :
gobject.timeout_add(self.delay,self.timer_loop)
def animationFinished(self, item, status):
if (self.counter != self.gcomprisBoard.level) :
gcompris.bonus.display(gcompris.bonus.LOOSE,gcompris.bonus.SMILEY)
def end(self):
# Remove the root item removes all the others inside it
self.root.remove()
def ok(self):
print("braille_fun ok.")
def repeat(self):
if(self.mapActive):
self.rootitem.props.visibility = goocanvas.ITEM_INVISIBLE
gcompris.set_background(self.gcomprisBoard.canvas.get_root_item(),
"braille_fun/hillside.svg")
self.root.props.visibility = goocanvas.ITEM_VISIBLE
self.mapActive = False
else :
self.root.props.visibility = goocanvas.ITEM_INVISIBLE
self.rootitem = goocanvas.Group(parent=
self.gcomprisBoard.canvas.get_root_item())
gcompris.set_default_background(self.gcomprisBoard.canvas.get_root_item())
map_obj = BrailleMap(self.rootitem, COLOR_ON, COLOR_OFF, CIRCLE_FILL, CIRCLE_STROKE)
self.mapActive = True
def config(self):
print("braille_fun config.")
def key_press(self, keyval, commit_str, preedit_str):
utf8char = gtk.gdk.keyval_to_unicode(keyval)
strn = u'%c' % utf8char
print("Gcompris_braille_fun key press keyval=%i %s" % (keyval, strn))
def pause(self, pause):
self.board_paused = pause
#This is to hide the Repeat board
if self.mapActive == True:
self.rootitem.props.visibility = goocanvas.ITEM_INVISIBLE
if(self.board_paused) and (self.gamewon == 1):
self.gamewon = 0
self.declare()
self.increment_level()
self.end()
self.start()
if(self.board_paused) and (self.gamewon == 0):
self.declare()
self.end()
self.start()
def declare(self):
self.letter_array = []
self.tile_array = []
self.alphabet_array = []
self.counter = 0
def increment_level(self):
self.declare()
gcompris.sound.play_ogg("sounds/bleep.wav")
self.gcomprisBoard.sublevel += 1
if(self.gcomprisBoard.sublevel>self.gcomprisBoard.number_of_sublevel):
self.gcomprisBoard.sublevel=1
self.gcomprisBoard.level += 1
if(self.gcomprisBoard.level > self.gcomprisBoard.maxlevel):
self.gcomprisBoard.level = 1
def set_level(self, level):
#This is to hide the Repeat board in case set_level button gets pressed
if self.mapActive == True:
self.rootitem.props.visibility = goocanvas.ITEM_INVISIBLE
self.declare()
gcompris.sound.play_ogg("sounds/receive.wav")
self.gcomprisBoard.level = level
self.gcomprisBoard.sublevel = 1
gcompris.bar_set_level(self.gcomprisBoard)
self.end()
self.start()
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="100"
height="100"
id="svg40739"
sodipodi:version="0.32"
inkscape:version="0.47 r22583"
version="1.0"
sodipodi:docname="python.svg">
<defs
id="defs40741">
<inkscape:perspective
sodipodi:type="inkscape:persp3d"
inkscape:vp_x="0 : 50 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_z="100 : 50 : 1"
inkscape:persp3d-origin="50 : 33.333333 : 1"
id="perspective22" />
<linearGradient
y2="593.93323"
x2="324.75836"
y1="230.74762"
x1="355.05255"
gradientTransform="matrix(0.275436,0,0,0.275436,-9.036391,-24.94534)"
gradientUnits="userSpaceOnUse"
id="linearGradient2149"
xlink:href="#linearGradient3195"
inkscape:collect="always" />
<radialGradient
r="109.16138"
fy="191.79465"
fx="191.85158"
cy="191.79465"
cx="191.85158"
gradientTransform="matrix(-0.05310125,0.872689,-0.600768,-0.03655593,224.2399,-59.43464)"
gradientUnits="userSpaceOnUse"
id="radialGradient2142"
xlink:href="#linearGradient2209"
inkscape:collect="always" />
<radialGradient
gradientTransform="matrix(-5.310125e-2,0.872689,-0.600768,-3.655593e-2,224.2399,-59.43464)"
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient2209"
id="radialGradient2502"
fy="191.79465"
fx="191.85158"
r="109.16138"
cy="191.79465"
cx="191.85158" />
<linearGradient
gradientTransform="matrix(0.275436,0,0,0.275436,-9.036391,-24.94534)"
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient3195"
id="linearGradient2499"
y2="593.93323"
x2="324.75836"
y1="230.74762"
x1="355.05255" />
<linearGradient
gradientTransform="matrix(0.275436,0,0,0.275436,-9.036391,-24.94534)"
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient3195"
id="linearGradient2492"
y2="593.93323"
x2="324.75836"
y1="230.74762"
x1="355.05255" />
<radialGradient
gradientTransform="matrix(-5.310125e-2,0.872689,-0.600768,-3.655593e-2,224.2399,-59.43464)"
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient2209"
id="radialGradient2490"
fy="191.79465"
fx="191.85158"
r="109.16138"
cy="191.79465"
cx="191.85158" />
<radialGradient
gradientTransform="matrix(-5.310125e-2,0.872689,-0.600768,-3.655593e-2,411.631,-21.7361)"
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient2028"
id="radialGradient2460"
fy="191.79465"
fx="191.85158"
r="109.16138"
cy="191.79465"
cx="191.85158" />
<linearGradient
gradientTransform="matrix(0.275436,0,0,0.275436,178.3546,12.7532)"
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient3195"
id="linearGradient2457"
y2="593.93323"
x2="324.75836"
y1="230.74762"
x1="355.05255" />
<linearGradient
gradientTransform="matrix(0.275436,0,0,0.275436,364.8811,-32.15133)"
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient3195"
id="linearGradient2454"
y2="593.93323"
x2="324.75836"
y1="230.74762"
x1="355.05255" />
<linearGradient
id="linearGradient2164">
<stop
id="stop2166"
offset="0"
style="stop-color:#05fa4a;stop-opacity:1" />
<stop
id="stop2168"
offset="1"
style="stop-color:#21fa4a;stop-opacity:0" />
</linearGradient>
<linearGradient
id="linearGradient2170">
<stop
id="stop2172"
offset="0"
style="stop-color:white;stop-opacity:0.37440759" />
<stop
id="stop2174"
offset="1"
style="stop-color:white;stop-opacity:0" />
</linearGradient>
<linearGradient
id="linearGradient2182">
<stop
id="stop2184"
offset="0"
style="stop-color:#89b0f1;stop-opacity:1" />
<stop
id="stop2186"
offset="1"
style="stop-color:#89b0f1;stop-opacity:0" />
</linearGradient>
<linearGradient
id="linearGradient2188">
<stop
id="stop2190"
offset="0"
style="stop-color:white;stop-opacity:1" />
<stop
id="stop2192"
offset="1"
style="stop-color:white;stop-opacity:0" />
</linearGradient>
<linearGradient
id="linearGradient2194">
<stop
id="stop2196"
offset="0"
style="stop-color:#faed21;stop-opacity:1" />
<stop
id="stop2198"
offset="1"
style="stop-color:#faed21;stop-opacity:0" />
</linearGradient>
<radialGradient
gradientTransform="matrix(0.650783,-3.06516e-2,2.791861e-2,0.592758,124.1873,214.4504)"
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient8440"
id="radialGradient2200"
fy="551.19287"
fx="410.15085"
r="197.44826"
cy="551.19287"
cx="410.15085" />
<linearGradient
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient10241"
id="linearGradient2202"
y2="300.84381"
x2="871.53973"
y1="566.73724"
x1="56.840466" />
<linearGradient
gradientTransform="translate(-723.2674,480.0855)"
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient10241"
id="linearGradient2204"
y2="300.84381"
x2="871.53973"
y1="566.73724"
x1="56.840466" />
<radialGradient
gradientTransform="matrix(0.650783,-3.06516e-2,2.791861e-2,0.592758,338.933,901.3419)"
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient8440"
id="radialGradient2206"
fy="551.19287"
fx="410.15085"
r="197.44826"
cy="551.19287"
cx="410.15085" />
<radialGradient
gradientTransform="matrix(0.628232,8.120038e-4,-8.375586e-4,0.64804,-113.341,354.6752)"
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient15608"
id="radialGradient2208"
fy="1036.5964"
fx="-330.87396"
r="197.44826"
cy="1036.5964"
cx="-330.87396" />
<radialGradient
gradientTransform="matrix(0.628232,8.120038e-4,-8.375586e-4,0.64804,-113.341,354.6752)"
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient15608"
id="radialGradient2210"
fy="1036.5964"
fx="-330.87396"
r="197.44826"
cy="1036.5964"
cx="-330.87396" />
<linearGradient
gradientTransform="translate(-723.2674,480.0855)"
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient10241"
id="linearGradient2212"
y2="300.84381"
x2="871.53973"
y1="566.73724"
x1="56.840466" />
<radialGradient
gradientTransform="matrix(0.628232,8.120038e-4,-8.375586e-4,0.64804,-113.341,354.6752)"
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient15608"
id="radialGradient2214"
fy="1036.5964"
fx="-330.87396"
r="197.44826"
cy="1036.5964"
cx="-330.87396" />
<linearGradient
gradientTransform="translate(-723.2674,480.0855)"
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient10241"
id="linearGradient2216"
y2="300.84381"
x2="871.53973"
y1="566.73724"
x1="56.840466" />
<linearGradient
gradientTransform="matrix(0.550543,0,0,0.550543,-18.1832,263.505)"
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient10241"
id="linearGradient2218"
y2="300.84381"
x2="871.53973"
y1="566.73724"
x1="56.840466" />
<radialGradient
gradientTransform="matrix(0.345869,4.47043e-4,-4.61112e-4,0.356774,594.4075,251.9103)"
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient15608"
id="radialGradient2220"
fy="1036.5964"
fx="-330.87396"
r="197.44826"
cy="1036.5964"
cx="-330.87396" />
<radialGradient
gradientTransform="matrix(0.628232,8.120038e-4,-8.375586e-4,0.64804,-113.341,354.6752)"
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient15608"
id="radialGradient2223"
fy="1036.5964"
fx="-330.87396"
r="197.44826"
cy="1036.5964"
cx="-330.87396" />
<linearGradient
gradientTransform="translate(-723.2674,480.0855)"
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient10241"
id="linearGradient2225"
y2="300.84381"
x2="871.53973"
y1="566.73724"
x1="56.840466" />
<linearGradient
gradientTransform="matrix(0.552861,0,0,0.552861,-8.679351,-52.47802)"
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient3195"
id="linearGradient2227"
y2="593.93323"
x2="324.75836"
y1="230.74762"
x1="355.05255" />
<radialGradient
gradientTransform="matrix(-0.106586,1.75168,-1.205874,-7.337587e-2,459.558,-121.7057)"
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient2209"
id="radialGradient2229"
fy="191.79465"
fx="191.85158"
r="109.16138"
cy="191.79465"
cx="191.85158" />
<radialGradient
gradientTransform="matrix(-0.106586,1.75168,-1.205874,-7.337587e-2,459.558,-121.7057)"
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient2209"
id="radialGradient2231"
fy="191.79465"
fx="191.85158"
r="109.16138"
cy="191.79465"
cx="191.85158" />
<linearGradient
gradientTransform="matrix(0.552861,0,0,0.552861,-8.679351,-52.47802)"
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient3195"
id="linearGradient2233"
y2="593.93323"
x2="324.75836"
y1="230.74762"
x1="355.05255" />
<linearGradient
gradientTransform="matrix(0.137222,0,0,0.137222,241.0501,5.28093)"
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient3195"
id="linearGradient2235"
y2="669.45007"
x2="306.77817"
y1="97.694176"
x1="369.43671" />
<linearGradient
gradientTransform="matrix(0.275436,0,0,0.275436,196.1709,-0.751182)"
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient3195"
id="linearGradient2237"
y2="593.93323"
x2="324.75836"
y1="230.74762"
x1="355.05255" />
<radialGradient
gradientTransform="matrix(-5.310125e-2,0.872689,-0.600768,-3.655593e-2,429.4473,-35.24048)"
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient15608"
id="radialGradient2239"
fy="191.79465"
fx="191.85158"
r="109.16138"
cy="191.79465"
cx="191.85158" />
<linearGradient
gradientTransform="matrix(0.275436,0,0,0.275436,366.1663,-0.751182)"
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient3195"
id="linearGradient2241"
y2="593.93323"
x2="324.75836"
y1="230.74762"
x1="355.05255" />
<radialGradient
gradientTransform="matrix(-5.310125e-2,0.872689,-0.600768,-3.655593e-2,599.4427,-35.24048)"
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient8440"
id="radialGradient2243"
fy="191.79465"
fx="191.85158"
r="109.16138"
cy="191.79465"
cx="191.85158" />
<linearGradient
gradientTransform="matrix(0.275436,0,0,0.275436,534.9284,-0.751182)"
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient3195"
id="linearGradient2245"
y2="593.93323"
x2="324.75836"
y1="230.74762"
x1="355.05255" />
<radialGradient
gradientTransform="matrix(-5.310125e-2,0.872689,-0.600768,-3.655593e-2,768.2048,-35.24048)"
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient2028"
id="radialGradient2247"
fy="191.79465"
fx="191.85158"
r="109.16138"
cy="191.79465"
cx="191.85158" />
<radialGradient
gradientTransform="matrix(-5.310125e-2,0.872689,-0.600768,-3.655593e-2,768.2048,-35.24048)"
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient2028"
id="radialGradient2249"
fy="191.79465"
fx="191.85158"
r="109.16138"
cy="191.79465"
cx="191.85158" />
<linearGradient
gradientTransform="matrix(0.275436,0,0,0.275436,534.9284,-0.751182)"
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient3195"
id="linearGradient2251"
y2="593.93323"
x2="324.75836"
y1="230.74762"
x1="355.05255" />
<radialGradient
gradientTransform="matrix(-5.310125e-2,0.872689,-0.600768,-3.655593e-2,768.2048,-35.24048)"
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient2028"
id="radialGradient2274"
fy="191.79465"
fx="191.85158"
r="109.16138"
cy="191.79465"
cx="191.85158" />
<linearGradient
gradientTransform="matrix(0.275436,0,0,0.275436,534.9284,-0.751182)"
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient3195"
id="linearGradient2276"
y2="593.93323"
x2="324.75836"
y1="230.74762"
x1="355.05255" />
<linearGradient
gradientTransform="matrix(0.275436,0,0,0.275436,534.9284,-0.751182)"
gradientUnits="userSpaceOnUse"
xlink:href="#linearGradient3195"
id="linearGradient2263"