Commit 571e01e0 authored by Bruno Coudoin's avatar Bruno Coudoin

braille char: changed the layout a little bit to make more room for the dots.

parent 9ce8cbab
# gcompris - BrailleChar.py # gcompris - BrailleChar.py
# #
# Copyright (C) 2011 xxxx # Copyright (C) 2011 Bruno Coudoin | Srishti Sethi
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
...@@ -26,10 +26,9 @@ import gcompris.utils ...@@ -26,10 +26,9 @@ import gcompris.utils
import gcompris.skin import gcompris.skin
import goocanvas import goocanvas
import pango import pango
import gcompris.sound
import string import string
from gcompris import gcompris_gettext as _
# For ASCII each letter, this represent the active dots in Braille.
BRAILLE_LETTERS = { BRAILLE_LETTERS = {
"A": [1], "B": [1, 2], "C": [1, 4], "D": [1, 4, 5], "E": [1, 5], "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], "F": [1, 2, 4], "G": [1, 2, 4, 5], "H": [1, 2, 5], "I": [2, 4],
...@@ -37,51 +36,52 @@ BRAILLE_LETTERS = { ...@@ -37,51 +36,52 @@ BRAILLE_LETTERS = {
"N": [1, 3, 4, 5], "O": [1, 3, 5], "P": [1, 2, 3, 4], "Q": [1, 2, 3, 4, 5], "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], "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], "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], "+" : [3,4,6], "_": [3,6], "*" : [1,6],"/" : [3,4], "Z": [1, 3, 5, 6], "+" : [3,4,6], "_": [3,6], "*" : [1,6], "/" : [3,4],
"#" : [3,4,5,6],1: [1],2 :[1, 2], 3 : [1, 4], 4: [1, 4, 5],5 : [1, 5], "#" : [3,4,5,6],1: [1],2 :[1, 2], 3 : [1, 4], 4: [1, 4, 5], 5 : [1, 5],
6 : [1,2,4],7 : [1,2,4,5],8 : [1,2,5], 9 : [2,4],0 :[3,5,6] 6 : [1, 2, 4], 7 : [1, 2, 4, 5], 8 : [1, 2, 5], 9 : [2, 4], 0 :[3, 5, 6]
} }
class BrailleChar: class BrailleChar:
"""Braille Char""" """Braille Char"""
def __init__(self, rootitem, def __init__(self, rootitem,
x, y, width, letter,DOT_ON, x, y, width, letter,
DOT_OFF,fill,stroke,display_letter, clickable, dot_on, dot_off,
rectangle,callback, braille_letter = "alphabet"): fill_color, stroke_color,
display_letter, clickable,
rectangle, callback, braille_letter = "alphabet"):
self.letter = letter self.letter = letter
self.callback = callback self.callback = callback
self.display_letter = display_letter self.display_letter = display_letter
self.clickable = clickable self.clickable = clickable
self.DOT_ON = DOT_ON self.dot_on = dot_on
self.DOT_OFF = DOT_OFF self.dot_off = dot_off
self.fill = fill self.fill_color = fill_color
self.stroke = stroke self.stroke_color = stroke_color
self.rectangle = rectangle self.rectangle = rectangle
self.braille_letter = braille_letter self.braille_letter = braille_letter
height = width * 1.33 height = width * 1.33
cell_radius = (width / 7.5) self.rootitem = goocanvas.Group(parent = rootitem)
self.rootitem = goocanvas.Group(parent=rootitem)
if(letter == '' or rectangle == False): if(letter == '' or rectangle == False):
"""no rect""" """no rect"""
else : else :
self.item = goocanvas.Rect(parent=self.rootitem, self.item = goocanvas.Rect(parent = self.rootitem,
x=x, x = x,
y=y, y = y,
width=width, width = width,
height=height, height = height,
stroke_color = self.stroke, stroke_color = self.stroke_color,
fill_color = self.fill, fill_color = self.fill_color,
line_width=2.0) line_width=2.0)
self.text = goocanvas.Text(parent=self.rootitem, self.text = goocanvas.Text(parent = self.rootitem,
x=x + (width / 2.0), x = x + (width / 2.0),
y=y + height + 15, y = y + height + 15,
text=str(letter), text = str(letter),
fill_color=self.stroke, fill_color = self.stroke_color,
alignment=pango.ALIGN_CENTER, alignment = pango.ALIGN_CENTER,
anchor = gtk.ANCHOR_CENTER, anchor = gtk.ANCHOR_CENTER,
font = 'Sans BOLD') font = 'Sans BOLD')
if not display_letter: if not display_letter:
...@@ -90,16 +90,28 @@ class BrailleChar: ...@@ -90,16 +90,28 @@ class BrailleChar:
dot = 1 dot = 1
self.dot_items = [] self.dot_items = []
self.cell_array = [] self.cell_array = []
cell_radius = (width / 6.3)
for u in range(2): for u in range(2):
for v in range(3): for v in range(3):
self.cell = goocanvas.Ellipse(parent=self.rootitem, xx = x + width / 3.0 * ( u + 1 ) - width / 20
center_x=x + width / 3.0 * ( u + 1 ), yy = y + height / 4.0 * ( v + 1 ) - height / 20
center_y=y + height / 4.0 * ( v + 1 ), if u:
radius_x=cell_radius, xx = x + width / 3.0 * ( u + 1 ) + width / 20
radius_y=cell_radius, if v == 1:
stroke_color=self.stroke, yy = y + height / 4.0 * ( v + 1 )
fill_color=self.fill, if v == 2:
line_width=width/25) yy = y + height / 4.0 * ( v + 1 ) + height / 20
self.cell = \
goocanvas.Ellipse(parent = self.rootitem,
center_x = xx,
center_y = yy,
radius_x = cell_radius,
radius_y = cell_radius,
stroke_color = self.stroke_color,
fill_color = self.fill_color,
line_width = width/25)
self.cell_array.append(self.cell) self.cell_array.append(self.cell)
# To fill the circles in lower board with red color # To fill the circles in lower board with red color
...@@ -115,9 +127,9 @@ class BrailleChar: ...@@ -115,9 +127,9 @@ class BrailleChar:
if fillings == None: if fillings == None:
"""only braille self.cell""" """only braille self.cell"""
elif dot in fillings: elif dot in fillings:
self.cell.set_property("fill_color_rgba", self.DOT_ON) self.cell.set_property("fill_color_rgba", self.dot_on)
else : else :
self.cell.set_property("fill_color_rgba", self.DOT_OFF) self.cell.set_property("fill_color_rgba", self.dot_off)
self.dot_items.append(self.cell) self.dot_items.append(self.cell)
dot += 1 dot += 1
...@@ -132,7 +144,7 @@ class BrailleChar: ...@@ -132,7 +144,7 @@ class BrailleChar:
# Create the dot list # Create the dot list
for l in range(6): for l in range(6):
if(self.dot_items[l].get_property("fill_color_rgba") == self.DOT_ON): if(self.dot_items[l].get_property("fill_color_rgba") == self.dot_on):
cells.append(l+1) cells.append(l+1)
self.letter = '' self.letter = ''
...@@ -152,10 +164,10 @@ class BrailleChar: ...@@ -152,10 +164,10 @@ class BrailleChar:
def dot_event(self, event, target, item): def dot_event(self, event, target, item):
"""A dot has been clicked, change its state and calculate our new letter value""" """A dot has been clicked, change its state and calculate our new letter value"""
if target.get_property("fill_color_rgba") == self.DOT_ON: if target.get_property("fill_color_rgba") == self.dot_on:
target.set_property("fill_color_rgba", self.DOT_OFF) target.set_property("fill_color_rgba", self.dot_off)
else: else:
target.set_property("fill_color_rgba", self.DOT_ON) target.set_property("fill_color_rgba", self.dot_on)
self.calculate_char() self.calculate_char()
#### This function has been added specially for BrailleLotto Activity #### This function has been added specially for BrailleLotto Activity
......
# gcompris - BrailleMap.py # gcompris - BrailleMap.py
# #
# Copyright (C) 2011 xxxx # Copyright (C) 2011 Bruno Coudoin | Srishti Sethi
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
...@@ -29,14 +29,14 @@ import pango ...@@ -29,14 +29,14 @@ import pango
from BrailleChar import * from BrailleChar import *
from gcompris import gcompris_gettext as _ from gcompris import gcompris_gettext as _
SYMBOL = ['+','_','*','/'] SYMBOL = ['+', '_', '*', '/', '#']
CELL_WIDTH = 30 CELL_WIDTH = 30
class BrailleMap: class BrailleMap:
"""Braille Map""" """Braille Map"""
def __init__(self, rootitem, color_on, color_off, circle_fill, circle_stroke): def __init__(self, rootitem, color_on, color_off, circle_fill, circle_stroke):
#Place alphabets & numbers in array format # Place alphabets & numbers in array format
for index, letter in enumerate(string.ascii_uppercase[:10]): for index, letter in enumerate(string.ascii_uppercase[:10]):
BrailleChar(rootitem, index*(CELL_WIDTH+40)+60, BrailleChar(rootitem, index*(CELL_WIDTH+40)+60,
40, 38, letter ,color_on, color_off, circle_fill, 40, 38, letter ,color_on, color_off, circle_fill,
...@@ -60,11 +60,8 @@ class BrailleMap: ...@@ -60,11 +60,8 @@ class BrailleMap:
circle_stroke, True ,False ,True , None) circle_stroke, True ,False ,True , None)
# The math operators +-*/ # The math operators +-*/
for index in range(4): for index, value in enumerate( SYMBOL ):
BrailleChar(rootitem,index * (CELL_WIDTH + 40) + 60, BrailleChar(rootitem,index * (CELL_WIDTH + 40) + 60,
400 , 38,SYMBOL[index], color_on, color_off, circle_fill, 400 , 38,SYMBOL[index], color_on, color_off, circle_fill,
circle_stroke,True ,False ,True , None) circle_stroke,True ,False ,True , None)
BrailleChar(rootitem, 5 *(CELL_WIDTH + 40) + 60, 400, 38,
"#", color_on, color_off, circle_fill,
circle_stroke, True ,False ,True , None)
...@@ -127,12 +127,10 @@ class Gcompris_braille_alphabets: ...@@ -127,12 +127,10 @@ class Gcompris_braille_alphabets:
self.start() self.start()
def config(self): def config(self):
print("learnbraille config.") pass
def key_press(self, keyval, commit_str, preedit_str): def key_press(self, keyval, commit_str, preedit_str):
utf8char = gtk.gdk.keyval_to_unicode(keyval) pass
strn = u'%c' % utf8char
print("Gcompris_learnbraille key press keyval=%i %s" % (keyval, strn))
def pause(self,pause): def pause(self,pause):
if(pause == 0): if(pause == 0):
...@@ -294,7 +292,7 @@ class Gcompris_braille_alphabets: ...@@ -294,7 +292,7 @@ class Gcompris_braille_alphabets:
gcompris.set_background(self.gcomprisBoard.canvas.get_root_item(), gcompris.set_background(self.gcomprisBoard.canvas.get_root_item(),
"braille_alphabets/mosaic.svgz") "braille_alphabets/mosaic.svgz")
#Translators : Do not translate the token {letter} # Translators : Do not translate the token {letter}
goocanvas.Text(parent = self.rootitem, goocanvas.Text(parent = self.rootitem,
x = 100, x = 100,
y = 200, y = 200,
...@@ -307,8 +305,10 @@ class Gcompris_braille_alphabets: ...@@ -307,8 +305,10 @@ class Gcompris_braille_alphabets:
text=_("Braille Cell"), text=_("Braille Cell"),
fill_color="black", fill_color="black",
font='Sans BOLD') font='Sans BOLD')
BrailleChar(self.rootitem, 150, 270, 120, '',COLOR_ON ,COLOR_OFF,CIRCLE_FILL,CIRCLE_STROKE, BrailleChar(self.rootitem, 150, 270, 120, '',
False,True,False,callback = self.letter_change , braille_letter = self.letter) COLOR_ON ,COLOR_OFF, CIRCLE_FILL, CIRCLE_STROKE,
False, True, False, callback = self.letter_change,
braille_letter = self.letter)
for i in range(2): for i in range(2):
for j in range(3): for j in range(3):
goocanvas.Text(parent=self.rootitem, goocanvas.Text(parent=self.rootitem,
......
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