Add unsqu33kr script and use it to add French, Spanish and fourth layer
This commit is contained in:
parent
f44e3fa48a
commit
efc5f3006b
8 changed files with 6047 additions and 563 deletions
13
unsqu33kr/Pipfile
Normal file
13
unsqu33kr/Pipfile
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
[[source]]
|
||||
url = "https://pypi.org/simple"
|
||||
verify_ssl = true
|
||||
name = "pypi"
|
||||
|
||||
[packages]
|
||||
pyyaml = "*"
|
||||
gitpython = "*"
|
||||
|
||||
[dev-packages]
|
||||
|
||||
[requires]
|
||||
python_version = "3.8"
|
||||
80
unsqu33kr/Pipfile.lock
generated
Normal file
80
unsqu33kr/Pipfile.lock
generated
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "2d598f1754849a1e6f92a1ee95baaf2ced919bf20e44a4eec871521e772b0127"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {
|
||||
"python_version": "3.8"
|
||||
},
|
||||
"sources": [
|
||||
{
|
||||
"name": "pypi",
|
||||
"url": "https://pypi.org/simple",
|
||||
"verify_ssl": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"default": {
|
||||
"gitdb": {
|
||||
"hashes": [
|
||||
"sha256:6c4cc71933456991da20917998acbe6cf4fb41eeaab7d6d67fbc05ecd4c865b0",
|
||||
"sha256:96bf5c08b157a666fec41129e6d327235284cca4c81e92109260f353ba138005"
|
||||
],
|
||||
"markers": "python_version >= '3.4'",
|
||||
"version": "==4.0.7"
|
||||
},
|
||||
"gitpython": {
|
||||
"hashes": [
|
||||
"sha256:b838a895977b45ab6f0cc926a9045c8d1c44e2b653c1fcc39fe91f42c6e8f05b",
|
||||
"sha256:fce760879cd2aebd2991b3542876dc5c4a909b30c9d69dfc488e504a8db37ee8"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==3.1.18"
|
||||
},
|
||||
"pyyaml": {
|
||||
"hashes": [
|
||||
"sha256:08682f6b72c722394747bddaf0aa62277e02557c0fd1c42cb853016a38f8dedf",
|
||||
"sha256:0f5f5786c0e09baddcd8b4b45f20a7b5d61a7e7e99846e3c799b05c7c53fa696",
|
||||
"sha256:129def1b7c1bf22faffd67b8f3724645203b79d8f4cc81f674654d9902cb4393",
|
||||
"sha256:294db365efa064d00b8d1ef65d8ea2c3426ac366c0c4368d930bf1c5fb497f77",
|
||||
"sha256:3b2b1824fe7112845700f815ff6a489360226a5609b96ec2190a45e62a9fc922",
|
||||
"sha256:3bd0e463264cf257d1ffd2e40223b197271046d09dadf73a0fe82b9c1fc385a5",
|
||||
"sha256:4465124ef1b18d9ace298060f4eccc64b0850899ac4ac53294547536533800c8",
|
||||
"sha256:49d4cdd9065b9b6e206d0595fee27a96b5dd22618e7520c33204a4a3239d5b10",
|
||||
"sha256:4e0583d24c881e14342eaf4ec5fbc97f934b999a6828693a99157fde912540cc",
|
||||
"sha256:5accb17103e43963b80e6f837831f38d314a0495500067cb25afab2e8d7a4018",
|
||||
"sha256:607774cbba28732bfa802b54baa7484215f530991055bb562efbed5b2f20a45e",
|
||||
"sha256:6c78645d400265a062508ae399b60b8c167bf003db364ecb26dcab2bda048253",
|
||||
"sha256:72a01f726a9c7851ca9bfad6fd09ca4e090a023c00945ea05ba1638c09dc3347",
|
||||
"sha256:74c1485f7707cf707a7aef42ef6322b8f97921bd89be2ab6317fd782c2d53183",
|
||||
"sha256:895f61ef02e8fed38159bb70f7e100e00f471eae2bc838cd0f4ebb21e28f8541",
|
||||
"sha256:8c1be557ee92a20f184922c7b6424e8ab6691788e6d86137c5d93c1a6ec1b8fb",
|
||||
"sha256:bb4191dfc9306777bc594117aee052446b3fa88737cd13b7188d0e7aa8162185",
|
||||
"sha256:bfb51918d4ff3d77c1c856a9699f8492c612cde32fd3bcd344af9be34999bfdc",
|
||||
"sha256:c20cfa2d49991c8b4147af39859b167664f2ad4561704ee74c1de03318e898db",
|
||||
"sha256:cb333c16912324fd5f769fff6bc5de372e9e7a202247b48870bc251ed40239aa",
|
||||
"sha256:d2d9808ea7b4af864f35ea216be506ecec180628aced0704e34aca0b040ffe46",
|
||||
"sha256:d483ad4e639292c90170eb6f7783ad19490e7a8defb3e46f97dfe4bacae89122",
|
||||
"sha256:dd5de0646207f053eb0d6c74ae45ba98c3395a571a2891858e87df7c9b9bd51b",
|
||||
"sha256:e1d4970ea66be07ae37a3c2e48b5ec63f7ba6804bdddfdbd3cfd954d25a82e63",
|
||||
"sha256:e4fac90784481d221a8e4b1162afa7c47ed953be40d31ab4629ae917510051df",
|
||||
"sha256:fa5ae20527d8e831e8230cbffd9f8fe952815b2b7dae6ffec25318803a7528fc",
|
||||
"sha256:fd7f6999a8070df521b6384004ef42833b9bd62cfee11a09bda1079b4b704247",
|
||||
"sha256:fdc842473cd33f45ff6bce46aea678a54e3d21f1b61a7750ce3c498eedfe25d6",
|
||||
"sha256:fe69978f3f768926cfa37b867e3843918e012cf83f680806599ddce33c2c68b0"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==5.4.1"
|
||||
},
|
||||
"smmap": {
|
||||
"hashes": [
|
||||
"sha256:7e65386bd122d45405ddf795637b7f7d2b532e7e401d46bbe3fb49b9986d5182",
|
||||
"sha256:a9a7479e4c572e2e775c404dcd3080c8dc49f39918c2cf74913d30c4c478e3c2"
|
||||
],
|
||||
"markers": "python_version >= '3.5'",
|
||||
"version": "==4.0.0"
|
||||
}
|
||||
},
|
||||
"develop": {}
|
||||
}
|
||||
170
unsqu33kr/unsqu33kr.py
Normal file
170
unsqu33kr/unsqu33kr.py
Normal file
|
|
@ -0,0 +1,170 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import git
|
||||
import os
|
||||
import sys
|
||||
import tempfile
|
||||
import yaml
|
||||
|
||||
|
||||
repository_url = 'https://gitlab.gnome.org/World/Phosh/squeekboard.git'
|
||||
rel_layouts_dir = 'data/keyboards'
|
||||
layout_whitelist = ['de', 'es', 'fr', 'us']
|
||||
layer_whitelist = ['base', 'upper', 'numbers', 'eschars']
|
||||
quote_blacklist = ['LV_SYMBOL_BACKSPACE', 'LV_SYMBOL_LEFT', 'LV_SYMBOL_RIGHT', 'LV_SYMBOL_OK']
|
||||
|
||||
key_map = {
|
||||
'"': '\\"',
|
||||
'colon': ':',
|
||||
'BackSpace': 'LV_SYMBOL_BACKSPACE',
|
||||
'period': '.',
|
||||
'preferences': None,
|
||||
'Shift_L': {
|
||||
'base': 'ABC',
|
||||
'upper': 'abc'
|
||||
},
|
||||
'show_eschars': 'àéö',
|
||||
'show_letters': 'abc',
|
||||
'show_numbers': '1#',
|
||||
'show_numbers_from_symbols': '1#',
|
||||
'show_symbols': None,
|
||||
'space': ['LV_SYMBOL_LEFT', ' ', 'LV_SYMBOL_RIGHT'],
|
||||
'Return': 'LV_SYMBOL_OK'
|
||||
}
|
||||
|
||||
layer_map = {
|
||||
'base': 'lower',
|
||||
'eschars': 'special'
|
||||
}
|
||||
|
||||
layer_to_description = {
|
||||
'base': 'Lowercase layer',
|
||||
'upper': 'Uppercase layer',
|
||||
'numbers': 'Number / symbol layer',
|
||||
'eschars': 'Special characters'
|
||||
}
|
||||
|
||||
name_map = {
|
||||
'de': 'German',
|
||||
'es': 'Spanish',
|
||||
'fr': 'French',
|
||||
'us': 'English (US)'
|
||||
}
|
||||
|
||||
|
||||
def clone_squeekboard_repo(destination):
|
||||
git.Repo.clone_from(repository_url, destination, depth=1)
|
||||
|
||||
|
||||
def load_yaml(path):
|
||||
with open(path, 'r') as stream:
|
||||
try:
|
||||
return yaml.safe_load(stream)
|
||||
except yaml.YAMLError as exc:
|
||||
print(exc)
|
||||
|
||||
|
||||
def map_key(key, layer, name):
|
||||
mapped = key_map[key] if key in key_map else key
|
||||
if isinstance(mapped, dict):
|
||||
mapped = mapped[layer] if layer in mapped else None
|
||||
if not mapped:
|
||||
return []
|
||||
if isinstance(mapped, list):
|
||||
return mapped
|
||||
return [mapped]
|
||||
|
||||
|
||||
def map_layer(layer):
|
||||
return layer_map[layer] if layer in layer_map else layer
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
layouts = []
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
clone_squeekboard_repo(tmp)
|
||||
|
||||
layouts_dir = os.path.join(tmp, rel_layouts_dir)
|
||||
|
||||
for file in os.listdir(layouts_dir):
|
||||
path = os.path.join(layouts_dir, file)
|
||||
|
||||
if not os.path.isfile(path):
|
||||
continue
|
||||
|
||||
name, extension = os.path.splitext(file)
|
||||
if name not in layout_whitelist:
|
||||
continue
|
||||
|
||||
data = load_yaml(path)
|
||||
if not data:
|
||||
continue
|
||||
|
||||
if not 'views' in data:
|
||||
continue
|
||||
|
||||
buttons = data['buttons'] if 'buttons' in data else {}
|
||||
|
||||
print(f'/**\n * {name_map[name]}\n **/\n')
|
||||
print(f'#define NAME_{name.upper()} "{name_map[name]}"\n')
|
||||
|
||||
for layer in layer_whitelist:
|
||||
print(f'/* {layer_to_description[layer]} */')
|
||||
if layer not in data['views']:
|
||||
print(f'#define KEYS_{map_layer(layer).upper()}_{name.upper()} ' + '{ NULL }')
|
||||
print(f'#define ATTRIBUTES_{map_layer(layer).upper()}_{name.upper()} ' + '{ 0 }\n')
|
||||
continue
|
||||
|
||||
rows = data['views'][layer]
|
||||
keys_by_row = []
|
||||
attrs_by_row = []
|
||||
|
||||
for i, row in enumerate(rows):
|
||||
keys = []
|
||||
attrs = []
|
||||
for key in row.split():
|
||||
for mapped in map_key(key, layer, name):
|
||||
keys.append(f'"{mapped}"' if mapped not in quote_blacklist else mapped)
|
||||
if key in buttons and key not in ['period', 'colon', '"']:
|
||||
attrs.append(f'LV_KEYBOARD_CTRL_BTN_FLAGS | {7 if mapped == " " else 3}')
|
||||
else:
|
||||
attrs.append('2')
|
||||
keys_by_row.append(keys)
|
||||
attrs_by_row.append(attrs)
|
||||
|
||||
print(f'#define KEYS_{map_layer(layer).upper()}_{name.upper()} ' + '{ \\')
|
||||
for i, keys in enumerate(keys_by_row):
|
||||
joined = ', '.join(keys)
|
||||
suffix = '"\\n", \\' if i < len(rows) - 1 else '"" \\'
|
||||
print(f' {joined}, {suffix}')
|
||||
print('}')
|
||||
print(f'#define ATTRIBUTES_{map_layer(layer).upper()}_{name.upper()} ' + '{ \\')
|
||||
for i, attrs in enumerate(attrs_by_row):
|
||||
joined = ', '.join(attrs)
|
||||
suffix = ', \\' if i < len(rows) - 1 else ' \\'
|
||||
print(f' {joined}{suffix}')
|
||||
print('}\n')
|
||||
|
||||
layouts.append(name)
|
||||
|
||||
print('/**\n * All layouts\n **/\n')
|
||||
|
||||
print('static const char * const names =')
|
||||
for i, name in enumerate(layouts):
|
||||
suffix = ' "\\n"' if i < len(layouts) - 1 else ';\n'
|
||||
print(f' LV_SYMBOL_KEYBOARD " " NAME_{name.upper()}{suffix}')
|
||||
|
||||
for layer in layer_whitelist:
|
||||
print(f'static const char ** const keys_{map_layer(layer)}[] = ' + '{')
|
||||
for i, name in enumerate(layouts):
|
||||
suffix = ', \\' if i < len(layouts) - 1 else ' \\'
|
||||
print(f' (const char * const [])KEYS_{map_layer(layer).upper()}_{name.upper()}{suffix}')
|
||||
print('};')
|
||||
print()
|
||||
print(f'static const lv_btnmatrix_ctrl_t * const attributes_{map_layer(layer)}[] = ' + '{')
|
||||
for i, name in enumerate(layouts):
|
||||
suffix = ', \\' if i < len(layouts) - 1 else ' \\'
|
||||
print(f' (lv_btnmatrix_ctrl_t[])ATTRIBUTES_{map_layer(layer).upper()}_{name.upper()}{suffix}')
|
||||
print('};')
|
||||
print()
|
||||
Loading…
Add table
Add a link
Reference in a new issue