summaryrefslogtreecommitdiff
path: root/lulua
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2019-10-05 09:06:23 +0200
committerLars-Dominik Braun <lars@6xq.net>2019-10-05 09:06:23 +0200
commitf73b4688844d2aec6a92474d7ccb8aae793d14ad (patch)
tree89117e3e19e16e57579295bdbca25de0c4162908 /lulua
parent2d45ef655f8791037373ab83174fc6c3596227b0 (diff)
downloadlulua-f73b4688844d2aec6a92474d7ccb8aae793d14ad.tar.gz
lulua-f73b4688844d2aec6a92474d7ccb8aae793d14ad.tar.bz2
lulua-f73b4688844d2aec6a92474d7ccb8aae793d14ad.zip
optimize: Support wildcard pins
Diffstat (limited to 'lulua')
-rw-r--r--lulua/optimize.py30
1 files changed, 27 insertions, 3 deletions
diff --git a/lulua/optimize.py b/lulua/optimize.py
index 281f0ab..db5807b 100644
--- a/lulua/optimize.py
+++ b/lulua/optimize.py
@@ -19,6 +19,7 @@
# THE SOFTWARE.
import pickle, sys, random, time, logging, argparse
+from fnmatch import fnmatch
from copy import deepcopy
from typing import List, Tuple, Optional, Text, FrozenSet
from abc import abstractmethod
@@ -237,7 +238,20 @@ class LayoutOptimizer (Annealer):
return super().run (steps)
def parsePin (s: Text):
- """ Parse --pin argument """
+ """
+ Parse --pin argument
+
+ Synax: <layer>[;<button>]
+ Examples:
+ 0
+ (keeps all buttons on the first layer on this layer)
+ 1;Bl1
+ (keeps Bl1 on layer 1 in place)
+ 2;B*
+ (pins all buttons matching B* on layer 2 in place)
+
+ (Expansion is performed when the keyboard is known)
+ """
pins = []
for p in s.split (';'):
p = p.split (',', 1)
@@ -289,13 +303,23 @@ def optimize ():
# mutate modifier key positions.
# XXX: only works for single-button-modifier
if not isinstance (k, LetterButton) or layout.isModifier (frozenset ([k])):
- logging.info (f'ignoring {k}')
+ logging.info (f'not mutating {k}')
continue
keys.append ((i, k))
values.append ((i, k))
buttonMap = dict (zip (keys, values))
- pins = [(x, keyboard[y] if y else None) for x, y in args.pin]
+ pins = []
+ for layer, match in args.pin:
+ # special pin, which just keeps buttons on the same layer
+ if match is None:
+ pins.append ((layer, match))
+ continue
+ # wildcard matches
+ for k in keyboard.keys ():
+ if fnmatch (k.name, match):
+ pins.append ((layer, k))
+ logging.info (f'pinning layer {layer} {k}')
opt = LayoutOptimizer (buttonMap, triads, layout, pins, writer, model=models[args.model])
if args.randomize: