Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalter Bender <walter.bender@gmail.com>2013-02-02 07:26:38 (GMT)
committer Walter Bender <walter.bender@gmail.com>2013-02-02 07:26:38 (GMT)
commit76b2514ce55046ed18cb5c457a9e04067e808523 (patch)
tree2e819d390eb8ddbb886015a4457d23d87ada4304
parent4706a4975be4e326f6cf999316251ed91a3b10aa (diff)
add visual feedback
-rw-r--r--LetterMatch.py18
-rw-r--r--NEWS4
-rw-r--r--activity/activity.info2
-rwxr-xr-xgenpieces.py12
-rw-r--r--images/correct.pngbin0 -> 41806 bytes
-rw-r--r--images/wrong.pngbin0 -> 42162 bytes
-rw-r--r--page.py66
7 files changed, 76 insertions, 26 deletions
diff --git a/LetterMatch.py b/LetterMatch.py
index 0a1e6c2..7983509 100644
--- a/LetterMatch.py
+++ b/LetterMatch.py
@@ -19,8 +19,6 @@ from sugar.graphics.toolbarbox import ToolbarBox, ToolbarButton
from sugar.activity.widgets import ActivityToolbarButton
from sugar.activity.widgets import StopButton
from sugar.graphics.toolbutton import ToolButton
-from sugar.graphics.combobox import ComboBox
-from sugar.graphics.toolcombobox import ToolComboBox
from sugar.datastore import datastore
from sugar import profile
from sugar.graphics.objectchooser import ObjectChooser
@@ -73,16 +71,14 @@ class LetterMatch(activity.Activity):
language = 'es'
self.letter = None
- if os.path.exists(os.path.join('~', 'Activities',
- 'IKnowMyABCs.activity')):
- self._lessons_path = os.path.join('~', 'Activities',
- 'IKnowMyABCs.activity',
- 'lessons', language)
- else:
- self._lessons_path = os.path.join('.', 'lessons', language)
+ self.activity_path = activity.get_bundle_path()
+ self._lessons_path = os.path.join(self.activity_path,
+ 'lessons', language)
- self._images_path = self._lessons_path.replace('lessons', 'images')
- self._sounds_path = self._lessons_path.replace('lessons', 'sounds')
+ self._images_path = os.path.join(self.activity_path,
+ 'images', language)
+ self._sounds_path = os.path.join(self.activity_path,
+ 'sounds', language)
self.data_from_journal = {}
if 'data_from_journal' in self.metadata:
self.data_from_journal = json.loads(
diff --git a/NEWS b/NEWS
index 6c340df..642b535 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,7 @@
+6
+
+* Add visual feedback
+
4
* Add audio pause (Aneesh Dogra)
diff --git a/activity/activity.info b/activity/activity.info
index 7f368e5..2104880 100644
--- a/activity/activity.info
+++ b/activity/activity.info
@@ -1,6 +1,6 @@
[Activity]
name = Letter Match
-activity_version = 4
+activity_version = 6
license = GPLv3
bundle_id = org.sugarlabs.LetterMatch
exec = sugar-activity LetterMatch.LetterMatch
diff --git a/genpieces.py b/genpieces.py
index f4d8485..bf9232d 100755
--- a/genpieces.py
+++ b/genpieces.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-#Copyright (c) 2009-11 Walter Bender
+#Copyright (c) 2009-13 Walter Bender
# 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
@@ -146,6 +146,16 @@ def generator(datapath):
close_file(f)
+def genblank(w, h, colors, stroke_width=1.0):
+ svg = SVG()
+ svg.set_scale(1)
+ svg.set_colors(colors)
+ svg.set_stroke_width(stroke_width)
+ svg_string = svg.header(int(w / 80), int(h / 60))
+ svg_string += svg.footer()
+ return svg_string
+
+
def main():
return 0
diff --git a/images/correct.png b/images/correct.png
new file mode 100644
index 0000000..95f5d5d
--- /dev/null
+++ b/images/correct.png
Binary files differ
diff --git a/images/wrong.png b/images/wrong.png
new file mode 100644
index 0000000..63084d4
--- /dev/null
+++ b/images/wrong.png
Binary files differ
diff --git a/page.py b/page.py
index ebaf1ee..076aae5 100644
--- a/page.py
+++ b/page.py
@@ -14,24 +14,21 @@
import gtk
import gobject
import os
-import codecs
from random import uniform, choice
from gettext import gettext as _
-from sugar.datastore import datastore
from utils.play_audio import play_audio_from_file
import logging
_logger = logging.getLogger('lettermatch-activity')
-try:
- from sugar.graphics import style
- GRID_CELL_SIZE = style.GRID_CELL_SIZE
-except ImportError:
- GRID_CELL_SIZE = 0
+from sugar.datastore import datastore
+from sugar import profile
+from sugar.graphics import style
+GRID_CELL_SIZE = style.GRID_CELL_SIZE
-from genpieces import generate_card
+from genpieces import generate_card, genblank
from utils.sprites import Sprites, Sprite
@@ -51,6 +48,8 @@ class Page():
self._images_path = images_path
self._sounds_path = sounds_path
+ self._colors = profile.get_color().to_string().split(',')
+
self._card_data = []
self._color_data = []
self._image_data = []
@@ -95,6 +94,30 @@ class Page():
self.target = 0
self.answers = [0, 0, 0, 0, 0, 0]
+ self._my_canvas = Sprite(
+ self._sprites, 0, 0, svg_str_to_pixbuf(genblank(
+ self._width, self._height, (self._colors[0],
+ self._colors[0]))))
+ self._my_canvas.type = 'background'
+
+ self._smile = Sprite(self._sprites,
+ int(self._width / 4),
+ int(self._height / 4),
+ gtk.gdk.pixbuf_new_from_file_at_size(
+ os.path.join(self._activity.activity_path,
+ 'images', 'correct.png'),
+ int(self._width / 2),
+ int(self._height / 2)))
+
+ self._frown = Sprite(self._sprites,
+ int(self._width / 4),
+ int(self._height / 4),
+ gtk.gdk.pixbuf_new_from_file_at_size(
+ os.path.join(self._activity.activity_path,
+ 'images', 'wrong.png'),
+ int(self._width / 2),
+ int(self._height / 2)))
+
self.load_level(os.path.join(self._lessons_path, 'alphabet' + '.csv'))
# Create the cards we'll need
@@ -103,11 +126,17 @@ class Page():
self.new_page()
+ def _hide_feedback(self):
+ if hasattr(self, '_smile'):
+ self._smile.hide()
+ self._frown.hide()
+
def new_page(self):
''' Load a page of cards '''
if self.timeout is not None:
gobject.source_remove(self.timeout)
self._hide_cards()
+ self._hide_feedback()
self.new_target()
x = self._grid_x_offset + self._card_width + GUTTER * 3
y = self._grid_y_offset + GUTTER
@@ -157,13 +186,13 @@ class Page():
if type(self._color_data[self.current_card][0]) == type([]):
stroke = self._test_for_stroke()
top = svg_str_to_pixbuf(generate_card(
- string=card[0].lower(),
+ string=card[0],
colors=[self._color_data[self.current_card][0][0],
'#FFFFFF'],
scale=self._scale,
center=True))
bot = svg_str_to_pixbuf(generate_card(
- string=card[0].lower(),
+ string=card[0],
colors=[self._color_data[self.current_card][0][1],
'#FFFFFF'],
scale=self._scale,
@@ -179,7 +208,8 @@ class Page():
stroke = self._test_for_stroke()
self._cards.append(Sprite(self._sprites, 0, 0,
svg_str_to_pixbuf(generate_card(
- string=card[0].lower(),
+ string='%s%s' % (
+ card[0].upper(), card[0].lower()),
colors=[self._color_data[self.current_card][0],
'#FFFFFF'],
stroke=stroke,
@@ -275,12 +305,21 @@ class Page():
if self.current_card == self.target:
self._activity.status.set_text(_('Very good!'))
+ self._play(True)
if self.timeout is not None:
gobject.source_remove(self.timeout)
self.timeout = gobject.timeout_add(1000, self.new_page)
else:
+ self._play(False)
self._activity.status.set_text(_('Please try again.'))
self._play_target_sound()
+ self.timeout = gobject.timeout_add(1000, self._hide_feedback)
+
+ def _play(self, great):
+ if great:
+ self._smile.set_layer(1000)
+ else:
+ self._frown.set_layer(1000)
def _keypress_cb(self, area, event):
''' No keyboard shortcuts at the moment. Perhaps jump to the page
@@ -322,7 +361,7 @@ class Page():
self._color_data = []
self._image_data = {} # {letter: [(Sprite, image_sound_path)...]}
self._pictures = []
- f = codecs.open(path, encoding='utf-8')
+ f = open(path)
for line in f:
if len(line) > 0 and line[0] not in '#\n':
words = line.split(', ')
@@ -358,7 +397,8 @@ class Page():
audiodataobject = datastore.get(images[1])
if imagedataobject and audiodataobject:
imagepath = imagedataobject.get_file_path()
- pixbuf = image_file_to_pixbuf(imagepath, self._card_width,
+ pixbuf = image_file_to_pixbuf(imagepath,
+ self._card_width,
self._card_height)
audiopath = audiodataobject.get_file_path()
s = Sprite(self._sprites, 0, 0, pixbuf)