Commit 331e4d67 authored by Srishti Sethi's avatar Srishti Sethi

Fourth Activity:Story of Louis Braille

parent 3d03663e
SUBDIRS =
pythondir = $(PYTHON_PLUGIN_DIR)
dist_python_DATA= louis_braille.py
xmldir = $(pkgdatadir)/@PACKAGE_DATA_DIR@
xml_in_files = \
louis_braille.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 = louis_braille.svg
EXTRA_DIST = $(icon_DATA) ${xml_in_files} init_path.sh
CLEANFILES = $(xml_DATA)
../boards/python/gcompris
\ No newline at end of file
# Set the different path for this activity
# This is sourced by runit.sh
path=$1
activity=louis_braille
plugindir=$path/../boards/.libs
pythonplugindir=$path/../braille_alphabets-activity:$path/../louis_braille-activity
resourcedir=$path/resources
section="/experimental"
# gcompris - louis_braille.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/>.
#
# louis_braille activity.
import gtk
import gtk.gdk
import gcompris
import gcompris.utils
import gcompris.skin
import goocanvas
import pango
import ConfigParser
from BrailleChar import *
from gcompris import gcompris_gettext as _
COLOR_ON = 0X00FFFFL
COLOR_OFF= 0X00000000L
CIRCLE_FILL = "red"
CELL_WIDTH = 30
LOUIS_BRAILLE_NAME = ['L','O','U','I','S','B','R','A','I','L','L','E']
class Gcompris_louis_braille:
"""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=1
self.gcomprisBoard.maxlevel = 11
# Needed to get key_press
gcomprisBoard.disable_im_context = True
def start(self):
# Set the buttons we want in the bar
gcompris.bar_set (0)
gcompris.bar_location(gcompris.BOARD_WIDTH - 160, -1, 0.6)
# Set a background image
gcompris.set_default_background(self.gcomprisBoard.canvas.get_root_item())
gcompris.set_background(self.gcomprisBoard.canvas.get_root_item(),
"louis_braille/back.png")
# 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())
#Previous Button
ok = goocanvas.Svg(parent = self.rootitem,
svg_handle = gcompris.skin.svg_get(),
svg_id = "#PREVIOUS",
tooltip = "Click to move to previous story page"
)
ok.translate(-300,50)
ok.connect("button_press_event", self.previous_event, self.gcomprisBoard.level)
gcompris.utils.item_focus_init(ok, None)
#Next Button
ok = goocanvas.Svg(parent = self.rootitem,
svg_handle = gcompris.skin.svg_get(),
svg_id = "#NEXT",
tooltip = "Click to move to next story page"
)
ok.translate(75,-58)
ok.connect("button_press_event", self.next_event, self.gcomprisBoard.level)
gcompris.utils.item_focus_init(ok, None)
#Display name of louis braille
for index in range(5):
BrailleChar(self.rootitem,(index+1) *(CELL_WIDTH + 20)+30,
20, 50, LOUIS_BRAILLE_NAME[index] ,COLOR_ON, COLOR_OFF,
CIRCLE_FILL, CIRCLE_FILL, True,False ,False, None)
for index in range(5,12):
BrailleChar(self.rootitem,(index+1) *(CELL_WIDTH + 20)+65,
20, 50, LOUIS_BRAILLE_NAME[index] ,COLOR_ON, COLOR_OFF,
CIRCLE_FILL, CIRCLE_FILL,True,False ,False, None)
self.read_data()
self.display_game(self.gcomprisBoard.level)
def read_data(self):
'''Load the activity data'''
config = ConfigParser.RawConfigParser()
p = gcompris.get_properties()
filename = gcompris.DATA_DIR + '/' + self.gcomprisBoard.name + '/activity.desktop'
try:
gotit = config.read(filename)
if not gotit:
gcompris.utils.dialog(_("Cannot find the file '{filename}'").format(filename=filename),None)
return False
except ConfigParser.Error as error:
gcompris.utils.dialog(_("Failed to parse data set '{filename}' with error:\n{error}").
format(filename=filename, error=error), None)
return False
self.dataset = config
return True
def display_game(self, level):
#Checking for newline in activity.desktop
story = self.dataset.get(str(level),"story")
story = story.replace("\\n", "\n")
#Displaying the YEAR
goocanvas.Text(parent = self.rootitem,
x=420.0,
y=410.0,
text=str(self.dataset.get(str(level),"year")),
fill_color="black",
anchor = gtk.ANCHOR_CENTER,
alignment = pango.ALIGN_CENTER,
font = 'SANS 17'
)
#Displaying the STORY
goocanvas.Text(parent = self.rootitem,
x=440.0,
y=450.0,
text=str(story),
fill_color="black",
anchor = gtk.ANCHOR_CENTER,
alignment = pango.ALIGN_CENTER,
font = 'SANS 17'
)
#Displaying the IMAGE
goocanvas.Image(parent = self.rootitem,
pixbuf = gcompris.utils.load_pixmap
(str(self.dataset.get(str(level),"image"))),
x = 300,
y = 120,
)
def previous_event(self, event, target,item, level):
if (self.gcomprisBoard.level == 1):
self.gcomprisBoard.level = self.gcomprisBoard.maxlevel
else :
self.gcomprisBoard.level = level - 1
self.end()
self.start()
def next_event(self, event, target, item, level):
if (self.gcomprisBoard.level == self.gcomprisBoard.maxlevel):
self.gcomprisBoard.level = 1
else :
self.gcomprisBoard.level = level + 1
self.end()
self.start()
def end(self):
# Remove the root item removes all the others inside it
self.rootitem.remove()
def ok(self):
print("louis_braille ok.")
def repeat(self):
print("louis_braille repeat.")
def config(self):
print("louis_braille config.")
def key_press(self, keyval, commit_str, preedit_str):
utf8char = gtk.gdk.keyval_to_unicode(keyval)
strn = u'%c' % utf8char
print("Gcompris_louis_braille key press keyval=%i %s" % (keyval, strn))
def pause(self, pause):
print("louis_braille pause. %i" % pause)
def set_level(self, level):
print("louis_braille set level. %i" % level)
\ No newline at end of file
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<GCompris>
<Board
name="louis_braille"
type="python:louis_braille"
section="/experimental"
icon="louis_braille.svg"
difficulty="1"
author="your name here"
boarddir=""
demo="1">
<_title>set a title for louis_braille</_title>
<_description>set a description for louis_braille</_description>
<_prerequisite>set a prerequisite for louis_braille</_prerequisite>
<_goal>set a goal for louis_braille</_goal>
<_manual>set a manual for louis_braille</_manual>
<_credit>set a credit for louis_braille</_credit>
</Board>
<Data directory=""/>
</GCompris>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment