Commit b4ffe3aa authored by Srishti Sethi's avatar Srishti Sethi

Added Repeat Icon|GOAL|braille tutor|integration with BrailleChar module

parent 5c5c4855
# gcompris - BrailleChar.py
#
# Copyright (C) 2011 xxxx
#
# 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/>.
#
# This class display a braille char to a given location
# The char may be static of dynamic. It maintains the value
# of the dots and the char it represents in real time.
#
import gtk
import gtk.gdk
import gcompris
import gcompris.utils
import gcompris.skin
import goocanvas
import pango
import gcompris.sound
import string
from gcompris import gcompris_gettext as _
BRAILLE_LETTERS = {
"A": [1], "B": [1, 2], "C": [1, 4], "D": [1, 4, 5], "E": [1, 5],
"F": [1, 2, 4], "G": [1, 2, 4, 5], "H": [1, 2, 5], "I": [2, 4],
"J": [2, 4, 5], "K": [1, 3], "L": [1, 2, 3], "M": [1, 3, 4],
"N": [1, 3, 4, 5], "O": [1, 3, 5], "P": [1, 2, 3, 4], "Q": [1, 2, 3, 4, 5],
"R": [1, 2, 3, 5], "S": [2, 3, 4], "T": [2, 3, 4, 5], "U": [1, 3, 6],
"V": [1, 2, 3, 6], "W": [2, 4, 5, 6], "X": [1, 3, 4, 6], "Y": [1, 3, 4, 5, 6],
"Z": [1, 3, 5, 6], 1: [2],2 :[2,3], 3 : [2,5], 4: [2,5,6],5 : [2,6],
6 : [2,3,5],7 : [2,3,5,6],8 : [2,3,6], 9 : [3,5],0 :[3,5,6]
}
DOT_ON = 0xFF0000FFL
DOT_OFF = 0x00000000L
class BrailleChar:
"""Braille Char"""
def __init__(self, rootitem,
x, y, width, letter,
display_letter, clickable,
callback):
self.letter = letter
self.callback = callback
self.display_letter = display_letter
self.clickable = clickable
height = width * 1.33
cell_radius = (width / 7.5)
self.rootitem = goocanvas.Group(parent=rootitem)
if(letter == ''):
"""no rect"""
else :
self.item = goocanvas.Rect(parent=self.rootitem,
x=x,
y=y,
width=width,
height=height,
stroke_color="blue",
fill_color="#DfDfDf",
line_width=2.0)
self.text = goocanvas.Text(parent=self.rootitem,
x=x + (width / 2.0),
y=y + height + 15,
text=str(letter),
fill_color="blue",
alignment=pango.ALIGN_CENTER,
anchor = gtk.ANCHOR_CENTER,
font = 'Sans BOLD')
if not display_letter:
self.text.props.visibility = goocanvas.ITEM_INVISIBLE
dot = 1
self.dot_items = []
for u in range(2):
for v in range(3):
cell = goocanvas.Ellipse(parent=self.rootitem,
center_x=x + width / 3.0 * ( u + 1 ),
center_y=y + height / 4.0 * ( v + 1 ),
radius_x=cell_radius,
radius_y=cell_radius,
stroke_color="blue",
fill_color="#DfDfDf",
line_width=width/25)
# To fill the circles in lower board with red color
if (clickable == True):
cell.connect("button_press_event", self.dot_event)
gcompris.utils.item_focus_init(cell, None)
if isinstance(letter,int):
fillings = BRAILLE_LETTERS.get(letter)
else :
fillings = BRAILLE_LETTERS.get(letter.upper())
if fillings == None:
"""only braille cell"""
elif dot in fillings:
cell.set_property("fill_color_rgba", DOT_ON)
else :
cell.set_property("fill_color_rgba", DOT_OFF)
self.dot_items.append(cell)
dot += 1
def get_letter(self):
"""Return the letter represented by this braille item"""
return self.letter
def calculate_char(self):
"""Calculate the represented char"""
cells = []
# Create the dot list
for l in range(6):
if(self.dot_items[l].get_property("fill_color_rgba") == DOT_ON):
cells.append(l+1)
self.letter = ''
for k,v in BRAILLE_LETTERS.items():
if v == cells:
self.letter = k
if isinstance(self.letter,int):
self.text.set_property("text",self.letter)
else :
self.text.set_property("text", str.upper(self.letter))
if self.callback:
self.callback(self.letter)
def dot_event(self, event, target, item):
"""A dot has been clicked, change its state and calculate our new letter value"""
if target.get_property("fill_color_rgba") == DOT_ON:
target.set_property("fill_color_rgba", DOT_OFF)
else:
target.set_property("fill_color_rgba", DOT_ON)
self.calculate_char()
\ 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:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="64px"
height="64px"
id="svg3211"
version="1.1"
inkscape:version="0.48.0 r9654"
sodipodi:docname="target.svg">
<defs
id="defs3213" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="5.5"
inkscape:cx="32"
inkscape:cy="32"
inkscape:current-layer="layer1"
showgrid="true"
inkscape:document-units="px"
inkscape:grid-bbox="true"
inkscape:window-width="1280"
inkscape:window-height="701"
inkscape:window-x="0"
inkscape:window-y="37"
inkscape:window-maximized="1" />
<metadata
id="metadata3216">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
id="layer1"
inkscape:label="Layer 1"
inkscape:groupmode="layer">
<g
id="g34218"
transform="matrix(0.74091789,-0.00895527,0.00790171,0.72102019,-4.4493366,-4.3813411)">
<path
id="path2941"
d="m 41.876434,78.550846 -1.099019,2.060663 -0.274755,4.415703 1.373774,2.649422 1.64853,2.649422 5.495097,0.29438 3.846569,-3.238183 -0.274755,-2.943802 -0.54951,-2.649422 -1.373774,-3.238183 -7.418382,-0.29438 -1.373775,0.29438 z"
style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:none"
inkscape:connector-curvature="0" />
<g
transform="translate(-0.639516,-2.131719)"
id="g34199">
<path
style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:none"
d="m 41.142176,9.6151159 c 0,0 15.987893,1.2790311 17.266924,1.2790311 1.279031,0 14.282517,5.116126 14.282517,5.116126 l 11.724454,12.790314 c 0,0 2.558063,10.019079 2.771235,11.084938 0.213172,1.06586 -1.918547,15.348377 -1.918547,16.84058 0,1.492203 -5.755642,13.42983 -5.755642,13.42983 l -9.166391,10.23225 c 0,0 -10.658595,2.558064 -14.282517,2.558064 -3.623922,0 -13.003486,0.639515 -15.774721,0.639515 -2.771234,0 -15.348376,-3.837094 -16.627408,-4.902954 C 22.383049,77.616951 10.445423,69.090075 10.658595,67.811044 10.871767,66.532012 5.7556412,56.512934 6.6083288,54.381215 7.4610164,52.249496 7.4610163,38.819666 7.4610163,38.819666 c 0,0 4.2634377,-9.805908 5.7556417,-12.363971 1.492203,-2.558062 4.902953,-6.181984 6.395156,-7.887359 1.492204,-1.705376 9.805908,-5.54247 9.805908,-5.54247 L 41.142176,9.6151159 z"
id="path2935"
sodipodi:nodetypes="csccssccssssscsscc"
inkscape:connector-curvature="0" />
<path
style="fill:#2165cd;fill-opacity:1;fill-rule:evenodd;stroke:none"
d="m 42.273349,15.051 c 0,0 14.129427,1.091047 15.259781,1.091047 1.130353,0 12.622287,4.364188 12.622287,4.364188 l 10.36158,10.910469 c 0,0 2.260708,8.546535 2.4491,9.45574 0.188393,0.909206 -1.695531,13.092564 -1.695531,14.365452 0,1.272887 -5.086594,11.455993 -5.086594,11.455993 l -8.100871,8.728374 c 0,0 -9.419618,2.182095 -12.622287,2.182095 -3.20267,0 -11.491934,0.545523 -13.941035,0.545523 -2.4491,0 -13.564249,-3.27314 -14.694604,-4.182347 -1.130354,-0.909205 -11.680325,-8.182851 -11.491933,-9.273898 0.188392,-1.091047 -4.333024,-9.637581 -3.579455,-11.455992 0.75357,-1.818412 0.75357,-13.274405 0.75357,-13.274405 0,0 3.767846,-8.364694 5.086593,-10.546788 1.318747,-2.182094 4.333024,-5.273393 5.65177,-6.728122 1.318747,-1.45473 8.666049,-4.727871 8.666049,-4.727871 L 42.273349,15.051 z"
id="path34196"
sodipodi:nodetypes="csccssccssssscsscc"
inkscape:connector-curvature="0" />
</g>
<g
transform="translate(-87.61365,-33.04165)"
id="g34189">
<path
style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:none"
d="m 111.27573,66.958356 11.51128,-10.871767 c 0,0 10.44542,-0.426344 13.643,-0.639516 3.19758,-0.213172 11.29811,2.558063 11.29811,2.558063 0,0 6.8215,5.329297 7.03468,6.821501 0.21317,1.492203 3.83709,10.871766 3.41075,13.429829 -0.42635,2.558063 -1.49221,9.166392 -1.91855,10.445423 -0.42634,1.279031 -9.37956,9.592736 -10.87177,10.445423 C 143.89103,100 131.52706,101.06586 127.26362,100 c -4.26344,-1.06586 -13.643,-5.116126 -13.643,-6.395157 0,-1.279032 -3.19758,-11.298111 -3.83709,-14.495689 -0.63952,-3.197579 1.27903,-12.150798 1.4922,-12.150798 z"
id="path2933"
sodipodi:nodetypes="ccscsssssssc"
inkscape:connector-curvature="0" />
<path
style="fill:#ffcc00;fill-opacity:1;fill-rule:evenodd;stroke:none"
d="m 114.80451,87.049609 9.74244,8.915227 c 0,0 8.84036,0.349616 11.54659,0.524425 2.70624,0.174809 9.56202,-2.097701 9.56202,-2.097701 0,0 5.7733,-4.370209 5.95372,-5.593867 0.18041,-1.223659 3.24747,-8.915227 2.88664,-11.012927 -0.36083,-2.0977 -1.2629,-7.51676 -1.62373,-8.56561 -0.36084,-1.04885 -7.93829,-7.866377 -9.2012,-8.56561 -1.2629,-0.699234 -11.727,-1.573276 -15.33531,-0.699234 -3.60831,0.874043 -11.54659,4.195401 -11.54659,5.244251 0,1.048851 -2.70624,9.264844 -3.24748,11.886969 -0.54125,2.622126 1.08249,9.964077 1.2629,9.964077 z"
id="path34187"
sodipodi:nodetypes="ccscsssssssc"
inkscape:connector-curvature="0" />
<g
id="g34181"
transform="translate(86.72317,32.58648)">
<path
sodipodi:nodetypes="cscscscssc"
id="path34183"
d="m 35.546664,49.58198 c 0,0 -0.415835,-6.958638 -0.151997,-8.0605 0.263839,-1.101861 4.901081,-7.365561 4.901081,-7.365561 0,0 5.10562,-1.865964 9.854703,-1.039569 4.749084,0.826397 6.992246,2.104826 8.086283,4.345154 0.690182,1.413329 2.63838,6.335704 1.846867,9.365822 -0.791514,3.03012 -2.902218,6.61117 -2.902218,6.61117 0,0 -5.27676,4.682911 -6.595951,4.958376 -1.31919,0.275466 -7.459145,-1.003565 -9.306012,-2.105427 -1.846865,-1.101861 -5.996594,-6.433999 -5.732756,-6.709465 z"
style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:none"
inkscape:connector-curvature="0" />
<path
sodipodi:nodetypes="cscscscssc"
id="path34185"
d="m 48.337813,54.969999 c 0,0 -4.852783,-0.938451 -5.556353,-1.313515 -0.703569,-0.375065 -4.086051,-4.662326 -4.086051,-4.662326 0,0 -0.275176,-3.835394 1.225465,-6.952261 1.500643,-3.116867 2.818346,-4.432852 4.569539,-4.79027 1.104754,-0.225481 4.862815,-0.69784 6.784657,0.378894 1.921843,1.076735 3.961959,3.156563 3.961959,3.156563 0,0 2.172878,4.448483 2.102286,5.403119 -0.07059,0.954635 -2.155127,4.947296 -3.273829,6.022116 -1.1187,1.07482 -5.590699,2.987372 -5.727673,2.75768 z"
style="fill:#ff140e;fill-opacity:1;fill-rule:evenodd;stroke:none"
inkscape:connector-curvature="0" />
</g>
</g>
<g
transform="translate(-0.639516,-2.131719)"
id="g34206">
<path
style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:none"
d="m 21.337915,74.632545 -5.344101,5.651787 -4.500296,5.394889 -1.6876106,5.908688 0.2812686,2.312095 8.156786,0.770699 5.344101,-4.110392 -1.125075,-4.62419 1.968879,-4.110391 5.62537,-3.596593 -8.719322,-3.596592 z"
id="path2937"
inkscape:connector-curvature="0" />
<path
style="fill:#85c751;fill-opacity:1;fill-rule:evenodd;stroke:none"
d="m 22.369847,76.385351 -3.743079,5.020853 -3.748481,3.828822 -1.405762,2.350884 -0.133982,2.903916 3.316201,0.692412 3.734239,-1.680492 -0.769628,-2.447263 0.493096,-4.326456 5.77782,-4.87644 -3.520424,-1.466236 z"
id="path34204"
sodipodi:nodetypes="ccccccccccc"
inkscape:connector-curvature="0" />
</g>
<g
transform="matrix(-1,0,0,1,92.62318,-1.279032)"
id="g34210">
<path
style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:none"
d="m 21.337915,74.632545 -5.344101,5.651787 -4.500296,5.394889 -1.6876106,5.908688 0.2812686,2.312095 8.156786,0.770699 5.344101,-4.110392 -1.125075,-4.62419 1.968879,-4.110391 5.62537,-3.596593 -8.719322,-3.596592 z"
id="path34212"
inkscape:connector-curvature="0" />
<path
style="fill:#85c751;fill-opacity:1;fill-rule:evenodd;stroke:none"
d="m 22.583019,75.959008 -3.956251,5.447196 -3.748481,3.828822 -1.405762,2.350884 -0.133982,2.903916 3.316201,0.692412 3.734239,-1.680492 -0.769628,-2.447263 0.493096,-4.326456 5.351476,-4.87644 -2.880908,-1.892579 z"
id="path34214"
sodipodi:nodetypes="ccccccccccc"
inkscape:connector-curvature="0" />
</g>
<path
id="path34216"
d="m 49.337452,81.606312 0.606355,1.06586 0.151589,2.283984 -0.757944,1.370391 -0.909534,1.37039 -3.031778,0.152266 -2.122245,-1.674922 0.151589,-1.522657 0.303178,-1.37039 0.757944,-1.674922 4.092901,-0.152266 0.757945,0.152266 z"
style="fill:#85c751;fill-opacity:1;fill-rule:evenodd;stroke:none"
inkscape:connector-curvature="0" />
</g>
</g>
</svg>
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