[caribou/geometry] Do expected level transitions.



commit 57632a57fbf4fd8ea25799e56f862af6f462c7e5
Author: Eitan Isaacson <eitan monotonous org>
Date:   Sun Apr 24 12:49:09 2011 -0700

    Do expected level transitions.

 caribou/ui/keyboard.py        |   27 ++++++++++++++++++---------
 data/layouts/natural/ara.json |    7 +++++--
 data/layouts/natural/il.json  |    7 +++++--
 data/layouts/natural/us.json  |   10 +++++++---
 4 files changed, 35 insertions(+), 16 deletions(-)
---
diff --git a/caribou/ui/keyboard.py b/caribou/ui/keyboard.py
index 9e7f21b..60c9ae1 100644
--- a/caribou/ui/keyboard.py
+++ b/caribou/ui/keyboard.py
@@ -148,7 +148,7 @@ class CaribouSubKeys(Gtk.Window):
         for key in keys:
             key.connect("clicked", self._on_key_clicked)
 
-        layout = KeyboardLayout("")
+        layout = KeyboardLayout(key.name, "subkeyboard")
         layout.add_row(keys)
         self.add(layout)
 
@@ -223,9 +223,10 @@ class ModifierKey(Gtk.ToggleButton, Key):
 class KeyboardLayout(Gtk.Grid):
     KEY_SPAN = 4
 
-    def __init__(self, name):
+    def __init__(self, name, mode):
         gobject.GObject.__init__(self)
         self.layout_name = name
+        self.mode = mode
         self.rows = []
         self.set_column_homogeneous(True)
         self.set_row_homogeneous(True)
@@ -338,7 +339,7 @@ class KbLayoutDeserializer(object):
             return None
         layouts_encoded = []
         for name, level in dictionary.items():
-            kb_layout = KeyboardLayout(name)
+            kb_layout = KeyboardLayout(name, level.get("mode", "locked"))
             rows_list = self._get_dict_value_as_list(level, 'rows')
             for row in rows_list:
                 keys = self._get_keys_from_list(row)
@@ -419,6 +420,9 @@ class CaribouKeyboard(Gtk.Notebook):
         for level in level_list:
             level.show()
             self.layouts[group][level.layout_name] = self.append_page(level, None)
+            if level.mode == "default":
+                self.layouts[group]["default"] = \
+                    self.layouts[group][level.layout_name]
             for row in level.rows:
                 for key in row:
                     self._connect_key_signals(key)
@@ -455,6 +459,9 @@ class CaribouKeyboard(Gtk.Notebook):
 
     def _released_normal_key(self, key):
         self.vk.keyval_release(key.keyval)
+        layout = self.get_nth_page(self.get_current_page())
+        if layout.mode == "latched":
+            self._switch_to_layout()
         while True:
             try:
                 mod = self.depressed_mods.pop()
@@ -463,11 +470,10 @@ class CaribouKeyboard(Gtk.Notebook):
             mod.set_active (False)
 
     def _pressed_layout_switcher_key(self, key):
-        _, group, variant = self.vk.get_current_group()
-        self._switch_to_layout('%s_%s' % (group, variant), key.toggle)
+        self._switch_to_layout(level=key.toggle)
 
     def _on_group_changed(self, vk, groupid, group, variant):
-        self._switch_to_default('%s_%s' % (group, variant))
+        self._switch_to_layout('%s_%s' % (group, variant))
 
     def _toggled_mask_key(self, key):
         if key.get_active():
@@ -490,19 +496,22 @@ class CaribouKeyboard(Gtk.Notebook):
         p.run()
         p.destroy()
 
-    def _switch_to_default(self, group):
+    def _switch_to_fallback(self, group):
         try:
             i = min(self.layouts[group].values())
         except KeyError:
             i = 0
         self.set_current_page(i)
 
-    def _switch_to_layout(self, group, level):
+    def _switch_to_layout(self, group=None, level="default"):
+        if group is None:
+            _, _group, _variant = self.vk.get_current_group()
+            group = '%s_%s' % (_group, _variant)
         if self.layouts.has_key(group):
             if self.layouts[group].has_key(level):
                 self.set_current_page(self.layouts[group][level])
                 return
-        self._switch_to_default(group)
+        self._switch_to_fallback(group)
 
     def get_current_layout(self):
         i = self.get_current_page()
