diff options
-rw-r--r-- | activity/activity.info | 2 | ||||
-rw-r--r-- | keyboard.py | 43 | ||||
-rw-r--r-- | lessonscreen.py | 9 | ||||
-rw-r--r-- | mainscreen.py | 4 |
4 files changed, 34 insertions, 24 deletions
diff --git a/activity/activity.info b/activity/activity.info index 3e03a06..eedd6a6 100644 --- a/activity/activity.info +++ b/activity/activity.info @@ -1,6 +1,6 @@ [Activity] name = Typing Turtle -activity_version = 12 +activity_version = 13 host_version = 1 service_name = org.laptop.community.TypingTurtle icon = Activity-typingturtle diff --git a/keyboard.py b/keyboard.py index c4bbfb5..a708b14 100644 --- a/keyboard.py +++ b/keyboard.py @@ -24,9 +24,7 @@ import os, glob import pango # Tweaking variables. -KEYBOARD_SCALE = 1.25 -HAND_SCALE = 1.4 -HAND_YOFFSET = -35 +HAND_YOFFSET = -15 PARAGRAPH_CODE = u'\xb6' @@ -220,15 +218,15 @@ OLPC_LAYOUT = { } class KeyboardImages: - def __init__(self): - self.width = int(775 * 1.4) - self.height = int(265 * 1.4) + def __init__(self, width, height): + self.width = width + self.height = height self.images = {} def load_images(self): for filename in glob.iglob('images/OLPC_*.svg'): - image = gtk.gdk.pixbuf_new_from_file_at_size(filename, self.width, self.height) + image = gtk.gdk.pixbuf_new_from_file_at_scale(filename, self.width, self.height, False) name = os.path.basename(filename) self.images[name] = image @@ -241,9 +239,6 @@ class KeyboardData: # Access the current GTK keymap. self.keymap = gtk.gdk.keymap_get_default() - # Layout scaling factor. - self.scale = KEYBOARD_SCALE - def set_layout(self, layout): self._build_key_list(layout) self._layout_keys() @@ -321,13 +316,6 @@ class KeyboardData: else: # k['group-layout'] == 'custom' or unsupported pass - # Apply the scale. - for k in self.keys: - k['key-x'] = int(k['key-x'] * self.scale) - k['key-y'] = int(k['key-y'] * self.scale) - k['key-width'] = int(k['key-width'] * self.scale) - k['key-height'] = int(k['key-height'] * self.scale) - def find_key_by_label(self, label): for k in self.keys: if k['key-label'] == label: @@ -389,6 +377,9 @@ class KeyboardWidget(KeyboardData, gtk.DrawingArea): self.image = image self.root_window = root_window + # Match the image cache in dimensions. + self.set_size_request(image.width, image.height) + self.connect("expose-event", self._expose_cb) # Active language group and modifier state. @@ -420,6 +411,16 @@ class KeyboardWidget(KeyboardData, gtk.DrawingArea): def set_layout(self, layout): """Sets the keyboard's layout from a layout description.""" KeyboardData.set_layout(self, layout) + + # Scale the keyboard to match the images. + width_scale = float(self.image.width) / self.keys[0]['layout-width'] + height_scale = float(self.image.height) / self.keys[0]['layout-height'] + for k in self.keys: + k['key-x'] = int(k['key-x'] * width_scale) + k['key-y'] = int(k['key-y'] * height_scale) + k['key-width'] = int(k['key-width'] * width_scale) + k['key-height'] = int(k['key-height'] * height_scale) + self._make_key_images() def _make_key_images(self): @@ -502,8 +503,8 @@ class KeyboardWidget(KeyboardData, gtk.DrawingArea): # TODO: Do something about ALTGR. bounds = self.get_allocation() - screen_x = int(bounds.width-self.keys[0]['layout-width']*self.scale)/2 - screen_y = int(bounds.height-self.keys[0]['layout-height']*self.scale)/2 + screen_x = int(bounds.width-self.image.width)/2 + screen_y = int(bounds.height-self.image.height)/2 self.window.draw_pixbuf(gc, lhand_image, 0, 0, screen_x, screen_y + HAND_YOFFSET) self.window.draw_pixbuf(gc, rhand_image, 0, 0, screen_x, screen_y + HAND_YOFFSET) @@ -512,8 +513,8 @@ class KeyboardWidget(KeyboardData, gtk.DrawingArea): gc = self.window.new_gc() bounds = self.get_allocation() - screen_x = int(bounds.width-self.keys[0]['layout-width']*self.scale)/2 - screen_y = int(bounds.height-self.keys[0]['layout-height']*self.scale)/2 + screen_x = int(bounds.width-self.image.width)/2 + screen_y = int(bounds.height-self.image.height)/2 # Draw the keys. for k in self.keys: diff --git a/lessonscreen.py b/lessonscreen.py index ef44297..c2a00b1 100644 --- a/lessonscreen.py +++ b/lessonscreen.py @@ -129,7 +129,7 @@ class LessonScreen(gtk.VBox): self.pack_start(hbox, False, False, 10) self.pack_start(frame, True, True) - self.pack_start(self.keyboard, True) + self.pack_start(self.keyboard, False) # Connect keyboard grabbing and releasing callbacks. self.connect('realize', self.realize_cb) @@ -140,15 +140,22 @@ class LessonScreen(gtk.VBox): self.timer_id = None self.begin_lesson() + + # Used to suppress warning beeps on keypresses. + def keynav_failed_cb(self, widget, dir): + print "keynav failed" + return False def realize_cb(self, widget): self.activity.add_events(gtk.gdk.KEY_PRESS_MASK|gtk.gdk.KEY_RELEASE_MASK) self.key_press_cb_id = self.activity.connect('key-press-event', self.key_cb) self.key_release_cb_id = self.activity.connect('key-release-event', self.key_cb) + self.keynav_failed_cb_id = self.activity.connect('keynav-failed', self.keynav_failed_cb) def unrealize_cb(self, widget): self.activity.disconnect(self.key_press_cb_id) self.activity.disconnect(self.key_release_cb_id) + self.activity.disconnect(self.keynav_failed_cb_id) def start_timer(self): self.start_time = time.time() diff --git a/mainscreen.py b/mainscreen.py index 1c82f3e..6c3735a 100644 --- a/mainscreen.py +++ b/mainscreen.py @@ -90,7 +90,9 @@ class MainScreen(gtk.VBox): self.lessons.sort(lambda x, y: x.get('order', 0) - y.get('order', 0)) # Load all the keyboard images. - self.keyboard_images = keyboard.KeyboardImages() + width = int(gtk.gdk.screen_width()) + height = int(gtk.gdk.screen_height()*0.4) + self.keyboard_images = keyboard.KeyboardImages(width, height) self.keyboard_images.load_images() navbox = gtk.HBox() |