summaryrefslogtreecommitdiff
path: root/src/keyboard.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/keyboard.py')
-rw-r--r--src/keyboard.py145
1 files changed, 67 insertions, 78 deletions
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()