Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWade Brainerd <wadetb@gmail.com>2008-12-16 03:30:22 (GMT)
committer Wade Brainerd <wadetb@gmail.com>2008-12-16 03:30:22 (GMT)
commitf9ff467b4000ce3e509e0a2824d522065ba2832f (patch)
tree2afe5587eca905b6a551edb5ecbb2159a0fdcf18
parent716b1a7e21d5afcc06ade6e3f6d664aa3196ecd1 (diff)
WIP on keyboard overlays.
-rwxr-xr-ximages/r_homerow.svg21
-rw-r--r--keyboard.py82
2 files changed, 74 insertions, 29 deletions
diff --git a/images/r_homerow.svg b/images/r_homerow.svg
new file mode 100755
index 0000000..66acd42
--- /dev/null
+++ b/images/r_homerow.svg
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Generator: Adobe Illustrator 13.0.2, SVG Export Plug-In . SVG Version: 6.00 Build 14948) -->
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
+<svg version="1.0" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
+ width="987.274px" height="1619.987px" viewBox="0 0 987.274 1619.987" enable-background="new 0 0 987.274 1619.987"
+ xml:space="preserve">
+<path fill="none" stroke="#000000" stroke-width="0.5" stroke-linecap="round" stroke-linejoin="round" d="M564.638,1572.356
+ c-20.131-151.191-58.518-299.367-69.832-451.723c-4.541-61.139-20.056-77.17-72.176-103.727
+ c-58.36-29.736-107.368-91.171-161.106-129.753c-55.319-39.717-85.746-90.433-122.6-146.227
+ C106.517,691.853,87.012,629.111,53.42,584.11C35.162,559.651-11.631,481.239,3.061,452.654
+ c25.577-49.707,111.793,0.158,133.86,24.371c64.295,70.547,70.284,152.069,157.089,199.44c8.545,4.663-9.014-118.235-11.692-131.273
+ c-14.503-70.591-34.967-139.859-55.289-208.942c-18.213-61.913-43.449-124.849-53.674-188.737
+ c-8.294-51.823,16.741-129.36,79.813-74.817c50.884,44.003,86.21,353.286,172.488,345.575
+ c21.054-74.923-2.098-161.041-15.168-235.526c-7.948-45.297-50.25-196.176,40.983-181.492
+ c64.797,10.428,66.693,104.694,78.904,153.955c7.66,30.903,31.077,223.268,61.601,228.504
+ c64.418-86.787-52.426-282.233,40.399-355.982c85.646-68.046,85.365,125.045,86.547,158.913
+ c1.41,40.439-16.075,201.321,32.894,220.829c57.853-90.469,0.957-214.106,48.11-310.045c21.765-44.282,84.195-50.96,95.019,4.542
+ c8.84,45.31-10.969,110.773-14.85,157.326c-10.18,122.136,11.189,235.617,16.438,356.979
+ c5.678,131.335-21.525,268.258,4.545,395.594c26.381,128.846,42.131,259.675,60.357,389.854
+ c11.896,84.961,67.592,176.936-36.132,195.151C850.704,1609.973,613.405,1652.12,564.638,1572.356"/>
+</svg>
diff --git a/keyboard.py b/keyboard.py
index 1eb340f..6e93a48 100644
--- a/keyboard.py
+++ b/keyboard.py
@@ -19,6 +19,9 @@
import pygtk
pygtk.require('2.0')
import gtk
+import cairo
+import os, sugar.activity.activity
+import rsvg
# List of all key properties in the keyboard layout description.
#
@@ -246,7 +249,7 @@ class Keyboard(gtk.EventBox):
self.area = gtk.DrawingArea()
self.area.connect("expose-event", self._expose_cb)
self.add(self.area)
-
+
# Initialize the default cairo context to None.
cr = None
@@ -265,6 +268,11 @@ class Keyboard(gtk.EventBox):
self.shift_down = False
+ # Load SVG files.
+ bundle_path = sugar.activity.activity.get_bundle_path()
+ #self.rhand_svg = gtk.gdk.pixbuf_new_from_file_at_size(os.path.join(bundle_path, 'images', 'r_homerow.svg'), 775, 300)
+ self.rhand_svg = rsvg.Handle(os.path.join(bundle_path, 'images', 'r_homerow.svg'))
+
# Connect keyboard grabbing and releasing callbacks.
self.area.connect('realize', self._realize_cb)
self.area.connect('unrealize', self._unrealize_cb)
@@ -375,23 +383,23 @@ class Keyboard(gtk.EventBox):
"""Applies the scaling factor to the layout given the current
allocation."""
bounds = self.get_allocation()
-
+
+ # This calculates a ratio from layout coordinates to the DrawingArea's
+ # dimensions. This ratio allows the layout coordinates to be *anything* -
+ # inches, millimeters, percentage, whatever. They just have to be
+ # relative to layout-width and layout-height.
+ ratio_x = 100 * bounds.width / self.keys[0].props['layout-width']
+ ratio_y = 100 * bounds.height / self.keys[0].props['layout-height']
+
+ # Pick the smaller ratio to fit while preserving aspect ratio.
+ self.screen_ratio = min(ratio_x, ratio_y)
+
for k in self.keys:
- # This calculates a ratio from layout coordinates to the DrawingArea's
- # dimensions. This ratio allows the layout coordinates to be *anything* -
- # inches, millimeters, percentage, whatever. They just have to be
- # relative to layout-width and layout-height.
- ratio_x = 100 * bounds.width / k.props['layout-width']
- ratio_y = 100 * bounds.height / k.props['layout-height']
-
- # Pick the smaller ratio to fit while preserving aspect ratio.
- ratio = min(ratio_x, ratio_y)
-
# Make sure the final coordinates are integers, for the drawing routines.
- k.screen_x = int(k.x * ratio / 100)
- k.screen_y = int(k.y * ratio / 100)
- k.screen_width = int(k.width * ratio / 100)
- k.screen_height = int(k.height * ratio / 100)
+ k.screen_x = int(k.x * self.screen_ratio / 100)
+ k.screen_y = int(k.y * self.screen_ratio / 100)
+ k.screen_width = int(k.width * self.screen_ratio / 100)
+ k.screen_height = int(k.height * self.screen_ratio / 100)
def _expose_key(self, k, cr=None):
# Create cairo context if need be.
@@ -399,14 +407,14 @@ class Keyboard(gtk.EventBox):
if not self.area.window:
return
cr = self.area.window.cairo_create()
-
+
cr.save()
-
+
x1 = k.screen_x
y1 = k.screen_y
x2 = k.screen_x + k.screen_width
y2 = k.screen_y + k.screen_height
-
+
# Outline rounded box.
corner = 5
cr.move_to(x1 + corner, y1)
@@ -418,7 +426,7 @@ class Keyboard(gtk.EventBox):
cr.line_to(x1, y2 - corner)
cr.line_to(x1, y1 + corner)
cr.close_path()
-
+
if k.pressed:
cr.set_source_rgb(1.0, 0.6, 0.6)
elif k.hilite:
@@ -426,12 +434,12 @@ class Keyboard(gtk.EventBox):
else:
cr.set_source_rgb(1.0, 1.0, 1.0)
cr.fill_preserve()
-
+
cr.set_source_rgb(0.1, 0.1, 0.1)
cr.stroke_preserve()
-
+
cr.clip()
-
+
# Inner text.
text = ''
if k.props['key-label']:
@@ -445,28 +453,44 @@ class Keyboard(gtk.EventBox):
text = unichr(key).encode('utf-8')
except:
pass
-
+
cr.set_font_size(16)
x_bearing, y_bearing, width, height = cr.text_extents(text)[:4]
-
+
cr.move_to(x1+8 - x_bearing, y2-8 - height - y_bearing)
cr.show_text(text)
-
+
cr.restore()
def _expose_cb(self, area, event):
# Update layout given widget size.
self._update_screen_layout()
-
+
# Draw the keys.
cr = self.area.window.cairo_create()
-
+
cr.rectangle(event.area.x, event.area.y, event.area.width, event.area.height)
cr.clip()
-
+
for k in self.keys:
self._expose_key(k, cr)
+
+ # Render overlay images.
+ ratio = self.keys[0].props['layout-width'] / 3146.0
+ ratio = self.screen_ratio / 100.0 * ratio
+
+ cr.save()
+ cr.scale(ratio, ratio)
+ cr.translate(1350, 625)
+ self.rhand_svg.render_cairo(cr)
+ cr.restore()
+ cr.save()
+ cr.scale(-ratio, ratio)
+ cr.translate(-100, 625)
+ self.rhand_svg.render_cairo(cr)
+ cr.restore()
+
return True
def _key_press_release_cb(self, widget, event):