[gcompris/gcomprisbraille] Reusable repeat code|Changes in four activities
- From: Srishti Sethi <srishs src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcompris/gcomprisbraille] Reusable repeat code|Changes in four activities
- Date: Thu, 7 Jul 2011 19:21:39 +0000 (UTC)
commit 02c210b023d15e55cf8cfde26d8f3b2552d45f8d
Author: Srishti Sethi <srishakatux gmail com>
Date: Fri Jul 8 00:51:07 2011 +0530
Reusable repeat code|Changes in four activities
src/braille_alphabets-activity/BrailleChar.py | 2 +-
.../braille_alphabets.py | 57 ++++++----
src/braille_lotto-activity/braille_lotto.py | 119 ++------------------
src/dicey_dicey-activity/dicey_dicey.py | 43 +-------
src/rhymes_riddles-activity/rhymes_riddles.py | 25 +----
5 files changed, 52 insertions(+), 194 deletions(-)
---
diff --git a/src/braille_alphabets-activity/BrailleChar.py b/src/braille_alphabets-activity/BrailleChar.py
index 8ce2df0..dc78448 100644
--- a/src/braille_alphabets-activity/BrailleChar.py
+++ b/src/braille_alphabets-activity/BrailleChar.py
@@ -38,7 +38,7 @@ BRAILLE_LETTERS = {
"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], "+" : [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]
}
diff --git a/src/braille_alphabets-activity/braille_alphabets.py b/src/braille_alphabets-activity/braille_alphabets.py
index e4d8ab4..d8fa859 100644
--- a/src/braille_alphabets-activity/braille_alphabets.py
+++ b/src/braille_alphabets-activity/braille_alphabets.py
@@ -30,11 +30,11 @@ import random
from gcompris import gcompris_gettext as _
from BrailleChar import *
-cell_width = 40
-on = 0xFF0000FFL
-off = 0X00000000L
-circle_fill = "#DfDfDf"
-circle_stroke = "blue"
+CELL_WIDTH = 30
+COLOR_ON = 0xFF0000FFL
+COLOR_OFF = 0X00000000L
+CIRCLE_FILL = "#DfDfDf"
+CIRCLE_STROKE = "blue"
braille_desc = {'intro' : "A system of writing for the blinds that \n"
"uses characters made of raised dots. \n\n"
@@ -113,25 +113,7 @@ class Gcompris_braille_alphabets:
self.gcomprisBoard.canvas.get_root_item())
gcompris.set_default_background(self.gcomprisBoard.canvas.get_root_item())
- #Place alphabets & numbers in array format
- for i, letter in enumerate(string.ascii_uppercase[:10]):
- tile = BrailleChar(self.rootitem, i*(cell_width+30)+60,
- 60, 50, letter ,on,off,circle_fill,
- circle_stroke,True ,False,True,None)
- for i, letter in enumerate(string.ascii_uppercase[10:20]):
- tile = BrailleChar(self.rootitem, i*(cell_width+30)+60,
- 150, 50, letter ,on, off, circle_fill,
- circle_stroke, True ,False,True,None)
- for i, letter in enumerate(string.ascii_uppercase[20:25]):
- tile = BrailleChar(self.rootitem, i*(cell_width+30)+60,
- 250, 50, letter ,on ,off ,circle_fill,
- circle_stroke, True ,False,True, None)
- BrailleChar(self.rootitem,60, 350, 50, "#",on ,off, circle_fill,
- circle_stroke, True, False,True, None)
- for letter in range(0,10):
- tile = BrailleChar(self.rootitem,(letter+1) *(cell_width+25)+60,
- 350, 50, letter ,on ,off ,circle_fill,
- circle_stroke, True ,False ,True, None)
+ self.Braille_Map(self.rootitem, COLOR_ON, COLOR_OFF,CIRCLE_FILL, CIRCLE_STROKE)
#Move back item
self.backitem = goocanvas.Image(parent = self.rootitem,
pixbuf = gcompris.utils.load_pixmap("braille_alphabets/back.png"),
@@ -339,3 +321,30 @@ class Gcompris_braille_alphabets:
def letter_change(self,letter):
self.correct_letter = letter
+
+ def Braille_Map(self, rootitem, color_on, color_off, circle_fill, circle_stroke):
+ SYMBOL = ['+','_','*','/']
+ #Place alphabets & numbers in array format
+
+ for index, letter in enumerate(string.ascii_uppercase[:10]):
+ BrailleChar(rootitem, index*(CELL_WIDTH+40)+60,
+ 40, 38, letter ,color_on, color_off, circle_fill,
+ circle_stroke,True ,False ,True , None)
+ for index, letter in enumerate(string.ascii_uppercase[10:20]):
+ BrailleChar(rootitem, index*(CELL_WIDTH+40)+60,
+ 130, 38, letter ,color_on, color_off, circle_fill,
+ circle_stroke,True ,False ,True , None)
+ for index, letter in enumerate(string.ascii_uppercase[20:25]):
+ BrailleChar(rootitem, index*(CELL_WIDTH+40)+60,
+ 220, 38, letter ,color_on, color_off, circle_fill,
+ circle_stroke,True ,False ,True , None)
+ BrailleChar(rootitem,60, 310, 38, "#",color_on, color_off, circle_fill,
+ circle_stroke,True ,False ,True , None)
+ for index in range(10):
+ BrailleChar(rootitem,(index+1) *(CELL_WIDTH + 33)+60,
+ 310, 38, index ,color_on, color_off, circle_fill,
+ circle_stroke,True ,False ,True , None)
+ for index in range(4):
+ BrailleChar(rootitem,index * (CELL_WIDTH + 40) + 60,
+ 400 , 38,SYMBOL[index],color_on, color_off, circle_fill,
+ circle_stroke,True ,False ,True , None)
\ No newline at end of file
diff --git a/src/braille_lotto-activity/braille_lotto.py b/src/braille_lotto-activity/braille_lotto.py
index 9a510ee..7084565 100644
--- a/src/braille_lotto-activity/braille_lotto.py
+++ b/src/braille_lotto-activity/braille_lotto.py
@@ -16,28 +16,18 @@
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
# braille_lotto activity.
-import goocanvas
+import gtk
+import gtk.gdk
import gcompris
-from gcompris import gcompris_gettext as _
import gcompris.utils
-import gcompris.bonus
import gcompris.skin
-import gcompris.sound
+import gcompris.bonus
import gcompris.timer
-import gtk
-import gtk.gdk
-import gobject
+import goocanvas
import random
-import cairo
-from BrailleChar import *
-
-import socket
-import struct
import pango
-import sys
-import uuid
-
-from socket import gethostname
+from BrailleChar import *
+from braille_alphabets import *
from gcompris import gcompris_gettext as _
#CONSTANTS for generating TICKET A
@@ -74,14 +64,6 @@ class Gcompris_braille_lotto:
# to know from the core
self.gcomprisBoard = gcomprisBoard
- # Adress and port
- self.mcast_adress = "227.234.253.9"
- self.port = 15922
- self.mcast_timer = 0
- self.sock = None
- # Used to recognize our own network message
- self.uuid = uuid.uuid1().hex
-
# Needed to get key_press
gcomprisBoard.disable_im_context = True
@@ -239,7 +221,7 @@ class Gcompris_braille_lotto:
self.lotto_room_tv.set_editable(False)
self.lotto_room_sw.add(self.lotto_room_tv)
# save name and selected color in a map
- self.lotto_room_map = []
+ self.lotto_room_map = {}
self.lotto_room_tb.set_text("")
@@ -281,7 +263,7 @@ class Gcompris_braille_lotto:
self.channel.show()
self.channel.set_text("Type your channel name in order to start playing")
- self.channel.connect("activate",self.enter_callback, self.channel)
+
# A label for the channel area
goocanvas.Text(
@@ -474,66 +456,6 @@ class Gcompris_braille_lotto:
BrailleChar(self.rootitem, 738, 377, 33 , ones_digit_f, COLOR_ON, COLOR_OFF ,
CIRCLE_FILL, CIRCLE_FILL, False, False ,True, None)
- try:
- # Start the server
- self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
- self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
- self.sock.bind(('', self.port))
- mreq = struct.pack('4sl', socket.inet_aton(self.mcast_adress), socket.INADDR_ANY)
- self.sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
- self.sock.setblocking(0)
- self.timer_interval = 10
- self.mcast_timer = gobject.timeout_add(self.timer_interval, self.mcast_read)
- print self.mcast_timer
- except:
- gcompris.utils.dialog(_("GCompris ERROR: Failed to initialize the network interface.\n"
- " You cannot communicate."),None)
- self.pause(1)
-
-
- def enter_callback(self, widget, entry):
- gcompris.sound.play_ogg("sounds/bleep.wav")
- if(not self.channel.get_text()):
- gcompris.utils.dialog(_("GCompris You must set a channel in your channel entry box first.\n"
- "Your friends must set the same channel in order to start playing"),None)
- return
- Prop = gcompris.get_properties()
- entry_text = entry.get_text()
- # format the message
- entry_text = ("GCOMPRIS:CHAT:" +
- self.channel.get_text() + ":" +
- Prop.logged_user.login + ":" +
- ":" + entry_text)
- self.send_message(entry_text)
-
-
- def send_message(self, message):
- """sends the given message."""
-
- sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,
- socket.IPPROTO_UDP)
- sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2)
-
- sock.sendto(message, (self.mcast_adress, self.port))
- sock.close()
-
- def mcast_read(self):
- if not self.mcast_timer:
- return
- self.mcast_timer = gobject.timeout_add(self.timer_interval,
- self.mcast_read)
- text = ""
- try:
- text = self.sock.recv(10240)
- print "Received text: %s\n" % text
- except:
- return
- # Parse it
- textl = text.split(":", 10)
- self.lotto_room_map.append(textl[3])
- self.lotto_room_tb.set_text(textl[3])
- gcompris.sound.play_ogg("sounds/receive.wav")
- return False
def say(self):
@@ -568,26 +490,8 @@ class Gcompris_braille_lotto:
self.rootitem = goocanvas.Group(parent=
self.gcomprisBoard.canvas.get_root_item())
gcompris.set_default_background(self.gcomprisBoard.canvas.get_root_item())
-
- #Place alphabets & numbers in array format
- for index, letter in enumerate(string.ascii_uppercase[:10]):
- tile = BrailleChar(self.rootitem, index*(CELL_WIDTH+40)+60,
- 55, 50, letter ,COLOR_ON, COLOR_OFF, CIRCLE_FILL,
- CIRCLE_FILL, True ,False ,True , None)
- for index, letter in enumerate(string.ascii_uppercase[10:20]):
- tile = BrailleChar(self.rootitem, index*(CELL_WIDTH+40)+60,
- 150, 50, letter ,COLOR_ON, COLOR_OFF, CIRCLE_FILL,
- CIRCLE_FILL, True ,False ,True, None)
- for index, letter in enumerate(string.ascii_uppercase[20:25]):
- tile = BrailleChar(self.rootitem, index*(CELL_WIDTH+40)+60,
- 250, 50, letter ,COLOR_ON ,COLOR_OFF ,CIRCLE_FILL,
- CIRCLE_FILL, True ,False,True, None)
- BrailleChar(self.rootitem,60, 350, 50, "#",COLOR_ON,COLOR_OFF, CIRCLE_FILL,
- CIRCLE_FILL, True, False,True, None)
- for index in range(0,10):
- tile = BrailleChar(self.rootitem,(index+1) *(CELL_WIDTH + 33)+60,
- 350, 50, index ,COLOR_ON,COLOR_OFF ,CIRCLE_FILL,
- CIRCLE_FILL, True ,False ,True, None)
+ map_obj = Gcompris_braille_alphabets(self.gcomprisBoard)
+ map_obj.Braille_Map(self.rootitem, COLOR_ON, COLOR_OFF, CIRCLE_FILL, CIRCLE_STROKE)
self.mapActive = True
self.pause(1)
@@ -615,10 +519,7 @@ class Gcompris_braille_lotto:
self.channel.show()
self.lotto_room_tv.show()
self.lotto_room_sw.show()
- #Setting Timer
- gcompris.timer.display(560,100,gcompris.timer.CLOCK,10,self.say)
gcompris.timer.pause(9)
- gcompris.timer.add(10)
def set_level(self, level):
diff --git a/src/dicey_dicey-activity/dicey_dicey.py b/src/dicey_dicey-activity/dicey_dicey.py
index 85bcc28..c7d767a 100644
--- a/src/dicey_dicey-activity/dicey_dicey.py
+++ b/src/dicey_dicey-activity/dicey_dicey.py
@@ -27,6 +27,7 @@ import pango
import random
import gcompris.bonus
from BrailleChar import *
+from braille_alphabets import *
from gcompris import gcompris_gettext as _
#Constants Declaration
@@ -313,48 +314,10 @@ class Gcompris_dicey_dicey:
self.rootitem = goocanvas.Group(parent=
self.gcomprisBoard.canvas.get_root_item())
gcompris.set_default_background(self.gcomprisBoard.canvas.get_root_item())
-
- #Place alphabets & numbers in array format
- for index, letter in enumerate(string.ascii_uppercase[:10]):
- tile = BrailleChar(self.rootitem, index*(CELL_WIDTH+40)+60,
- 60, 38, letter ,COLOR_ON, COLOR_OFF, CIRCLE_FILL,
- CIRCLE_FILL, True ,False ,True , None)
- for index, letter in enumerate(string.ascii_uppercase[10:20]):
- tile = BrailleChar(self.rootitem, index*(CELL_WIDTH+40)+60,
- 135, 38, letter ,COLOR_ON, COLOR_OFF, CIRCLE_FILL,
- CIRCLE_FILL, True ,False ,True, None)
- for index, letter in enumerate(string.ascii_uppercase[20:25]):
- tile = BrailleChar(self.rootitem, index*(CELL_WIDTH+40)+60,
- 210, 38, letter ,COLOR_ON ,COLOR_OFF ,CIRCLE_FILL,
- CIRCLE_FILL, True ,False,True, None)
- BrailleChar(self.rootitem,60, 285, 38, "#",COLOR_ON,COLOR_OFF, CIRCLE_FILL,
- CIRCLE_FILL, True, False,True, None)
- for index in range(0,10):
- tile = BrailleChar(self.rootitem,(index+1) *(CELL_WIDTH + 33)+60,
- 285, 38, index ,COLOR_ON,COLOR_OFF ,CIRCLE_FILL,
- CIRCLE_FILL, True ,False ,True, None)
- for index in range(4):
- BrailleChar(self.rootitem,index * (CELL_WIDTH + 40) + 60,
- 360 , 38,SYMBOL[index],COLOR_ON,COLOR_OFF,CIRCLE_FILL
- ,CIRCLE_FILL,True, False , True, None)
-
- #Move back item
- self.backitem = goocanvas.Image(parent = self.rootitem,
- pixbuf = gcompris.utils.load_pixmap("dicey_dicey/back.png"),
- x = 600,
- y = 450,
- tooltip = "Move Back"
- )
- self.backitem.connect("button_press_event", self.move_back)
- gcompris.utils.item_focus_init(self.backitem, None)
-
+ map_obj = Gcompris_braille_alphabets(self.gcomprisBoard)
+ map_obj.Braille_Map(self.rootitem, COLOR_ON, COLOR_OFF, CIRCLE_FILL, CIRCLE_STROKE)
self.mapActive = True
-
- def move_back(self,event,target,item):
- self.end()
- self.start()
-
def config(self):
print("dicey_dicey config.")
diff --git a/src/rhymes_riddles-activity/rhymes_riddles.py b/src/rhymes_riddles-activity/rhymes_riddles.py
index 3ab60d4..112fc9d 100644
--- a/src/rhymes_riddles-activity/rhymes_riddles.py
+++ b/src/rhymes_riddles-activity/rhymes_riddles.py
@@ -28,12 +28,14 @@ import random
import string
from BrailleChar import *
+from braille_alphabets import *
from gcompris import gcompris_gettext as _
#Constants Declaration
COLOR_ON = 0XCC3399L
COLOR_OFF = 0X00000000L
CIRCLE_FILL = "#CC3399"
+CIRCLE_STROKE = "#CC3399"
CELL_WIDTH = 30
RHYMES_RIDDLES_LIST = [
[ # Level 1
@@ -138,6 +140,7 @@ class Gcompris_rhymes_riddles:
BrailleChar(self.rootitem,index*(CELL_WIDTH+20)+100,350,40,str[index],
COLOR_ON, COLOR_OFF, CIRCLE_FILL,
CIRCLE_FILL, False, False, True,None)
+
# the answer area
self.entry = gtk.Entry()
self.entry.connect("activate", self.enter_callback,self.entry,level)
@@ -185,26 +188,8 @@ class Gcompris_rhymes_riddles:
self.rootitem = goocanvas.Group(parent=
self.gcomprisBoard.canvas.get_root_item())
gcompris.set_default_background(self.gcomprisBoard.canvas.get_root_item())
-
- #Place alphabets & numbers in array format
- for index, letter in enumerate(string.ascii_uppercase[:10]):
- tile = BrailleChar(self.rootitem, index*(CELL_WIDTH+40)+60,
- 55, 50, letter ,COLOR_ON, COLOR_OFF, CIRCLE_FILL,
- CIRCLE_FILL, True ,False ,True , None)
- for index, letter in enumerate(string.ascii_uppercase[10:20]):
- tile = BrailleChar(self.rootitem, index*(CELL_WIDTH+40)+60,
- 150, 50, letter ,COLOR_ON, COLOR_OFF, CIRCLE_FILL,
- CIRCLE_FILL, True ,False ,True, None)
- for index, letter in enumerate(string.ascii_uppercase[20:25]):
- tile = BrailleChar(self.rootitem, index*(CELL_WIDTH+40)+60,
- 250, 50, letter ,COLOR_ON ,COLOR_OFF ,CIRCLE_FILL,
- CIRCLE_FILL, True ,False,True, None)
- BrailleChar(self.rootitem,60, 350, 50, "#",COLOR_ON,COLOR_OFF, CIRCLE_FILL,
- CIRCLE_FILL, True, False,True, None)
- for index in range(0,10):
- tile = BrailleChar(self.rootitem,(index+1) *(CELL_WIDTH + 33)+60,
- 350, 50, index ,COLOR_ON,COLOR_OFF ,CIRCLE_FILL,
- CIRCLE_FILL, True ,False ,True, None)
+ map_obj = Gcompris_braille_alphabets(self.gcomprisBoard)
+ map_obj.Braille_Map(self.rootitem, COLOR_ON, COLOR_OFF, CIRCLE_FILL, CIRCLE_STROKE)
self.mapActive = True
self.pause(1)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]