diff options
-rw-r--r-- | src/keyboard.py | 40 | ||||
-rw-r--r-- | src/qwerty.py | 49 |
2 files changed, 58 insertions, 31 deletions
diff --git a/src/keyboard.py b/src/keyboard.py index fe62999..a44b057 100644 --- a/src/keyboard.py +++ b/src/keyboard.py @@ -10,17 +10,22 @@ import qwerty class CaribouPredicitionArea(gtk.HBox): pass +# TODO validate keyboard by creating this object and catching exception class CaribouKeyboard(gtk.Frame): - def __init__(self): + def __init__(self, keyboard): gtk.Frame.__init__(self) self.set_shadow_type(gtk.SHADOW_NONE) + # FIXME use references instead of this?? self._layouts = [] self._vk = virtkey.virtkey() - for layout in qwerty.keyboard: + switch_buttons = [] + for layout in keyboard.layouts: layoutvbox = gtk.VBox(homogeneous=True) + layoutvbox.set_name(layout) + layout = getattr(keyboard, layout) for row in layout: rowhbox = gtk.HBox(homogeneous=True) for key in row: @@ -34,7 +39,9 @@ class CaribouKeyboard(gtk.Frame): # check if this key is a layout switch key or not if isinstance(key[1], str): # switch layout key - button.connect("clicked", self.__change_layout, key[1]) + # set layer name on button and save to process later + button.set_name(key[1]) + switch_buttons.append(button) else: # regular key button.connect("clicked", self.__send_keysym, key[1]) @@ -44,8 +51,21 @@ class CaribouKeyboard(gtk.Frame): rowhbox.pack_start(button, expand=False, fill=True) layoutvbox.pack_start(rowhbox, expand=False, fill=False) + self._layouts.append(layoutvbox) + for button in switch_buttons: + print + for layout in self._layouts: + print "button", button.get_name() + print "layer", layout.get_name() + if button.get_name() == layout.get_name(): + button.connect("clicked", self.__change_layout, layout) + button.set_name("") + break + else: + print "ERROR" # TODO throw exception + # add the first layer and make it visible self.add(self._layouts[0]) self.show_all() @@ -59,15 +79,9 @@ class CaribouKeyboard(gtk.Frame): self._vk.release_keysym(data) def __change_layout(self, widget, data): - label = widget.get_label() - if label == "⇧": - self.remove(self._layouts[0]) - self.add(self._layouts[1]) - self.show_all() - elif label == "⇩": - self.remove(self._layouts[1]) - self.add(self._layouts[0]) - self.show_all() + self.remove(self.get_child()) + self.add(data) + self.show_all() gobject.type_register(CaribouKeyboard) @@ -82,7 +96,7 @@ class CaribouWindow(gtk.VBox): 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.pack_start(CaribouKeyboard(qwerty)) def set_cursor_location(self, x, y): #print "----> SET CURSOR LOCATION" diff --git a/src/qwerty.py b/src/qwerty.py index ad642a5..6831cff 100644 --- a/src/qwerty.py +++ b/src/qwerty.py @@ -5,25 +5,38 @@ import keyboardcommon # TODO add horizontal keysize - will be able to specify a mulitplier # TODO add key colour # TODO add noop keysym +# TODO add ability switch back to previous layer after x keystrokes +# TODO ensure keyboard doesn't change size when changing layers +# TODO finish numbers and punctuation layout # key format ("label", keysym) -backspace = ("⌫", keyboardcommon.keysyms["backspace"]) -# TODO implement numbers and contol caracters -control = (".?12", keyboardcommon.keysyms["space"]) +bs = ("⌫", keyboardcommon.keysyms["backspace"]) +# return +rt = ("rtn", keyboardcommon.keysyms["return"]) # 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 ) +# shift up +su = ("⇧", "uppercase") +# shift down +sd = ("⇩", "lowercase") +# number and punctuation +np = (".?12", "num_punct") +# letters +lt = ("abc", "lowercase") + +# keyboard layouts - put a single utf-8 character or a tuple defined above +lowercase = ( ("?", "q", "w", "e", "r", "t", "y", "u", "i", "o", "p"), + ( np, "a", "s", "d", "f", "g", "h", "j", "k", "l", bs), + ( su, "z", "x", "c", "v", "b", "n", "m", ".", " ", rt) ) + +uppercase = ( ("?", "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"), + ( np, "A", "S", "D", "F", "G", "H", "J", "K", "L", bs), + ( sd, "Z", "X", "C", "V", "B", "N", "M", ".", " ", rt) ) + +num_punct = ( ("!", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"), + ( lt, "@", "$", "/", "+", "-", " ", "\"", ",", ".", bs), + ("'", "(", ")", ";", ":", " ", " ", " ", " ", " ", rt) ) + +# the layout that appears in position 0 will be visible +# when the keyboard is first created +layouts = ( "lowercase", "uppercase", "num_punct" ) |