eb393cc7a0f0 — Arne Babenhauserheide 13 years ago
`FIX: swtich keys got distracted by keys repeated on higher layers of Neo.`
```2 files changed, 73 insertions(+), 18 deletions(-)

M check_neo.py
M layout_base.py
```
`M check_neo.py +26 -5`
```@@ 109,8 109,18 @@ def switch_keys(keypairs, layout=NEO_LAY
'q'
>>> get_key((1, 10, 0), layout=lay)
'w'
+    >>> get_key((1, 1, 1), layout=lay)
+    'L'
+    >>> get_key((1, 3, 1), layout=lay)
+    'X'
+    >>> get_key((1, 5, 1), layout=lay)
+    'Q'
+    >>> get_key((1, 10, 1), layout=lay)
+    'W'
>>> find_key("l", layout=lay) == (1, 1, 0)
True
+    >>> find_key("L", layout=lay) == (1, 1, 1)
+    True
>>> NEO_LAYOUT_lxwq == lay[:5]
True
>>> lay = switch_keys(["lx"], layout = NEO_LAYOUT)

@@ 120,14 130,24 @@ def switch_keys(keypairs, layout=NEO_LAY
>>> lay = switch_keys(["ab"], layout=lay)
>>> a == find_key("b", layout=lay)
True
+    >>> dot = find_key(".", layout=NEO_LAYOUT)
+    >>> d = find_key("d", layout=NEO_LAYOUT)
+    >>> lay = switch_keys([".d"], layout=NEO_LAYOUT)
+    >>> d == find_key(".", layout=lay)
+    True
+    >>> dot == find_key("d", layout=lay)
+    True
"""
lay = deepcopy(layout)
from pprint import pprint
#pprint(lay)
for pair in keypairs:
-        try:
pos0 = find_key(pair[0], layout=lay)
pos1 = find_key(pair[1], layout=lay)
+            if None in lay[5].values():
+                print(prev, pos0, pos1, pair)
+                exit()
+
if pair[1].upper() == pair[1]:
tmp0 = (pair[1], ) + tuple(lay[pos0[0]][pos0[1]][1:])
else:

@@ 141,10 161,11 @@ def switch_keys(keypairs, layout=NEO_LAY
lay[pos0[0]][pos0[1]] = tmp0
lay[pos1[0]][pos1[1]] = tmp1
update_letter_to_key_cache_multiple(pair+pair.upper(), layout=lay)
-        except:
-            pprint(lay)
-            print(pair, tmp0, tmp1)
-            exit()
+            prev = pair
+        #except:
+        #    pprint(lay)
+        #    print(prev, pair, pos0, pos1, tmp0, tmp1)
+        #    exit()

return lay

```
`M layout_base.py +47 -13`
```@@ 56,18 56,48 @@ NEO_LAYOUT = [
[(), (), (), (" ", " ", " ", "0", " ", " "), (), (), (), ()] # Reihe 4 mit Leertaste
]
NEO_LAYOUT_lx = [
-    [("^"),("1"),("2"),("3"),("4"),("5"),("6"),("7"),("8"),("9"),("0"),("-"),("`"),("←")], # Zahlenreihe (0)
-    [("⇥"),("l"),("v"),("x"),("c"),("w"),("k"),("h"),("g"),("f"),("q"),("ß"),("´"),()], # Reihe 1
-    [("⇩"),("u"),("i"),("a"),("e"),("o"),("s"),("n"),("r"),("t"),("d"),("y"),("⇘"),("\n")], # Reihe 2
-    [("⇧"),(),("ü"),("ö"),("ä"),("p"),("z"),("b"),("m"),(","),("."),("j"),("⇗")],        # Reihe 3
-    [(), (), (), (" "), (), (), (), ()] # Reihe 4 mit Leertaste
+    [("^", "ˇ", "↻", "˙", "˞", "̣"),("1", "°", "¹", "ª", "₁", "¬"),("2", "§", "²", "º", "₂", "∨"),("3", "ℓ", "³", "№", "₃", "∧"),
+     ("4", "»", "›", "", "♀", "⊥"),("5", "«", "‹", "·", "♂", "∡"),("6", "\$", "¢", "£", "⚥", "∥"),("7", "€", "¥", "¤", "ϰ", "→"),
+     ("8", "„", "‚", "⇥", "⟨", "∞"),("9", "“", "‘", " /", "⟩", "∝"),("0", "”", "’", "*", "₀", "∅"),("-", "—", "-", "‑", "­"),
+     ("`", "¸", "°", "¨", "", "¯"),("←")], # Zahlenreihe (0)
+
+    [("⇥"),("l", "L", "…", "⇞", "ξ", "Ξ"),("v", "V", "_", "⌫", "", "√"),("x", "X", "[", "⇡", "", "λ", "Λ"),
+     ("c", "C", "]", "Entf", "χ", "ℂ"),("w", "W", "^", "⇟", "ω", "Ω"),("k", "K", "!", "¡", "κ", "×"),("h", "H", "<", "7", "ψ", "Ψ"),
+     ("g", "G", ">", "8", "γ", "Γ"),("f", "F", "=", "9", "φ", "Φ"),("q", "Q", "&", "+", "ϕ", "ℚ"),("ß", "ẞ", "ſ", "−", "ς", "∘"),
+     ("´", "~", "/", "˝", "", "˘"),()], # Reihe 1
+
+    [("⇩"),("u", "U", "\\", "⇱", "", "⊂"),("i", "I", "/", "⇠", "ι", "∫"),("a", "A", "{",  "⇣", "α", "∀"),
+     ("e", "E", "}", "⇢", "ε", "∃"),("o", "O", "*", "⇲", "ο", "∈"),("s", "S", "?", "¿", "σ", "Σ"),("n", "N", "(", "4", "ν", "ℕ"),
+     ("r", "R", ")", "5", "ρ", "ℝ"),("t", "T", "-", "6", "τ", "∂"),("d", "D", ":", ",", "δ", "Δ"),("y", "Y", "@", ".", "υ", "∇"),
+     ("⇘"),("\n")], # Reihe 2
+
+    [("⇧"),(),("ü", "Ü", "\#", "", "", "∪"),("ö", "Ö", "\$", "", "ϵ", "∩"),("ä", "Ä", "|", "⎀", "η", "ℵ"),
+     ("p", "P", "~", "\n", "π", "Π"),("z", "Z", "`", "↶", "ζ", "ℤ"),("b", "B", "+", ":", "β", "⇐"),("m", "M", "%", "1", "μ", "⇔"),
+     (",", "–", '"', "2", "ϱ", "⇒"),(".", "•", "'", "3", "ϑ", "↦"),("j", "J", ";", ";", "θ", "Θ"),("⇗")],        # Reihe 3
+
+    [(), (), (), (" ", " ", " ", "0", " ", " "), (), (), (), ()] # Reihe 4 mit Leertaste
]
-NEO_LAYOUT_lxwq = [ # 25% weniger Fingerwiederholungen als Neo, fast 50% weniger als Qwertz
-    [("^"),("1"),("2"),("3"),("4"),("5"),("6"),("7"),("8"),("9"),("0"),("-"),("`"),("←")], # Zahlenreihe (0)
-    [("⇥"),("l"),("v"),("x"),("c"),("q"),("k"),("h"),("g"),("f"),("w"),("ß"),("´"),()], # Reihe 1
-    [("⇩"),("u"),("i"),("a"),("e"),("o"),("s"),("n"),("r"),("t"),("d"),("y"),("⇘"),("\n")], # Reihe 2
-    [("⇧"),(),("ü"),("ö"),("ä"),("p"),("z"),("b"),("m"),(","),("."),("j"),("⇗")],        # Reihe 3
-    [(), (), (), (" "), (), (), (), ()] # Reihe 4 mit Leertaste
+NEO_LAYOUT_lxwq = [
+    [("^", "ˇ", "↻", "˙", "˞", "̣"),("1", "°", "¹", "ª", "₁", "¬"),("2", "§", "²", "º", "₂", "∨"),("3", "ℓ", "³", "№", "₃", "∧"),
+     ("4", "»", "›", "", "♀", "⊥"),("5", "«", "‹", "·", "♂", "∡"),("6", "\$", "¢", "£", "⚥", "∥"),("7", "€", "¥", "¤", "ϰ", "→"),
+     ("8", "„", "‚", "⇥", "⟨", "∞"),("9", "“", "‘", " /", "⟩", "∝"),("0", "”", "’", "*", "₀", "∅"),("-", "—", "-", "‑", "­"),
+     ("`", "¸", "°", "¨", "", "¯"),("←")], # Zahlenreihe (0)
+
+    [("⇥"),("l", "L", "…", "⇞", "ξ", "Ξ"),("v", "V", "_", "⌫", "", "√"),("x", "X", "[", "⇡", "", "λ", "Λ"),
+     ("c", "C", "]", "Entf", "χ", "ℂ"),("q", "Q", "^", "⇟", "ω", "Ω"),("k", "K", "!", "¡", "κ", "×"),("h", "H", "<", "7", "ψ", "Ψ"),
+     ("g", "G", ">", "8", "γ", "Γ"),("f", "F", "=", "9", "φ", "Φ"),("w", "W", "&", "+", "ϕ", "ℚ"),("ß", "ẞ", "ſ", "−", "ς", "∘"),
+     ("´", "~", "/", "˝", "", "˘"),()], # Reihe 1
+
+    [("⇩"),("u", "U", "\\", "⇱", "", "⊂"),("i", "I", "/", "⇠", "ι", "∫"),("a", "A", "{",  "⇣", "α", "∀"),
+     ("e", "E", "}", "⇢", "ε", "∃"),("o", "O", "*", "⇲", "ο", "∈"),("s", "S", "?", "¿", "σ", "Σ"),("n", "N", "(", "4", "ν", "ℕ"),
+     ("r", "R", ")", "5", "ρ", "ℝ"),("t", "T", "-", "6", "τ", "∂"),("d", "D", ":", ",", "δ", "Δ"),("y", "Y", "@", ".", "υ", "∇"),
+     ("⇘"),("\n")], # Reihe 2
+
+    [("⇧"),(),("ü", "Ü", "\#", "", "", "∪"),("ö", "Ö", "\$", "", "ϵ", "∩"),("ä", "Ä", "|", "⎀", "η", "ℵ"),
+     ("p", "P", "~", "\n", "π", "Π"),("z", "Z", "`", "↶", "ζ", "ℤ"),("b", "B", "+", ":", "β", "⇐"),("m", "M", "%", "1", "μ", "⇔"),
+     (",", "–", '"', "2", "ϱ", "⇒"),(".", "•", "'", "3", "ϑ", "↦"),("j", "J", ";", ";", "θ", "Θ"),("⇗")],        # Reihe 3
+
+    [(), (), (), (" ", " ", " ", "0", " ", " "), (), (), (), ()] # Reihe 4 mit Leertaste
]

# TODO: Add higher layers (shift for the numbers, …)

@@ 221,8 251,10 @@ def update_letter_to_key_cache(key, layo
# make sure that the keys on lower levels always win agains those on higher levels.
# TODO (maybe someday): update the scheme to allow for multiple positions ⇒ only take the lowest cost.
idx_rev = key_num - idx -1
-                    if layout[row][col][idx] == key:
-                        pos = (row, col, idx)
+                    if layout[row][col][idx_rev] == key:
+                        if pos and pos[2] < idx_rev:
+                            continue
+                        pos = (row, col, idx_rev)
LETTER_TO_KEY_CACHE[key] = pos
return pos

@@ 271,6 303,8 @@ def find_key(key, layout):
(2, 3, 1)
>>> find_key("e", NEO_LAYOUT)
(2, 4, 0)
+    >>> find_key(",", NEO_LAYOUT)
+    (3, 9, 0)
"""
# check, if the layout already has a cache. If not, create it.
# this approach reduces the time to find a key by about 50%.

```