summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/caribou.py2
-rw-r--r--src/keyboard.py145
-rw-r--r--src/keyboardcommon.py22
-rw-r--r--src/qwerty.py29
4 files changed, 119 insertions, 79 deletions
diff --git a/src/caribou.py b/src/caribou.py
index 4db7a17..e4d9cbe 100644
--- a/src/caribou.py
+++ b/src/caribou.py
@@ -141,7 +141,7 @@ if __name__ == "__main__":
pyatspi.Registry.registerKeystrokeListener(test.on_key_down, mask = None, kind = (pyatspi.KEY_PRESSED_EVENT,))
# TODO: move text entry detection to its own file
- cp = keyboard.CaribouKeyboard()
+ cp = keyboard.CaribouWindow()
cp.hide_all()
gtk.main()
diff --git a/src/keyboard.py b/src/keyboard.py
index ffe7207..6f059bf 100644
--- a/src/keyboard.py
+++ b/src/keyboard.py
@@ -5,95 +5,84 @@ import gobject
import gtk.gdk as gdk
import pango
import virtkey
-
-
-# from OnBoard.utils.py
-keysyms = {"space" : 0xff80,
- "insert" : 0xff9e,
- "home" : 0xff50,
- "page_up" : 0xff55,
- "page_down" : 0xff56,
- "end" : 0xff57,
- "delete" : 0xff9f,
- "return" : 0xff0d,
- "backspace" : 0xff08,
- "left" : 0xff51,
- "up" : 0xff52,
- "right" : 0xff53,
- "down" : 0xff54,}
-
-# TODO add horizonal keysize - will be able to specify a mulitplier
-# TODO add key colour
-
-backspace = ("⌫", keysyms["backspace"])
-control = (".?12", keysyms["space"]) #TODO not implemented
-
-# key format ("label", keysym, size)
-layout = ( ("q", "w", "e", "r", "t", "y", "u", "i", "o", "p"),
- ("a", "s", "d", "f", "g", "h", "j", "k", "l", backspace ),
- ("z", "x", "c", "v", "b", "n", "m", " ", control, "⇧") )
-
-# TODO add keyboard layers
-#layout2 = ( ("Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"),
-# ("A", "S", "D", "F", "G", "H", "J", "K", "L", backspace ),
-# ("Z", "X", "C", "V", "B", "N", "M", " ", " ", "⇧") )
+import qwerty
class CaribouPredicitionArea(gtk.HBox):
pass
-class CaribouKey(gtk.Button):
- __gtype_name__ = "CaribouKey"
-
- def __init__(self, key, vk):
- if isinstance(key, tuple):
- label = key[0]
- keysym = key[1]
- self.__press_key = vk.press_keysym
- self.__release_key = vk.release_keysym
- elif isinstance(key, str):
- label = key
- keysym = ord(key.decode('utf-8'))
- self.__press_key = vk.press_unicode
- self.__release_key = vk.release_unicode
- else:
- pass #TODO throw error here
- gtk.Button.__init__(self, label)
- #self.set_relief(gtk.RELIEF_NONE)
- self.connect("clicked", self.__on_click, keysym)
-
- def __on_click(self, widget, data):
- self.__press_key(data)
- self.__release_key(data)
-
-gobject.type_register(CaribouKey)
-
-class CaribouKeyboard(gtk.VBox):
- __gtype_name__ = "CaribouKeyboard"
+class CaribouKeyboard(gtk.Frame):
+
+ def __init__(self):
+ gtk.Frame.__init__(self)
+ self.set_shadow_type(gtk.SHADOW_NONE)
+
+ self._layouts = []
+ self._vk = virtkey.virtkey()
+
+ for layout in qwerty.keyboard:
+ layoutvbox = gtk.VBox(homogeneous=True)
+ for row in layout:
+ rowhbox = gtk.HBox(homogeneous=True)
+ for key in row:
+ # check if the key is a simple str or a key defined by a tuple
+ if isinstance(key, str):
+ button = gtk.Button(key)
+ char = ord(key.decode('utf-8'))
+ button.connect("clicked", lambda w, d: self.__send_unicode(d), char)
+ elif isinstance(key, tuple):
+ button = gtk.Button(key[0])
+ # check if this key is a layout switch key or not
+ if isinstance(key[1], str):
+ # switch layout key
+ button.connect("clicked", lambda w, d: self.__switch_layout(d), key[0])
+ else:
+ # regular key
+ button.connect("clicked", lambda w, d: self.__send_keysym(d), key[1])
+ else:
+ pass #TODO throw error here
+
+ rowhbox.pack_start(button, expand=False, fill=True)
+
+ layoutvbox.pack_start(rowhbox, expand=False, fill=False)
+ self._layouts.append(layoutvbox)
+
+ # add the first layer and make it visible
+ self.add(self._layouts[0])
+ self.show_all()
+
+ def __send_unicode(self, char):
+ self._vk.press_unicode(char)
+ self._vk.release_unicode(char)
+
+ def __send_keysym(self, keysym):
+ self._vk.press_keysym(keysym)
+ self._vk.release_keysym(keysym)
+
+ def __switch_layout(self, data):
+ if data == "⇧":
+ self.remove(self._layouts[0])
+ self.add(self._layouts[1])
+ self.show_all()
+ elif data == "⇩":
+ self.remove(self._layouts[1])
+ self.add(self._layouts[0])
+ self.show_all()
+
+gobject.type_register(CaribouKeyboard)
+
+class CaribouWindow(gtk.VBox):
+ __gtype_name__ = "CaribouWindow"
def __init__(self):
- super(CaribouKeyboard, self).__init__()
- self.set_name("CaribouKeyboard")
+ super(CaribouWindow, self).__init__()
+ self.set_name("CaribouWindow")
self.__toplevel = gtk.Window(gtk.WINDOW_POPUP)
self.__toplevel.add(self)
self.__toplevel.connect("size-allocate", lambda w, a: self.__check_position())
-
self.__cursor_location = (0, 0)
+ self.pack_start(CaribouKeyboard())
- self.__build_keyboard()
-
-
- #TODO: validate keyboard
- def __build_keyboard(self):
- vk = virtkey.virtkey()
- for row in layout:
- rowhbox = gtk.HBox(homogeneous=True)
- for keylabel in row:
- key = CaribouKey(keylabel, vk)
- rowhbox.pack_start(key, expand=False, fill=True)
- self.pack_start(rowhbox, expand=False, fill=False)
-
- #TODO understand
def set_cursor_location(self, x, y):
#print "----> SET CURSOR LOCATION"
self.__cursor_location = (x, y)
@@ -136,7 +125,7 @@ class CaribouKeyboard(gtk.VBox):
self.__toplevel.move(x, y)
if __name__ == "__main__":
- ckbd = CaribouKeyboard()
+ ckbd = CaribouWindow()
ckbd.show_all()
gtk.main()
diff --git a/src/keyboardcommon.py b/src/keyboardcommon.py
new file mode 100644
index 0000000..7d8ce60
--- /dev/null
+++ b/src/keyboardcommon.py
@@ -0,0 +1,22 @@
+# from OnBoard.utils.py
+keysyms = {"space" : 0xff80,
+ "insert" : 0xff9e,
+ "home" : 0xff50,
+ "page_up" : 0xff55,
+ "page_down" : 0xff56,
+ "end" : 0xff57,
+ "delete" : 0xff9f,
+ "return" : 0xff0d,
+ "backspace" : 0xff08,
+ "left" : 0xff51,
+ "up" : 0xff52,
+ "right" : 0xff53,
+ "down" : 0xff54 }
+
+
+global layer1
+global layer2
+layer3 = None
+layer4 = None
+layer5 = None
+
diff --git a/src/qwerty.py b/src/qwerty.py
new file mode 100644
index 0000000..ad642a5
--- /dev/null
+++ b/src/qwerty.py
@@ -0,0 +1,29 @@
+# -*- coding: UTF-8 -*-
+
+import keyboardcommon
+
+# TODO add horizontal keysize - will be able to specify a mulitplier
+# TODO add key colour
+# TODO add noop keysym
+
+# key format ("label", keysym)
+backspace = ("⌫", keyboardcommon.keysyms["backspace"])
+# TODO implement numbers and contol caracters
+control = (".?12", keyboardcommon.keysyms["space"])
+
+# define keys to switch layers here
+# TODO find a better way to specify which layer to switch to
+# TODO add ability switch back to previous layer after x keystrokes
+shift_up = ("⇧", "layer2")
+shift_down = ("⇩", "layer1")
+
+layout1 = ( ("q", "w", "e", "r", "t", "y", "u", "i", "o", "p"),
+ ("a", "s", "d", "f", "g", "h", "j", "k", "l", backspace ),
+ ("z", "x", "c", "v", "b", "n", "m", " ", control, shift_up) )
+
+layout2 = ( ("Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"),
+ ("A", "S", "D", "F", "G", "H", "J", "K", "L", backspace),
+ ("Z", "X", "C", "V", "B", "N", "M", " ", control, shift_down) )
+
+
+keyboard = ( layout1, layout2 )