[gcompris/braille] braille: reformatted the code in unix encoding.
- From: Bruno Coudoin <bcoudoin src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcompris/braille] braille: reformatted the code in unix encoding.
- Date: Fri, 3 Jun 2011 07:43:43 +0000 (UTC)
commit 1807df0d9dd32aa8bd66d8dd64c2ad0c29d4117f
Author: Bruno Coudoin <bruno coudoin free fr>
Date: Fri Jun 3 09:43:03 2011 +0200
braille: reformatted the code in unix encoding.
.../braille_alphabets.py | 286 +++++++++++++++++++-
1 files changed, 285 insertions(+), 1 deletions(-)
---
diff --git a/src/braille_alphabets-activity/braille_alphabets.py b/src/braille_alphabets-activity/braille_alphabets.py
index a93c333..60bffc4 100644
--- a/src/braille_alphabets-activity/braille_alphabets.py
+++ b/src/braille_alphabets-activity/braille_alphabets.py
@@ -1 +1,285 @@
-# gcompris - braille_alphabets.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_alphabets activity.import gtkimport gtk.gdkimport gcomprisimport gcompris.utilsimport gcompris.skinimport goocanvasimport pangoimport gcompris.soundimport stringfrom 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],}cell_width = 40x1 = 190y1 = 150red_fill = 4278190335class Gcompris_braille_alphabets: """Empty gcompris python class""" def __init__(self, gcomprisBoard): # Save the gcomprisBoard, it defines everything we need # to know from the core #defining the number of levels in activity self.gcomprisBoard = gcomprisBoard self.gcomprisBoard.level = 1 self.gcomprisBoard.maxlevel=2 self.gcomprisBoard.sublevel=1 self.gcomprisBoard.number_of_sublevel=1 # Needed to get key_press gcomprisBoard
.disable_im_context = True def start(self): # Set the buttons we want in the bar gcompris.bar_set_level(self.gcomprisBoard) gcompris.bar_set(gcompris.BAR_LEVEL) # Set a background image gcompris.set_background(self.gcomprisBoard.canvas.get_root_item(), "mosaic_bg.svgz") # 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.display_game() def end(self): # Remove the root item removes all the others inside it self.rootitem.remove() def ok(self): print("learnbraille ok.") def repeat(self): print("learnbraille repeat.") def config(self): print("learnbraille config.") def key_press(self, keyval, commit_str, preedit_str): utf8char = gtk.gdk.keyva
l_to_unicode(keyval) strn = u'%c' % utf8char print("Gcompris_learnbraille key press keyval=%i %s" % (keyval, strn)) def pause(self, pause): print("learnbraille pause. %i" % pause) def set_level(self, level): gcompris.sound.play_ogg("sounds/receive.wav") self.gcomprisBoard.level = level self.gcomprisBoard.sublevel = 1 gcompris.bar_set_level(self.gcomprisBoard) print("braille_alphabets set level. %i" % self.gcomprisBoard.level) self.increment_level() def increment_level(self): gcompris.sound.play_ogg("sounds/bleep.wav") self.end() self.start() def display_game(self): goocanvas.Text(parent=self.rootitem, x=390.0, y=70.0, text=_("Alphabet"), width=500, height=500, fill_color="blue", anchor=gtk.ANCHOR_CENTER, font='BOLD') """call braille cell""" self.braille_cell() self.board_lower(self.gcomprisBoard.level) """Call lower board 1 or 2""" def board_lower(sel
f,level): if(level ==1): self.board_lower1() elif(level == 2) : self.board_lower2() def board_lower1(self): for i, letter in enumerate(string.ascii_uppercase[:13]): tile = self.braille_tile(letter, cell_width, i) def braille_tile(self, letter, cell_width, index_x): padding = cell_width * 0.21 cell_size = cell_width / 2 - padding inner_padding = cell_width * 0.08 cell_radius = cell_size - inner_padding * 2 item = goocanvas.Rect(parent=self.rootitem, x=index_x * (cell_width + 10) + 60, y=350, width=40, height=60, stroke_color="blue", fill_color="#DfDfDf", line_width=2.0) item.connect("button_press_event", self.braille_char, x1, y1, letter, True, True) gcompri
s.utils.item_focus_init(item, None) goocanvas.Text(parent=self.rootitem, x=(index_x * (cell_width + 10) + 60) + 10, y=425, text=str(letter), fill_color="blue", font='BOLD') cells = [] for u in range(2): for v in range(3): cell = goocanvas.Ellipse(parent=self.rootitem, center_x=index_x * 50 + u * 20 + 70, center_y=v * 15 + 365, radius_x=cell_radius, radius_y=cell_radius, stroke_color="blue", line_width=2.0) #keep a separate track so we don't mix up with other cells cells.append(cell) #To fill the circles in lower board with red color fillings = braille_le
tters.get(letter.lower()) for index_x in range(6): cells[index_x].connect("button_press_event", self.braille_char, x1, y1, letter, True, True) gcompris.utils.item_focus_init(cells[index_x], item) if(index_x + 1) in fillings: cells[index_x].set_property("fill_color", "red") else : cells[index_x].set_property("fill_color", "#DfDfDf") def braille_char(self, event, target, item, a, b, letter, clickable, displayable): """Checking the booleans to evaluate if text is to displayed & if its clickable""" if(displayable == True): #load an image in alphabet area before displaying text goocanvas.Image(parent=self.rootitem, pixbuf=gcompris.utils.load_pixmap("drawing.svg"), x=100, y=80, width=200, height=200) text1 = goocanvas.Tex
t(parent=self.rootitem, x=a, y=b, fill_color="blue", font="Sans 78", anchor=gtk.ANCHOR_CENTER, text=str(letter)) if(clickable == True): text1.connect("button_press_event", self.display_letter, letter) gcompris.utils.item_focus_init(text1, None) def display_letter(self, item, event, target, letter): #To fill the points in braille cell area self.fillings = braille_letters.get(letter.lower()) for i in range(6): if(i + 1) in self.fillings: self.c[i].set_property("fill_color", "red") else : self.c[i].set_property("fill_color", "#DfDfDf") def board_lower2(self): for i, letter in enumerate(string.ascii_uppercase[13:]): tile = self.braille_tile(letter, cell_width, i) """Braille Cell function to represent the dots & braille code""" def braille_cell(self): #Braille Cell Array self.c = []
goocanvas.Text(parent=self.rootitem, x=540.0, y=70.0, text=_("Braille Cell"), fill_color="blue", font='BOLD') for i in range(2): for j in range(3): goocanvas.Text(parent=self.rootitem, text=(str(j + 1 + i * 3)), font='Sans 30', fill_color="blue", x=i * 140 + 510, y=j * 50 + 100) cell1 = goocanvas.Ellipse(parent=self.rootitem, center_x=i * 50 + 570, center_y=j * 50 + 120, radius_x=20, radius_y=20, stroke_color="blue", fill_color="#DfDfDf",
line_width=5.0) #to ensure that cells do not mess up & append #them to array self.c.append(cell1) #To make the points clickable in braille cell area for index in range(6): self.c[index].connect("button_press_event",self.change_color,index) gcompris.utils.item_focus_init(self.c[index],None) """function being called on click of a point""" def change_color(self,item,event,target,incr): self.cell = [] #set the property of point to transparent if it is red if(self.c[incr].get_property("fill_color_rgba") == red_fill): self.c[incr].set_property("fill_color","#DfDfDf") self.click_display(item,target,event) else : #set the property of point to red if it is transparent self.c[incr].set_property("fill_color","red") self.click_display(item,target,event) """Appends the point clicked in an array
""" def click_display(self,item,target,event): for l in range(6): if(self.c[l].get_property("fill_color_rgba") == red_fill): self.cell.append(l+1) if(self.gcomprisBoard.level == 1): for k,v in braille_letters.items()[:13]: if v == self.cell: self.braille_char(item,target,event,x1,y1,string.upper(k),False,True) elif(self.gcomprisBoard.level == 2): for k,v in braille_letters.items()[13:]: if v == self.cell: self.braille_char(item,target,event,x1,y1,string.upper(k),False,True)
\ No newline at end of file
+# gcompris - braille_alphabets.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_alphabets activity.
+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],
+}
+
+cell_width = 40
+x1 = 190
+y1 = 150
+red_fill = 4278190335
+class Gcompris_braille_alphabets:
+ """Empty gcompris python class"""
+
+
+ def __init__(self, gcomprisBoard):
+ # Save the gcomprisBoard, it defines everything we need
+ # to know from the core
+
+ #defining the number of levels in activity
+ self.gcomprisBoard = gcomprisBoard
+ self.gcomprisBoard.level = 1
+ self.gcomprisBoard.maxlevel=2
+ self.gcomprisBoard.sublevel=1
+ self.gcomprisBoard.number_of_sublevel=1
+
+ # Needed to get key_press
+ gcomprisBoard.disable_im_context = True
+
+ def start(self):
+ # Set the buttons we want in the bar
+ gcompris.bar_set_level(self.gcomprisBoard)
+ gcompris.bar_set(gcompris.BAR_LEVEL)
+
+ # Set a background image
+ gcompris.set_background(self.gcomprisBoard.canvas.get_root_item(),
+ "mosaic_bg.svgz")
+
+ # 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.display_game()
+
+ def end(self):
+ # Remove the root item removes all the others inside it
+ self.rootitem.remove()
+
+ def ok(self):
+ print("learnbraille ok.")
+
+ def repeat(self):
+ print("learnbraille repeat.")
+
+
+ def config(self):
+ print("learnbraille config.")
+
+
+ def key_press(self, keyval, commit_str, preedit_str):
+ utf8char = gtk.gdk.keyval_to_unicode(keyval)
+ strn = u'%c' % utf8char
+
+ print("Gcompris_learnbraille key press keyval=%i %s" % (keyval, strn))
+
+ def pause(self, pause):
+ print("learnbraille pause. %i" % pause)
+
+ def set_level(self, level):
+ gcompris.sound.play_ogg("sounds/receive.wav")
+ self.gcomprisBoard.level = level
+ self.gcomprisBoard.sublevel = 1
+ gcompris.bar_set_level(self.gcomprisBoard)
+ print("braille_alphabets set level. %i" % self.gcomprisBoard.level)
+ self.increment_level()
+
+
+ def increment_level(self):
+ gcompris.sound.play_ogg("sounds/bleep.wav")
+ self.end()
+ self.start()
+
+
+ def display_game(self):
+ goocanvas.Text(parent=self.rootitem, x=390.0, y=70.0, text=_("Alphabet"),
+ width=500, height=500, fill_color="blue",
+ anchor=gtk.ANCHOR_CENTER, font='BOLD')
+
+ """call braille cell"""
+ self.braille_cell()
+ self.board_lower(self.gcomprisBoard.level)
+
+ """Call lower board 1 or 2"""
+
+ def board_lower(self,level):
+ if(level ==1):
+ self.board_lower1()
+ elif(level == 2) :
+ self.board_lower2()
+
+
+
+ def board_lower1(self):
+ for i, letter in enumerate(string.ascii_uppercase[:13]):
+ tile = self.braille_tile(letter, cell_width, i)
+
+
+ def braille_tile(self, letter, cell_width, index_x):
+
+ padding = cell_width * 0.21
+ cell_size = cell_width / 2 - padding
+
+ inner_padding = cell_width * 0.08
+ cell_radius = cell_size - inner_padding * 2
+ item = goocanvas.Rect(parent=self.rootitem,
+ x=index_x * (cell_width + 10) + 60,
+ y=350, width=40,
+ height=60,
+ stroke_color="blue",
+ fill_color="#DfDfDf",
+ line_width=2.0)
+
+
+ item.connect("button_press_event", self.braille_char, x1, y1, letter, True, True)
+ gcompris.utils.item_focus_init(item, None)
+ goocanvas.Text(parent=self.rootitem, x=(index_x * (cell_width + 10) + 60) + 10,
+ y=425, text=str(letter),
+ fill_color="blue",
+ font='BOLD')
+
+
+ cells = []
+ for u in range(2):
+ for v in range(3):
+ cell = goocanvas.Ellipse(parent=self.rootitem,
+ center_x=index_x * 50 + u * 20 + 70,
+ center_y=v * 15 + 365,
+ radius_x=cell_radius,
+ radius_y=cell_radius,
+ stroke_color="blue",
+ line_width=2.0)
+ #keep a separate track so we don't mix up with other cells
+ cells.append(cell)
+
+ #To fill the circles in lower board with red color
+ fillings = braille_letters.get(letter.lower())
+ for index_x in range(6):
+ cells[index_x].connect("button_press_event", self.braille_char, x1, y1, letter, True, True)
+ gcompris.utils.item_focus_init(cells[index_x], item)
+ if(index_x + 1) in fillings:
+ cells[index_x].set_property("fill_color", "red")
+ else :
+ cells[index_x].set_property("fill_color", "#DfDfDf")
+
+ def braille_char(self, event, target, item, a, b, letter, clickable, displayable):
+ """Checking the booleans to evaluate if text is to displayed & if its clickable"""
+
+ if(displayable == True):
+ #load an image in alphabet area before displaying text
+ goocanvas.Image(parent=self.rootitem,
+ pixbuf=gcompris.utils.load_pixmap("drawing.svg"),
+ x=100,
+ y=80,
+ width=200,
+ height=200)
+ text1 = goocanvas.Text(parent=self.rootitem,
+ x=a,
+ y=b,
+ fill_color="blue",
+ font="Sans 78",
+ anchor=gtk.ANCHOR_CENTER,
+ text=str(letter))
+
+ if(clickable == True):
+ text1.connect("button_press_event", self.display_letter, letter)
+ gcompris.utils.item_focus_init(text1, None)
+
+ def display_letter(self, item, event, target, letter):
+ #To fill the points in braille cell area
+ self.fillings = braille_letters.get(letter.lower())
+ for i in range(6):
+ if(i + 1) in self.fillings:
+ self.c[i].set_property("fill_color", "red")
+ else :
+ self.c[i].set_property("fill_color", "#DfDfDf")
+ def board_lower2(self):
+ for i, letter in enumerate(string.ascii_uppercase[13:]):
+ tile = self.braille_tile(letter, cell_width, i)
+
+
+ """Braille Cell function to represent the dots & braille code"""
+ def braille_cell(self):
+
+ #Braille Cell Array
+ self.c = []
+ goocanvas.Text(parent=self.rootitem,
+ x=540.0, y=70.0,
+ text=_("Braille Cell"),
+ fill_color="blue",
+ font='BOLD')
+ for i in range(2):
+ for j in range(3):
+ goocanvas.Text(parent=self.rootitem,
+ text=(str(j + 1 + i * 3)),
+ font='Sans 30',
+ fill_color="blue",
+ x=i * 140 + 510,
+ y=j * 50 + 100)
+ cell1 = goocanvas.Ellipse(parent=self.rootitem,
+ center_x=i * 50 + 570,
+ center_y=j * 50 + 120,
+ radius_x=20, radius_y=20,
+ stroke_color="blue",
+ fill_color="#DfDfDf",
+ line_width=5.0)
+
+ #to ensure that cells do not mess up & append
+ #them to array
+ self.c.append(cell1)
+
+ #To make the points clickable in braille cell area
+ for index in range(6):
+ self.c[index].connect("button_press_event",self.change_color,index)
+ gcompris.utils.item_focus_init(self.c[index],None)
+
+ """function being called on click of a point"""
+ def change_color(self,item,event,target,incr):
+ self.cell = []
+ #set the property of point to transparent if it is red
+ if(self.c[incr].get_property("fill_color_rgba") == red_fill):
+ self.c[incr].set_property("fill_color","#DfDfDf")
+ self.click_display(item,target,event)
+ else :
+ #set the property of point to red if it is transparent
+ self.c[incr].set_property("fill_color","red")
+ self.click_display(item,target,event)
+
+ """Appends the point clicked in an array"""
+ def click_display(self,item,target,event):
+ for l in range(6):
+ if(self.c[l].get_property("fill_color_rgba") == red_fill):
+ self.cell.append(l+1)
+ if(self.gcomprisBoard.level == 1):
+ for k,v in braille_letters.items()[:13]:
+ if v == self.cell:
+ self.braille_char(item,target,event,x1,y1,string.upper(k),False,True)
+ elif(self.gcomprisBoard.level == 2):
+ for k,v in braille_letters.items()[13:]:
+ if v == self.cell:
+ self.braille_char(item,target,event,x1,y1,string.upper(k),False,True)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]