diff --git a/data/layouts/natural/ara.json b/data/layouts/natural/ara.json
index ecea3a1..068554e 100644
--- a/data/layouts/natural/ara.json
+++ b/data/layouts/natural/ara.json
@@ -1,5 +1,6 @@
 {
    "level1" : {
+      "mode" : "default",
       "rows" : [
          [{"name" : "Arabic_dad"},
           {"name" : "Arabic_sad"},
@@ -39,6 +40,7 @@
       ]
    },
    "symbols1" : {
+      "mode" : "locked",
       "rows" : [
          [{"name" : "Arabic_1"},
           {"name" : "Arabic_2"},
@@ -71,13 +73,14 @@
           {"name" : "quotedbl"},
           {"name" : "bar"},
           {"name" : "numbersign"}],
-         [{"name" : "Caribou_Alpha", "width" : 2, "toggle" : "level1"},
+         [{"name" : "Caribou_Alpha", "width" : 2, "toggle" : "default"},
           {"name" : "Caribou_Emoticons"},
           {"name" : "space", "width" : 5},
           {"name" : "Caribou_Prefs", "margin_left" : 2}]
       ]
    },
    "symbols2" : {
+      "mode" : "locked",
       "rows" : [
          [{"name" : "Arabic_percent"},
           {"name" : "bracketleft"},
@@ -110,7 +113,7 @@
           {"name" : "quotedbl"},
           {"name" : "bar"},
           {"name" : "numbersign"}],
-         [{"name" : "Caribou_Alpha", "width" : 2, "toggle" : "level1"},
+         [{"name" : "Caribou_Alpha", "width" : 2, "toggle" : "default"},
           {"name" : "Caribou_Emoticons"},
           {"name" : "space", "width" : 5},
           {"name" : "Caribou_Prefs", "margin_left" : 2}]
diff --git a/data/layouts/natural/il.json b/data/layouts/natural/il.json
index 17f75c5..06f566f 100644
--- a/data/layouts/natural/il.json
+++ b/data/layouts/natural/il.json
@@ -1,5 +1,6 @@
 {
    "level1" : {
+      "mode" : "default",
       "rows" : [
          [{"name" : "period"},
           {"name" : "comma"},
@@ -39,6 +40,7 @@
       ]
    },
    "symbols1" : {
+      "mode" : "locked",
       "rows" : [
          [{"name" : "1"},
           {"name" : "2"},
@@ -71,13 +73,14 @@
           {"name" : "quotedbl"},
           {"name" : "bar"},
           {"name" : "numbersign"}],
-         [{"name" : "Caribou_Alpha", "width" : 2, "toggle" : "level1"},
+         [{"name" : "Caribou_Alpha", "width" : 2, "toggle" : "default"},
           {"name" : "Caribou_Emoticons"},
           {"name" : "space", "width" : 5},
           {"name" : "Caribou_Prefs", "margin_left" : 2}]
       ]
    },
    "symbols2" : {
+      "mode" : "locked",
       "rows" : [
          [{"name" : "percent"},
           {"name" : "bracketleft"},
@@ -110,7 +113,7 @@
           {"name" : "quotedbl"},
           {"name" : "bar"},
           {"name" : "numbersign"}],
-         [{"name" : "Caribou_Alpha", "width" : 2, "toggle" : "level1"},
+         [{"name" : "Caribou_Alpha", "width" : 2, "toggle" : "default"},
           {"name" : "Caribou_Emoticons"},
           {"name" : "space", "width" : 5},
           {"name" : "Caribou_Prefs", "margin_left" : 2}]
diff --git a/data/layouts/natural/us.json b/data/layouts/natural/us.json
index c3779c0..fbe2496 100644
--- a/data/layouts/natural/us.json
+++ b/data/layouts/natural/us.json
@@ -1,5 +1,6 @@
 {
    "level1" : {
+      "mode" : "default",
       "rows" : [
          [{"name" : "q"},
           {"name" : "w"},
@@ -64,6 +65,7 @@
       ]
    },
    "level2" : {
+      "mode" : "latched",
       "rows" : [
          [{"name" : "Q"},
           {"name" : "W"},
@@ -121,13 +123,14 @@
           {"name" : "comma"},
           {"name" : "period"},
           {"name" : "question"}],
-         [{"name" : "Caribou_Symbols", "width" : 2, "toggle" : "symbols1"},
+         [{"name" : "Caribou_Symbols", "width" : 2, "toggle" : "default"},
           {"name" : "Caribou_Emoticons"},
           {"name" : "space", "width" : 5},
           {"name" : "Caribou_Prefs", "margin_left" : 2}]
       ]
    },
    "symbols1" : {
+      "mode" : "locked",
       "rows" : [
          [{"name" : "1"},
           {"name" : "2"},
@@ -160,13 +163,14 @@
           {"name" : "quotedbl"},
           {"name" : "bar"},
           {"name" : "numbersign"}],
-         [{"name" : "Caribou_Alpha", "width" : 2, "toggle" : "level1"},
+         [{"name" : "Caribou_Alpha", "width" : 2, "toggle" : "default"},
           {"name" : "Caribou_Emoticons"},
           {"name" : "space", "width" : 5},
           {"name" : "Caribou_Prefs", "margin_left" : 2}]
       ]
    },
    "symbols2" : {
+      "mode" : "locked",
       "rows" : [
          [{"name" : "percent"},
           {"name" : "bracketleft"},
@@ -199,7 +203,7 @@
           {"name" : "quotedbl"},
           {"name" : "bar"},
           {"name" : "numbersign"}],
-         [{"name" : "Caribou_Alpha", "width" : 2, "toggle" : "level1"},
+         [{"name" : "Caribou_Alpha", "width" : 2, "toggle" : "default"},
           {"name" : "Caribou_Emoticons"},
           {"name" : "space", "width" : 5},
           {"name" : "Caribou_Prefs", "margin_left" : 2}]



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]