]> git.donarmstrong.com Git - qmk_firmware.git/blob - layouts/community/ortho_4x12/guidoism/generate_c.py
Converted guidoism layout to new keyboard-agnostic form (#3367)
[qmk_firmware.git] / layouts / community / ortho_4x12 / guidoism / generate_c.py
1 import itertools
2 import json
3 from pprint import pprint as pp
4
5 layers = dict(enumerate(['_QWERTY', '_LOWER', '_RAISE', '_MOVEMENT', '_NUMPAD']))
6 key_names = {('MO(%d)' % i): layers.get(i).strip('_') for i in layers.keys()}
7
8 unicodes = {
9     "<i class='fa fa-fast-forward'></i>": "next",
10     "<i class='fa fa-volume-down'></i>": "vol-",
11     "<i class='fa fa-volume-up'></i>": "vol+",
12     "<i class='fa fa-play'></i>": "play",
13 }
14
15 d = json.load(open('layouts/community/ortho_4x12/guidoism/guidoism.json'))
16
17 def grouper(iterable, n):
18     args = [iter(iterable)] * n
19     return itertools.zip_longest(*args, fillvalue='')
20
21 def truthy(s):
22     return [a for a in s if a]
23
24 def just(s, n):
25     return [a.center(n*2+1 if len(s) == 11 and i == 5 else n) for i, a in enumerate(s)]
26
27 def replace(s):
28     return [key_names.get(a, a) for a in s]
29
30 def layer(i, l):
31     n = max(len(s) for s in l)
32     rows = [', '.join(replace(truthy(row))) for row in grouper(l, 12)]
33     return '[%s] = %s(\n%s)' % (layers[i], d['layout'], ',\n'.join(rows))
34
35 print(',\n\n'.join(layer(i, l) for i, l in enumerate(d['layers'])))
36
37 def surround(s, a, b, c):
38     return a + b.join(s) + c
39
40 def pattern(cell, table):
41     return ['─'*cell for i in range(table)]
42
43 keys = json.load(open('layouts/community/ortho_4x12/guidoism/keys.json'))
44
45 def layer2(i, l):
46     def replace(s):
47         s = [keys.get(a, a) for a in s]
48         return [unicodes.get(a, a) for a in s]
49     n = max(len(s) for s in l)
50     return [surround(just(replace(truthy(row)), 5), '│', '│', '│') for row in grouper(l, 12)]
51
52 for i, l in enumerate(d['layers']):
53     print(surround(pattern(5, 12), '┌', '┬', '┐'))
54     for n, row in enumerate(layer2(i, l)):
55         print(row)
56         if n < 3:
57             print(surround(pattern(5, 12), '├', '┼', '┤'))
58         else:
59             print(surround(pattern(5, 12), '└', '┴', '┘'))