Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/keyboard.py
diff options
context:
space:
mode:
authorWade Brainerd <wadetb@gmail.com>2008-11-10 21:07:07 (GMT)
committer Wade Brainerd <wadetb@gmail.com>2008-11-10 21:07:07 (GMT)
commitca20fcdf3c2a3583227563531da8574fea993ccc (patch)
treea0ee2199ad819648c9bc10e8992caa1b0b2ded30 /keyboard.py
parent8056a0e856c458c4e57dc86bdc2f373a8f1be4a8 (diff)
Bug fixes, slight cleanup of keyboard module.
Diffstat (limited to 'keyboard.py')
-rw-r--r--keyboard.py111
1 files changed, 54 insertions, 57 deletions
diff --git a/keyboard.py b/keyboard.py
index d70024c..3dd4838 100644
--- a/keyboard.py
+++ b/keyboard.py
@@ -4,6 +4,55 @@ import pygtk
pygtk.require('2.0')
import gtk
+# List of all possible properties in the keyboard layout description.
+#
+# Keyboard Layouts use a property inheritance scheme similar to CSS (cascading style sheets):
+# - Keys inherit properties from their groups, if not explicitly set.
+# - Groups similarly inherit properties from the layout.
+# - The layout inherits properties from defaults values defined below.
+#
+# Therefore it is possible to set any property once in the Layout, and have
+# it automatically filter down to all Keys, yet still be able to override it
+# individually per key.
+KEY_PROPS = [
+ # Name of the layout.
+ { 'name': 'layout-name', 'default': '' },
+
+ # Source dimensions of the layout.
+ # This is the coordinate system that key sizes and coordinates are defined in.
+ # It can be any units, for example inches, millimeters, percentages, etc.
+ { 'name': 'layout-width', 'default': 100 },
+ { 'name': 'layout-height', 'default': 100 },
+
+ # Name of the group.
+ { 'name': 'group-name', 'default': '' },
+
+ # Position of group in layout coordinates.
+ { 'name': 'group-x', 'default': 0 },
+ { 'name': 'group-y', 'default': 0 },
+
+ # Layout algorithm for the group.
+ # Possibilities are: 'horizontal', 'vertical', 'custom'.
+ { 'name': 'group-layout', 'default': 'custom' },
+
+ # Position of key in layout coordinates. Used by 'custom' layout algorithm.
+ { 'name': 'key-x', 'default': 0 },
+ { 'name': 'key-y', 'default': 0 },
+
+ # Dimensions of a key in the layout coordinates.
+ { 'name': 'key-width', 'default': 0 },
+ { 'name': 'key-height', 'default': 0 },
+
+ # Gap between keys. Used by 'horizontal' and 'verical' layout algorithms.
+ { 'name': 'key-gap', 'default': 0 },
+
+ # Character generated by the key, when no modifier keys are pressed.
+ { 'name': 'key-normal', 'default': '' },
+
+ # Character generated by the key with shift pressed.
+ { 'name': 'key-shift', 'default': '' },
+]
+
# This is an example keyboard layout.
#
# The keyboard layout is described by the following data structure. The structure
@@ -12,12 +61,9 @@ import gtk
# related keys (e.g. nearby each other on the keyboard with similar properties)
# together.
#
-# Entirely new keyboard layouts can be created just by modifying the following values,
-# without changing the code.
-#
-# Further, the property scheme allows for an expandable feature set with good support
-# for backwards compatibility.
-default_layout = {
+# 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",
'layout-width': 555,
@@ -162,55 +208,6 @@ class Keyboard(gtk.DrawingArea):
"""A GTK widget which provides an interactive visual keyboard, with support
for data driven custom layouts."""
- # List of all possible properties in the keyboard layout description.
- #
- # Keyboard Layouts use a property inheritance scheme similar to CSS (cascading style sheets):
- # - Keys inherit properties from their groups, if not explicitly set.
- # - Groups similarly inherit properties from the layout.
- # - The layout inherits properties from defaults values defined below.
- #
- # Therefore it is possible to set any property once in the Layout, and have
- # it automatically filter down to all Keys, yet still be able to override it
- # individually per key.
- key_props = [
- # Name of the layout.
- { 'name': 'layout-name', 'default': '' },
-
- # Source dimensions of the layout.
- # This is the coordinate system that key sizes and coordinates are defined in.
- # It can be any units, for example inches, millimeters, percentages, etc.
- { 'name': 'layout-width', 'default': 100 },
- { 'name': 'layout-height', 'default': 100 },
-
- # Name of the group.
- { 'name': 'group-name', 'default': '' },
-
- # Position of group in layout coordinates.
- { 'name': 'group-x', 'default': 0 },
- { 'name': 'group-y', 'default': 0 },
-
- # Layout algorithm for the group.
- # Possibilities are: 'horizontal', 'vertical', 'custom'.
- { 'name': 'group-layout', 'default': 'custom' },
-
- # Position of key in layout coordinates. Used by 'custom' layout algorithm.
- { 'name': 'key-x', 'default': 0 },
- { 'name': 'key-y', 'default': 0 },
-
- # Dimensions of a key in the layout coordinates.
- { 'name': 'key-width', 'default': 0 },
- { 'name': 'key-height', 'default': 0 },
-
- # Gap between keys. Used by 'horizontal' and 'verical' layout algorithms.
- { 'name': 'key-gap', 'default': 0 },
-
- # Character generated by the key, when no modifier keys are pressed.
- { 'name': 'key-normal', 'default': '' },
-
- # Character generated by the key with shift pressed.
- { 'name': 'key-shift', 'default': '' },
- ]
-
def __init__(self):
gtk.DrawingArea.__init__(self)
@@ -245,7 +242,7 @@ class Keyboard(gtk.DrawingArea):
# Inherit undefined properties from group, layout and
# defaults, in that order.
- for p in Keyboard.key_props:
+ for p in KEY_PROPS:
pname = p['name']
if not props.has_key(pname):
if g.has_key(pname):
@@ -356,7 +353,7 @@ if __name__ == "__main__":
window.connect("destroy", lambda w: gtk.main_quit())
k = Keyboard()
- k.set_layout(default_layout)
+ k.set_layout(DEFAULT_LAYOUT)
k.show()
window.add(k)