From 4c2453aa1b71d269f67a25c89848965f9a6d2925 Mon Sep 17 00:00:00 2001 From: Jan Christoph Ebersbach Date: Tue, 30 Apr 2019 06:35:34 +0200 Subject: [Keyboard] Signum3.0 remove sortedcontainers (#5679) * Remove dependency on sortedcontainers * Sort dictionary on output --- keyboards/signum/3_0/elitec/keymaps/default/generate_km.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'keyboards/signum/3_0/elitec/keymaps/default/generate_km.py') diff --git a/keyboards/signum/3_0/elitec/keymaps/default/generate_km.py b/keyboards/signum/3_0/elitec/keymaps/default/generate_km.py index 7778da8f5..05996d06c 100755 --- a/keyboards/signum/3_0/elitec/keymaps/default/generate_km.py +++ b/keyboards/signum/3_0/elitec/keymaps/default/generate_km.py @@ -1,7 +1,6 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -from sortedcontainers import SortedDict import layout import re @@ -11,7 +10,7 @@ import re def gen_uc_iter(): length = len(layout.uc_dict) - for key, value in layout.uc_dict.items(): + for key, value in sorted(layout.uc_dict.items()): length -= 1 if length: yield (key, value, False) -- cgit v1.2.3-70-g09d2 From 074be4fe5e8a783c0147e6fa57182c1a6b61418d Mon Sep 17 00:00:00 2001 From: Jan Christoph Ebersbach Date: Wed, 1 May 2019 06:53:29 +0200 Subject: [Keyboard] Signum3.0 generate json keymap (#5688) * Remove dependency on sortedcontainers * Sort dictionary on output * Externalize writing of keymap.c into function - serialize layers into one flat list * Add encoding * Generate JSON keymap in addition to keymap.c * Replace XXXXXX with KC_NO --- .../3_0/elitec/keymaps/default/generate_km.py | 126 +++++++++++++-------- .../signum/3_0/elitec/keymaps/default/keymap.c | 24 ++-- .../signum/3_0/elitec/keymaps/default/layout.py | 60 +++++----- .../signum/3_0/elitec/keymaps/default/readme.md | 3 +- 4 files changed, 125 insertions(+), 88 deletions(-) (limited to 'keyboards/signum/3_0/elitec/keymaps/default/generate_km.py') diff --git a/keyboards/signum/3_0/elitec/keymaps/default/generate_km.py b/keyboards/signum/3_0/elitec/keymaps/default/generate_km.py index 05996d06c..9517a2f1f 100755 --- a/keyboards/signum/3_0/elitec/keymaps/default/generate_km.py +++ b/keyboards/signum/3_0/elitec/keymaps/default/generate_km.py @@ -1,12 +1,11 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- +import json import layout +import os import re -# TODO: auto-generate mutex layers -# TODO: auto-generate update_tri_layer (_state) - def gen_uc_iter(): length = len(layout.uc_dict) @@ -18,7 +17,7 @@ def gen_uc_iter(): yield (key, value, True) -def translate(s): +def _translate(s): if re.match("^[0-9]$", s): return ("KC_{0}".format(s), " {0} ".format(s)) elif re.match("^[a-z]$", s): @@ -50,80 +49,115 @@ def translate(s): def toKC(s): - (kc, lgd) = translate(s) - return kc + return _translate(s)[0] def toLgd(s): - (kc, lgd) = translate(s) - return lgd - - -if __name__ == "__main__": + return _translate(s)[1] - template = open("km_template.txt", mode="r") - output = open("keymap.c", mode="w", encoding='utf-8') +def writeKeymap(f_template, f_keymap, columns, rows): doCopy = False - for line in template: + for line in f_template: doCopy = True if line.startswith("//"): doCopy = False -# output.write(str(layout.uc_dict)) + # f_keymap.write(str(layout.uc_dict)) for k, v, isLast in gen_uc_iter(): if isLast: - output.write(k + "\n") + f_keymap.write(k + "\n") else: - output.write(k + ",\n") - if line.startswith("//"): + f_keymap.write(k + ",\n") + elif line.startswith("//"): doCopy = False for k, v, isLast in gen_uc_iter(): if isLast: - output.write(u"\t[{0}] = {1} // {2}\n".format(k, v, chr(int(v, 0)))) + f_keymap.write(u"\t[{0}] = {1} // {2}\n".format(k, v, chr(int(v, 0)))) else: - output.write(u"\t[{0}] = {1}, // {2}\n".format(k, v, chr(int(v, 0)))) - if line.startswith("//"): + f_keymap.write(u"\t[{0}] = {1}, // {2}\n".format(k, v, chr(int(v, 0)))) + elif line.startswith("//"): doCopy = False - counter = len(layout.layers) - layer = 0 - S = layout.static - for L in layout.layers: - counter -= 1 - r_counter = 4 - output.write("/* Layer %d\n" % layer) - output.write(" * ------------------------------------------------- -------------------------------------------------\n") - output.write(" * |{0}|{1}|{2}|{3}|{4}|{5}| |{6}|{7}|{8}|{9}|{10}|{11}|\n".format(toLgd(L[0][0]), toLgd(L[0][1]), toLgd(L[0][2]), toLgd(L[0][3]), toLgd(L[0][4]), toLgd(L[0][5]), toLgd(L[0][6]), toLgd(L[0][7]), toLgd(L[0][8]), toLgd(L[0][9]), toLgd(L[0][10]), toLgd(L[0][11]))) - output.write(" * ------------------------------------------------- -------------------------------------------------\n") - output.write(" * |{0}|{1}|{2}|{3}|{4}|{5}| |{6}|{7}|{8}|{9}|{10}|{11}|\n".format(toLgd(L[1][0]), toLgd(L[1][1]), toLgd(L[1][2]), toLgd(L[1][3]), toLgd(L[1][4]), toLgd(L[1][5]), toLgd(L[1][6]), toLgd(L[1][7]), toLgd(L[1][8]), toLgd(L[1][9]), toLgd(L[1][10]), toLgd(L[1][11]))) - output.write(" * ------------------------------------------------- -------------------------------------------------\n") - output.write(" * |{0}|{1}|{2}|{3}|{4}|{5}| |{6}|{7}|{8}|{9}|{10}|{11}|\n".format(toLgd(L[2][0]), toLgd(L[2][1]), toLgd(L[2][2]), toLgd(L[2][3]), toLgd(L[2][4]), toLgd(L[2][5]), toLgd(L[2][6]), toLgd(L[2][7]), toLgd(L[2][8]), toLgd(L[2][9]), toLgd(L[2][10]), toLgd(L[2][11]))) - output.write(" * -----------------------------------------------------------------------------------------------------------------\n") - output.write(" * {0} {1} {2} |{3}|{4}|{5}|{6}|{7}|{8}| {9} {10} {11}".format(toLgd(L[3][0]), toLgd(L[3][1]), toLgd(L[3][2]), toLgd(L[3][3]), toLgd(L[3][4]), toLgd(L[3][5]), toLgd(L[3][6]), toLgd(L[3][7]), toLgd(L[3][8]), toLgd(L[3][9]), toLgd(L[3][10]), toLgd(L[3][11])).rstrip()+"\n") - output.write(" * -------------------------------------------------\n") - output.write(" */\n") + for layer, L in enumerate(layout.layers): + r_counter = rows + f_keymap.write("/* Layer %d\n" % layer) + f_keymap.write(" * ------------------------------------------------- -------------------------------------------------\n") + f_keymap.write(" * |{0}|{1}|{2}|{3}|{4}|{5}| |{6}|{7}|{8}|{9}|{10}|{11}|\n".format(*map(toLgd, L[:12]))) + f_keymap.write(" * ------------------------------------------------- -------------------------------------------------\n") + f_keymap.write(" * |{0}|{1}|{2}|{3}|{4}|{5}| |{6}|{7}|{8}|{9}|{10}|{11}|\n".format(*map(toLgd, L[12:24]))) + f_keymap.write(" * ------------------------------------------------- -------------------------------------------------\n") + f_keymap.write(" * |{0}|{1}|{2}|{3}|{4}|{5}| |{6}|{7}|{8}|{9}|{10}|{11}|\n".format(*map(toLgd, L[24:36]))) + f_keymap.write(" * -----------------------------------------------------------------------------------------------------------------\n") + f_keymap.write(" * {0} {1} {2} |{3}|{4}|{5}|{6}|{7}|{8}| {9} {10} {11}".format(*map(toLgd, L[36:48])).rstrip()+"\n") + f_keymap.write(" * -------------------------------------------------\n") + f_keymap.write(" */\n") l_code = '\tLAYOUT_ortho_4x12(\n' for r in range(r_counter): r_counter -= 1 - c_counter = 12 + c_counter = columns l_code += '\t\t' for c in range(c_counter): c_counter -= 1 if c != 0: l_code += " " - l_code += "%s" % toKC(L[r][c]) + l_code += "%s" % toKC(L[r*columns + columns-c_counter-1]) if r_counter or c_counter: l_code += "," l_code += '\n' - if counter: + if layer + 1 != len(layout.layers): l_code += "\t),\n\n" else: l_code += "\t)\n" - output.write(l_code) - layer += 1 + f_keymap.write(l_code) if doCopy: - output.write(line) + f_keymap.write(line) + + +def getKeymapJSON(keyboard, keymap, layout, layers): + return json.dumps({ + 'keyboard': keyboard, + 'keymap': keymap, + 'layout': layout, + 'layers': layers + }, sort_keys=True, indent=4) + - template.close() - output.close() +def layersToKC(layers): + return [list(map(toKC, layer)) for layer in layers] + + +def pathToKeymap(path): + head, keymap = os.path.split(path) + _, keymapsdir = os.path.split(head) + if keymapsdir == 'keymaps': + return keymap + + +def pathToKeyboard(path): + head, keymap = os.path.split(path) + head, keymapsdir = os.path.split(head) + if keymapsdir == 'keymaps': + head, dir = os.path.split(head) + while dir not in ('/', 'keyboards'): + yield dir + head, dir = os.path.split(head) + + +if __name__ == "__main__": + with open("km_template.txt", mode="r") as f_template: + with open("keymap.c", mode="w", encoding='utf-8') as f_keymap: + writeKeymap(f_template, f_keymap, columns=12, rows=4) + + abspath = os.path.dirname(os.path.abspath(__file__)) + keyboard = list(reversed(list(pathToKeyboard(abspath)))) + keymap = pathToKeymap(abspath) + keyboard_layout = 'LAYOUT_ortho_4x12' + with open("%s_%s.json" % ('_'.join(keyboard), keymap), mode="w") as f_keymapjson: + f_keymapjson.write( + getKeymapJSON( + '/'.join(keyboard), + keymap, + keyboard_layout, + layersToKC(layout.layers)) + ) diff --git a/keyboards/signum/3_0/elitec/keymaps/default/keymap.c b/keyboards/signum/3_0/elitec/keymaps/default/keymap.c index 4b3a9439d..c94890eda 100644 --- a/keyboards/signum/3_0/elitec/keymaps/default/keymap.c +++ b/keyboards/signum/3_0/elitec/keymaps/default/keymap.c @@ -672,8 +672,8 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { */ LAYOUT_ortho_4x12( KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_RBRC, - KC_TRNS, DF(0), DF(1), XXXXXXX, XXXXXXX, MO(3), KC_4, KC_4, KC_5, KC_6, KC_MINS, KC_EQL, - KC_TRNS, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, MO(5), KC_1, KC_1, KC_2, KC_3, KC_BSLS, KC_TRNS, + KC_TRNS, DF(0), DF(1), KC_NO, KC_NO, MO(3), KC_4, KC_4, KC_5, KC_6, KC_MINS, KC_EQL, + KC_TRNS, KC_NO, KC_NO, KC_NO, KC_NO, MO(5), KC_1, KC_1, KC_2, KC_3, KC_BSLS, KC_TRNS, TG(2), KC_TRNS, KC_TRNS, KC_TRNS, KC_DEL, KC_TRNS, KC_TRNS, KC_BSPC, KC_0, KC_TRNS, KC_TRNS, KC_TRNS ), @@ -689,9 +689,9 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { * ------------------------------------------------- */ LAYOUT_ortho_4x12( - KC_TRNS, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, XXXXXXX, - KC_TRNS, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, MO(3), KC_F4, KC_F4, KC_F5, KC_F6, XXXXXXX, XXXXXXX, - KC_TRNS, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_F1, KC_F1, KC_F2, KC_F3, XXXXXXX, KC_TRNS, + KC_TRNS, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_NO, + KC_TRNS, KC_NO, KC_NO, KC_NO, KC_NO, MO(3), KC_F4, KC_F4, KC_F5, KC_F6, KC_NO, KC_NO, + KC_TRNS, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_F1, KC_F1, KC_F2, KC_F3, KC_NO, KC_TRNS, TG(3), KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_F10, KC_F11, KC_F12, KC_TRNS, KC_TRNS, KC_TRNS ), @@ -709,7 +709,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { LAYOUT_ortho_4x12( KC_ESC, KC_ESC, LCTL(KC_W), LCTL(KC_T), CTL_T(KC_PGDN), CTL_T(KC_PGDN), KC_PGDN, KC_HOME, KC_UP, KC_INS, LSFT(KC_INS), KC_ESC, KC_TRNS, KC_CAPS, LGUI_T(KC_LEFT), LGUI_T(KC_TAB), LGUI_T(KC_RIGHT), LGUI_T(KC_RIGHT), KC_LEFT, KC_LEFT, KC_DOWN, KC_RIGHT, KC_END, KC_PSCR, - KC_TRNS, XXXXXXX, XXXXXXX, XXXXXXX, CTL_T(KC_PGUP), CTL_T(KC_PGUP), KC_PGUP, XXXXXXX, KC_DOWN, XXXXXXX, KC_APP, KC_TRNS, + KC_TRNS, KC_NO, KC_NO, KC_NO, CTL_T(KC_PGUP), CTL_T(KC_PGUP), KC_PGUP, KC_NO, KC_DOWN, KC_NO, KC_APP, KC_TRNS, TG(4), KC_TRNS, KC_TRNS, KC_TRNS, KC_DEL, KC_TRNS, KC_TRNS, KC_BSPC, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS ), @@ -725,9 +725,9 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { * ------------------------------------------------- */ LAYOUT_ortho_4x12( - KC_TRNS, XXXXXXX, KC_MPLY, KC_VOLU, KC_VOLU, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, RESET, KC_PWR, - KC_TRNS, XXXXXXX, KC_MPRV, KC_MUTE, KC_MNXT, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_SLEP, - KC_TRNS, XXXXXXX, XXXXXXX, KC_VOLD, KC_VOLD, MO(5), XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, + KC_TRNS, KC_NO, KC_MPLY, KC_VOLU, KC_VOLU, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, RESET, KC_PWR, + KC_TRNS, KC_NO, KC_MPRV, KC_MUTE, KC_MNXT, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_SLEP, + KC_TRNS, KC_NO, KC_NO, KC_VOLD, KC_VOLD, MO(5), KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, TG(5), KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS ), @@ -743,9 +743,9 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { * ------------------------------------------------- */ LAYOUT_ortho_4x12( - KC_TRNS, KC_ACL1, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_WH_U, KC_WH_L, KC_MS_U, KC_WH_R, XXXXXXX, XXXXXXX, - KC_TRNS, KC_ACL2, KC_BTN3, KC_BTN2, KC_BTN1, KC_BTN1, KC_MS_L, KC_MS_L, KC_MS_D, KC_MS_R, XXXXXXX, XXXXXXX, - KC_TRNS, KC_ACL0, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_WH_D, XXXXXXX, KC_MS_D, XXXXXXX, XXXXXXX, KC_TRNS, + KC_TRNS, KC_ACL1, KC_NO, KC_NO, KC_NO, KC_NO, KC_WH_U, KC_WH_L, KC_MS_U, KC_WH_R, KC_NO, KC_NO, + KC_TRNS, KC_ACL2, KC_BTN3, KC_BTN2, KC_BTN1, KC_BTN1, KC_MS_L, KC_MS_L, KC_MS_D, KC_MS_R, KC_NO, KC_NO, + KC_TRNS, KC_ACL0, KC_NO, KC_NO, KC_NO, KC_NO, KC_WH_D, KC_NO, KC_MS_D, KC_NO, KC_NO, KC_TRNS, TG(6), KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS ) }; diff --git a/keyboards/signum/3_0/elitec/keymaps/default/layout.py b/keyboards/signum/3_0/elitec/keymaps/default/layout.py index 5a796c862..69cc059f1 100644 --- a/keyboards/signum/3_0/elitec/keymaps/default/layout.py +++ b/keyboards/signum/3_0/elitec/keymaps/default/layout.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + # Add all used Unicode symbols to this list. # The key (e.g. "SNEK") is used in keymap.c for "enum", "unicode_map" and "keymaps", so it needs to be a valid C variable name. # The key is also used in this file to define the layout, so use recognizeable names. @@ -336,7 +338,7 @@ qmk_dict = { # If you find "BAD" in your keymaps, then something went wrong.) "a": "BAD", "A": "BAD", "0": "BAD", # Basic Keycodes - "XXX": "XXXXXXX", "": "KC_TRNS", + "XXX": "KC_NO", "": "KC_TRNS", "!": "S(KC_1)", "@": "S(KC_2)", "#": "S(KC_3)", "$": "S(KC_4)", "%": "S(KC_5)", "^": "S(KC_6)", "&": "S(KC_7)", "*": "S(KC_8)", "(": "S(KC_9)", ")": "S(KC_0)", "Enter": "KC_ENT", "Esc": "KC_ESC", "BSpace": "KC_BSPC", "Tab": "KC_TAB", @@ -426,58 +428,58 @@ static = ["NEO", "GREEK", "GREEK", "GREEK", "GREEK", "MOUSE"] # 0 qwerty = [ - ["Tab", "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "["], - ["LCtrl", "a", "s", "d", "f", "g", "h", "j", "k", "l", ";", "'"], - ["LShift(", "z", "x", "c", "v", "b", "n", "m", ",", ".", "/", "RShift)"], - ["MO2", "LGui", "LAlt", "TT2", "LT6_SPC", "TT4", "Enter", "Space", "TT2", "RAlt", "RGui", "RCtrl"], + "Tab", "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "[", + "LCtrl", "a", "s", "d", "f", "g", "h", "j", "k", "l", ";", "'", + "LShift(", "z", "x", "c", "v", "b", "n", "m", ",", ".", "/", "RShift)", + "MO2", "LGui", "LAlt", "TT2", "LT6_SPC", "TT4", "Enter", "Space", "TT2", "RAlt", "RGui", "RCtrl", ] # 1 colemak = [ - ["Tab", "q", "w", "f", "p", "g", "j", "l", "u", "y", ";", "["], - ["LCtrl", "a", "r", "s", "t", "d", "h", "n", "e", "i", "o", "'"], - ["LShift(", "z", "x", "c", "v", "b", "k", "m", ",", ".", "/", "RShift)"], - ["MO2", "LGui", "LAlt", "TT2", "LT6_SPC", "TT4", "Enter", "Space", "TT2", "RAlt", "RGui", "RCtrl"], + "Tab", "q", "w", "f", "p", "g", "j", "l", "u", "y", ";", "[", + "LCtrl", "a", "r", "s", "t", "d", "h", "n", "e", "i", "o", "'", + "LShift(", "z", "x", "c", "v", "b", "k", "m", ",", ".", "/", "RShift)", + "MO2", "LGui", "LAlt", "TT2", "LT6_SPC", "TT4", "Enter", "Space", "TT2", "RAlt", "RGui", "RCtrl", ] # 2 numpad = [ - ["`", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "]"], - ["", "DF0", "DF1", "XXX", "XXX", "MO3", "4", "4", "5", "6", "-", "="], - ["", "XXX", "XXX", "XXX", "XXX", "MO5", "1", "1", "2", "3", "\\", ""], - ["TG2", "", "", "", "Del", "", "", "BSpace", "0", "", "", ""], + "`", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "]", + "", "DF0", "DF1", "XXX", "XXX", "MO3", "4", "4", "5", "6", "-", "=", + "", "XXX", "XXX", "XXX", "XXX", "MO5", "1", "1", "2", "3", "\\", "", + "TG2", "", "", "", "Del", "", "", "BSpace", "0", "", "", "", ] # 3 fpad = [ - ["", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "XXX"], - ["", "XXX", "XXX", "XXX", "XXX", "MO3", "F4", "F4", "F5", "F6", "XXX", "XXX"], - ["", "XXX", "XXX", "XXX", "XXX", "XXX", "F1", "F1", "F2", "F3", "XXX", ""], - ["TG3", "", "", "", "", "", "F10", "F11", "F12", "", "", ""], + "", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "XXX", + "", "XXX", "XXX", "XXX", "XXX", "MO3", "F4", "F4", "F5", "F6", "XXX", "XXX", + "", "XXX", "XXX", "XXX", "XXX", "XXX", "F1", "F1", "F2", "F3", "XXX", "", + "TG3", "", "", "", "", "", "F10", "F11", "F12", "", "", "", ] # 4 movement = [ - ["Esc", "Esc", "Tab x", "Tab n", "CPg Dn", "CPg Dn", "Pg Down", "Home", "^ Arrow", "Insert", "SInsert", "Esc"], - ["", "Caps", "< Gui", "Gui Tab", "> Gui", "> Gui", "< Arrow", "< Arrow", "v Arrow", "> Arrow", "End", "Pr Scr"], - ["", "XXX", "XXX", "XXX", "CPg Up", "CPg Up", "Pg Up", "XXX", "v Arrow", "XXX", "App", ""], - ["TG4", "", "", "", "Del", "", "", "BSpace", "", "", "", ""], + "Esc", "Esc", "Tab x", "Tab n", "CPg Dn", "CPg Dn", "Pg Down", "Home", "^ Arrow", "Insert", "SInsert", "Esc", + "", "Caps", "< Gui", "Gui Tab", "> Gui", "> Gui", "< Arrow", "< Arrow", "v Arrow", "> Arrow", "End", "Pr Scr", + "", "XXX", "XXX", "XXX", "CPg Up", "CPg Up", "Pg Up", "XXX", "v Arrow", "XXX", "App", "", + "TG4", "", "", "", "Del", "", "", "BSpace", "", "", "", "", ] # 5 media = [ - ["", "XXX", "play/ps", "Vol +", "Vol +", "XXX", "XXX", "XXX", "XXX", "XXX", "_reset", "Power"], - ["", "XXX", "|<<", "Vol 0", ">>|", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "Sleep"], - ["", "XXX", "XXX", "Vol -", "Vol -", "MO5", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX"], - ["TG5", "", "", "", "", "", "", "", "", "", "", ""], + "", "XXX", "play/ps", "Vol +", "Vol +", "XXX", "XXX", "XXX", "XXX", "XXX", "_reset", "Power", + "", "XXX", "|<<", "Vol 0", ">>|", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", "Sleep", + "", "XXX", "XXX", "Vol -", "Vol -", "MO5", "XXX", "XXX", "XXX", "XXX", "XXX", "XXX", + "TG5", "", "", "", "", "", "", "", "", "", "", "", ] # 6 mouse = [ - ["", "acc1", "XXX", "XXX", "XXX", "XXX", "^ Wheel", "< Wheel", "^ Mouse", "> Wheel", "XXX", "XXX"], - ["", "acc2", "Mouse 3", "Mouse 2", "Mouse 1", "Mouse 1", "< Mouse", "< Mouse", "v Mouse", "> Mouse", "XXX", "XXX"], - ["", "acc0", "XXX", "XXX", "XXX", "XXX", "v Wheel", "XXX", "v Mouse", "XXX", "XXX", ""], - ["TG6", "", "", "", "", "", "", "", "", "", "", ""], + "", "acc1", "XXX", "XXX", "XXX", "XXX", "^ Wheel", "< Wheel", "^ Mouse", "> Wheel", "XXX", "XXX", + "", "acc2", "Mouse 3", "Mouse 2", "Mouse 1", "Mouse 1", "< Mouse", "< Mouse", "v Mouse", "> Mouse", "XXX", "XXX", + "", "acc0", "XXX", "XXX", "XXX", "XXX", "v Wheel", "XXX", "v Mouse", "XXX", "XXX", "", + "TG6", "", "", "", "", "", "", "", "", "", "", "", ] layers = [ diff --git a/keyboards/signum/3_0/elitec/keymaps/default/readme.md b/keyboards/signum/3_0/elitec/keymaps/default/readme.md index 54db18cd3..be8cc30e8 100644 --- a/keyboards/signum/3_0/elitec/keymaps/default/readme.md +++ b/keyboards/signum/3_0/elitec/keymaps/default/readme.md @@ -20,4 +20,5 @@ starting point to create your own layouts for the Signum 3.0 with - Attention 2: additional C functions need to be put into `km_template.txt` -Run `./generate_km.py` to regenerate `keymap.c`. +Run `./generate_km.py` to regenerate `keymap.c` and the JSON keymap +definition that should be copied to `qmk_configurator/public/keymaps`. -- cgit v1.2.3-70-g09d2 From aa65cd7a905370ab36f37a3562d3f53387fcae92 Mon Sep 17 00:00:00 2001 From: Jan Christoph Ebersbach Date: Wed, 8 May 2019 20:04:32 +0200 Subject: [Keymap] Signum3.0 Generate printable keymap (#5818) * Externalize generation of visual text keymap * Generate keymap in Asciidoc format for further processing * Remove artifacts from a2x call --- .../3_0/elitec/keymaps/default/generate_km.py | 59 +++++++++++++++++----- .../signum/3_0/elitec/keymaps/default/keymap.c | 21 +++++--- 2 files changed, 59 insertions(+), 21 deletions(-) (limited to 'keyboards/signum/3_0/elitec/keymaps/default/generate_km.py') diff --git a/keyboards/signum/3_0/elitec/keymaps/default/generate_km.py b/keyboards/signum/3_0/elitec/keymaps/default/generate_km.py index 9517a2f1f..cfa8edf57 100755 --- a/keyboards/signum/3_0/elitec/keymaps/default/generate_km.py +++ b/keyboards/signum/3_0/elitec/keymaps/default/generate_km.py @@ -56,7 +56,29 @@ def toLgd(s): return _translate(s)[1] -def writeKeymap(f_template, f_keymap, columns, rows): +def quoteC(text): + yield "/*" + for line in text: + yield " * " + line + yield " */\n" + + +def getKeymapText(id, layer, columns, rows): + keymap = [] + keymap.append("Layer %d" % id) + keymap.append("------------------------------------------------- -------------------------------------------------") + keymap.append("|{0}|{1}|{2}|{3}|{4}|{5}| |{6}|{7}|{8}|{9}|{10}|{11}|".format(*map(toLgd, layer[:12]))) + keymap.append("------------------------------------------------- -------------------------------------------------") + keymap.append("|{0}|{1}|{2}|{3}|{4}|{5}| |{6}|{7}|{8}|{9}|{10}|{11}|".format(*map(toLgd, layer[12:24]))) + keymap.append("------------------------------------------------- -------------------------------------------------") + keymap.append("|{0}|{1}|{2}|{3}|{4}|{5}| |{6}|{7}|{8}|{9}|{10}|{11}|".format(*map(toLgd, layer[24:36]))) + keymap.append("-----------------------------------------------------------------------------------------------------------------") + keymap.append(" {0} {1} {2} |{3}|{4}|{5}|{6}|{7}|{8}| {9} {10} {11}".format(*map(toLgd, layer[36:48])).rstrip()) + keymap.append(" -------------------------------------------------") + return keymap + + +def writeKeymap(f_template, f_keymap, layers, columns, rows): doCopy = False for line in f_template: @@ -78,19 +100,9 @@ def writeKeymap(f_template, f_keymap, columns, rows): f_keymap.write(u"\t[{0}] = {1}, // {2}\n".format(k, v, chr(int(v, 0)))) elif line.startswith("//"): doCopy = False - for layer, L in enumerate(layout.layers): + for layer, L in enumerate(layers): r_counter = rows - f_keymap.write("/* Layer %d\n" % layer) - f_keymap.write(" * ------------------------------------------------- -------------------------------------------------\n") - f_keymap.write(" * |{0}|{1}|{2}|{3}|{4}|{5}| |{6}|{7}|{8}|{9}|{10}|{11}|\n".format(*map(toLgd, L[:12]))) - f_keymap.write(" * ------------------------------------------------- -------------------------------------------------\n") - f_keymap.write(" * |{0}|{1}|{2}|{3}|{4}|{5}| |{6}|{7}|{8}|{9}|{10}|{11}|\n".format(*map(toLgd, L[12:24]))) - f_keymap.write(" * ------------------------------------------------- -------------------------------------------------\n") - f_keymap.write(" * |{0}|{1}|{2}|{3}|{4}|{5}| |{6}|{7}|{8}|{9}|{10}|{11}|\n".format(*map(toLgd, L[24:36]))) - f_keymap.write(" * -----------------------------------------------------------------------------------------------------------------\n") - f_keymap.write(" * {0} {1} {2} |{3}|{4}|{5}|{6}|{7}|{8}| {9} {10} {11}".format(*map(toLgd, L[36:48])).rstrip()+"\n") - f_keymap.write(" * -------------------------------------------------\n") - f_keymap.write(" */\n") + f_keymap.write('\n'.join(quoteC(getKeymapText(layer, L, columns, rows)))) l_code = '\tLAYOUT_ortho_4x12(\n' for r in range(r_counter): @@ -123,6 +135,20 @@ def getKeymapJSON(keyboard, keymap, layout, layers): }, sort_keys=True, indent=4) +def getKeymapAsciidoc(title, layers, columns, rows): + yield '= ' + title + yield '' + for id, layer in enumerate(layers): + keymap = getKeymapText(id, layer, columns, rows) + if len(keymap): + yield '.' + keymap[0] + yield '--------------------------' + for line in keymap[1:]: + yield ' ' + line + yield '--------------------------' + yield '' + + def layersToKC(layers): return [list(map(toKC, layer)) for layer in layers] @@ -147,7 +173,7 @@ def pathToKeyboard(path): if __name__ == "__main__": with open("km_template.txt", mode="r") as f_template: with open("keymap.c", mode="w", encoding='utf-8') as f_keymap: - writeKeymap(f_template, f_keymap, columns=12, rows=4) + writeKeymap(f_template, f_keymap, layout.layers, columns=12, rows=4) abspath = os.path.dirname(os.path.abspath(__file__)) keyboard = list(reversed(list(pathToKeyboard(abspath)))) @@ -161,3 +187,8 @@ if __name__ == "__main__": keyboard_layout, layersToKC(layout.layers)) ) + + with open("keymap.adoc", mode="w") as f_keymapasciidoc: + f_keymapasciidoc.write('\n'.join(getKeymapAsciidoc('Signum 3.0 %s_%s' % ('_'.join(keyboard), keymap), layout.layers, columns=12, rows=4))) + print("Run the following command to generate a PDF from the keymap") + print("a2x -f pdf --xsltproc-opts '--stringparam page.orientation landscape --stringparam body.font.master 12' --fop -v keymap.adoc") diff --git a/keyboards/signum/3_0/elitec/keymaps/default/keymap.c b/keyboards/signum/3_0/elitec/keymaps/default/keymap.c index bd6254524..511be8c0d 100644 --- a/keyboards/signum/3_0/elitec/keymaps/default/keymap.c +++ b/keyboards/signum/3_0/elitec/keymaps/default/keymap.c @@ -623,7 +623,8 @@ const uint32_t PROGMEM unicode_map[] = { const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { -/* Layer 0 +/* + * Layer 0 * ------------------------------------------------- ------------------------------------------------- * | Tab | q | w | e | r | t | | y | u | i | o | p | [ | * ------------------------------------------------- ------------------------------------------------- @@ -641,7 +642,8 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { KC_LCTL, KC_LALT, KC_LGUI, TT(2), LT(6,KC_SPC), LT(4,KC_DEL), LT(4,KC_ENT), KC_SPC, LT(2,KC_BSPC), KC_RGUI, KC_RALT, KC_RCTL ), -/* Layer 1 +/* + * Layer 1 * ------------------------------------------------- ------------------------------------------------- * | Tab | q | w | f | p | g | | j | l | u | y | ; | [ | * ------------------------------------------------- ------------------------------------------------- @@ -659,7 +661,8 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { KC_LCTL, KC_LALT, KC_LGUI, TT(2), LT(6,KC_SPC), LT(4,KC_DEL), LT(4,KC_ENT), KC_SPC, LT(2,KC_BSPC), KC_RGUI, KC_RALT, KC_RCTL ), -/* Layer 2 +/* + * Layer 2 * ------------------------------------------------- ------------------------------------------------- * | ` | 1 | 2 | 3 | 4 | 5 | | 6 | 7 | 8 | 9 | 0 | ] | * ------------------------------------------------- ------------------------------------------------- @@ -677,7 +680,8 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { TG(2), KC_TRNS, KC_TRNS, KC_TRNS, KC_DEL, KC_TRNS, KC_TRNS, KC_BSPC, KC_0, KC_TRNS, KC_TRNS, KC_TRNS ), -/* Layer 3 +/* + * Layer 3 * ------------------------------------------------- ------------------------------------------------- * | | F1 | F2 | F3 | F4 | F5 | | F6 | F7 | F8 | F9 | F10 | XXX | * ------------------------------------------------- ------------------------------------------------- @@ -695,7 +699,8 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { TG(3), KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS ), -/* Layer 4 +/* + * Layer 4 * ------------------------------------------------- ------------------------------------------------- * | Esc | Esc | Tab x | Tab n |CPg Dn |CPg Dn | |Pg Down| Home |^ Arrow|Insert |SInsert| Esc | * ------------------------------------------------- ------------------------------------------------- @@ -713,7 +718,8 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { TG(4), KC_TRNS, KC_TRNS, KC_TRNS, KC_DEL, KC_TRNS, KC_TRNS, KC_BSPC, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS ), -/* Layer 5 +/* + * Layer 5 * ------------------------------------------------- ------------------------------------------------- * | | XXX |play/ps| Vol + | Vol + | XXX | | XXX | XXX | XXX | XXX |_reset | Power | * ------------------------------------------------- ------------------------------------------------- @@ -731,7 +737,8 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { TG(5), KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS ), -/* Layer 6 +/* + * Layer 6 * ------------------------------------------------- ------------------------------------------------- * | | acc1 | XXX | XXX | XXX | XXX | |^ Wheel|< Wheel|^ Mouse|> Wheel| XXX | XXX | * ------------------------------------------------- ------------------------------------------------- -- cgit v1.2.3-70-g09d2