diff options
author | Wade Brainerd <wadetb@gmail.com> | 2009-02-01 01:19:09 (GMT) |
---|---|---|
committer | Wade Brainerd <wadetb@gmail.com> | 2009-02-01 01:19:09 (GMT) |
commit | 41a368e7850e999c4cc37b88deee25d60d1cd3a0 (patch) | |
tree | 91204c164b3dda47884048c66645d93318698943 | |
parent | 2e6e0bbeecba10edbe6cd7536f7cd6e2914469b9 (diff) |
Keyboard image preloader.
-rw-r--r-- | TODO | 8 | ||||
-rw-r--r-- | keyboard.py | 77 | ||||
-rw-r--r-- | lessonscreen.py | 8 | ||||
-rw-r--r-- | mainscreen.py | 8 |
4 files changed, 42 insertions, 59 deletions
@@ -27,7 +27,6 @@ First Release + Status message on the main screen. "You unlocked a new lesson!" for example. Eventually have the turtle 'say' it. + Graphical WPM and accuracy meters. + Make medal WPM adjustable somehow? Perhaps a settable Goal WPM? -+ Highlight regions of keyboard, color by finger. + Sound effects. + Welcome to the activity sound. + Speed up / slow down sounds when WPM crosses threshold: Slow, Medium, Fast. @@ -35,6 +34,7 @@ First Release + Incorrect key pressed tick sound. Future Release ++ Highlight regions of keyboard, color by finger. + Goal support with progress reporting. WPM, Accuracy, Entire keyboard learned, etc. + Keymap showing skill per key. Star icons on keys that are mastered. + History screen: List of lessons completed with statistics. @@ -43,10 +43,10 @@ Future Release Balloon Game -+ Game finished popup, displays score and medal text. -+ Fix flickering +- Game finished popup, displays score and medal text. +- Fix flickering + Improve graphics. -+ Support for displaying high score in home screen. +- Support for displaying high score in home screen. Paper Airplane Game diff --git a/keyboard.py b/keyboard.py index 8ff98b2..b71ab71 100644 --- a/keyboard.py +++ b/keyboard.py @@ -20,11 +20,16 @@ import pygtk pygtk.require('2.0') import gtk import rsvg -import os +import os, glob import pango import sugar.activity.activity +# Tweaking variables. +KEYBOARD_SCALE = 1.25 +HAND_SCALE = 1.4 +HAND_YOFFSET = -35 + PARAGRAPH_CODE = u'\xb6' # List of all key properties in the keyboard layout description. @@ -96,8 +101,8 @@ KEY_PROPS = [ # # Entirely new keyboard layouts can be created just by copying this structure and # modifying the following values, without changing the code. -DEFAULT_LAYOUT = { - 'layout-name': "default", +OLPC_LAYOUT = { + 'layout-name': "olpc", 'layout-width': 775, 'layout-height': 265, @@ -109,24 +114,6 @@ DEFAULT_LAYOUT = { 'key-gap': 5, 'groups': [ - # Note- Top row disabled for now to make more room for the other rows. - #{ - # 'group-name': "row0", - # 'group-x': 10, - # 'group-y': 10, - # - # 'key-height': 35, - # - # 'keys': [ - # {}, # Escape - # {}, # Show Source - # {'key-width':182}, # Zoom - # {'key-width':182}, # Size - # {'key-width':181}, # Volume - # {}, # Window - # {}, # Frame - # ] - #}, { 'group-name': "numbers", 'group-x': 10, @@ -234,9 +221,20 @@ DEFAULT_LAYOUT = { ] } -KEYBOARD_SCALE = 1.25 -HAND_SCALE = 1.4 -HAND_YOFFSET = -35 +class KeyboardImages: + def __init__(self): + self.width = 775 * 1.4 + self.height = 265 * 1.4 + + self.images = {} + + def load_images(self): + bundle_path = sugar.activity.activity.get_bundle_path() + path = os.path.join(bundle_path, 'images') + for filename in glob.iglob(path + '/*.svg'): + image = gtk.gdk.pixbuf_new_from_file_at_size(filename, self.width, self.height) + name = os.path.basename(filename) + self.images[name] = image class KeyboardData: def __init__(self): @@ -375,7 +373,7 @@ class KeyboardData: # Find list of key combinations that can generate this keyval. entries = self.keymap.get_entries_for_keyval(keyval) if not entries: - return None, 0, 0 + return None, 0, 0 keycode, group, level = entries[0] @@ -393,10 +391,11 @@ class KeyboardWidget(KeyboardData, gtk.DrawingArea): """A GTK widget which implements an interactive visual keyboard, with support for custom data driven layouts.""" - def __init__(self, root_window): + def __init__(self, image, root_window): KeyboardData.__init__(self) gtk.DrawingArea.__init__(self) + self.image = image self.root_window = root_window self.connect("expose-event", self._expose_cb) @@ -427,26 +426,6 @@ class KeyboardWidget(KeyboardData, gtk.DrawingArea): self.root_window.disconnect(self.key_press_cb_id) self.root_window.disconnect(self.key_release_cb_id) - def _load_image(self, name): - bundle_path = sugar.activity.activity.get_bundle_path() - filename = os.path.join(bundle_path, 'images', name) - - w = int(self.keys[0]['layout-width']*HAND_SCALE) - h = int(self.keys[0]['layout-height']*HAND_SCALE) - - return gtk.gdk.pixbuf_new_from_file_at_size(filename, w, h) - - def load_hand_images(self): - # Load stock SVG files. - self.lhand_home = self._load_image('OLPC_Lhand_HOMEROW.svg') - self.rhand_home = self._load_image('OLPC_Rhand_HOMEROW.svg') - self.lhand_shift = self._load_image('OLPC_Lhand_SHIFT.svg') - self.rhand_shift = self._load_image('OLPC_Rhand_SHIFT.svg') - - for key in self.keys: - if key['key-hand-image']: - key['key-hand-image-handle'] = self._load_image(key['key-hand-image']) - def _make_key_images(self): group = self.active_group @@ -501,13 +480,13 @@ class KeyboardWidget(KeyboardData, gtk.DrawingArea): pass def _expose_hands(self, gc): - lhand_image = self.lhand_home - rhand_image = self.rhand_home + lhand_image = self.image.images['OLPC_Lhand_HOMEROW.svg'] + rhand_image = self.image.images['OLPC_Rhand_HOMEROW.svg'] if self.hilite_letter: key, state, group = self.get_key_state_group_for_letter(self.hilite_letter) if key: - handle = key['key-hand-image-handle'] + handle = self.image.images[key['key-hand-image']] finger = key['key-finger'] # Assign the key image to the correct side. diff --git a/lessonscreen.py b/lessonscreen.py index 1d41d64..ef44297 100644 --- a/lessonscreen.py +++ b/lessonscreen.py @@ -44,10 +44,11 @@ DEFAULT_MEDALS = [ ] class LessonScreen(gtk.VBox): - def __init__(self, lesson, activity): + def __init__(self, lesson, keyboard_images, activity): gtk.VBox.__init__(self) self.lesson = lesson + self.keyboard_images = keyboard_images self.activity = activity # Build the user interface. @@ -123,9 +124,8 @@ class LessonScreen(gtk.VBox): frame = gtk.Frame() frame.add(self.lessonscroll) - self.keyboard = keyboard.KeyboardWidget(self.activity) - self.keyboard.set_layout(keyboard.DEFAULT_LAYOUT) - self.keyboard.load_hand_images() + self.keyboard = keyboard.KeyboardWidget(self.keyboard_images, self.activity) + self.keyboard.set_layout(keyboard.OLPC_LAYOUT) self.pack_start(hbox, False, False, 10) self.pack_start(frame, True, True) diff --git a/mainscreen.py b/mainscreen.py index fef569e..64b95bc 100644 --- a/mainscreen.py +++ b/mainscreen.py @@ -27,6 +27,7 @@ from sugar.graphics import * # Import activity modules. import lessonscreen, medalscreen, balloongame +import keyboard # Temporary SVGs of medals from Wikimedia Commons. # See the links below for licensing information. @@ -127,6 +128,10 @@ class MainScreen(gtk.VBox): # Sort by the 'order' field. self.lessons.sort(lambda x, y: x.get('order', 0) - y.get('order', 0)) + + # Load all the keyboard images. + self.keyboard_images = keyboard.KeyboardImages() + self.keyboard_images.load_images() lessonscrollbox = gtk.HBox() lessonscrollbox.set_spacing(10) @@ -150,7 +155,6 @@ class MainScreen(gtk.VBox): finally: fd.close() - def get_next_lesson(self): """Returns the index of the first lesson without a medal.""" index = len(self.lessons)-1 @@ -262,7 +266,7 @@ class MainScreen(gtk.VBox): self.activity.push_screen(balloongame.BalloonGame(self.visible_lesson, self.activity)) else: reload(lessonscreen) - self.activity.push_screen(lessonscreen.LessonScreen(self.visible_lesson, self.activity)) + self.activity.push_screen(lessonscreen.LessonScreen(self.visible_lesson, self.keyboard_images, self.activity)) def medal_clicked_cb(self, widget): if self.activity.data['medals'].has_key(self.visible_lesson['name']): |