summaryrefslogtreecommitdiffstats
path: root/lib/python/qmk/keymap.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/python/qmk/keymap.py')
-rw-r--r--lib/python/qmk/keymap.py19
1 files changed, 15 insertions, 4 deletions
diff --git a/lib/python/qmk/keymap.py b/lib/python/qmk/keymap.py
index b91ba89bed..69cdc8d5b5 100644
--- a/lib/python/qmk/keymap.py
+++ b/lib/python/qmk/keymap.py
@@ -1,6 +1,5 @@
"""Functions that help you work with QMK keymaps.
"""
-import os
from pathlib import Path
import qmk.path
@@ -11,7 +10,7 @@ DEFAULT_KEYMAP_C = """#include QMK_KEYBOARD_H
/* THIS FILE WAS GENERATED!
*
- * This file was generated by qmk-compile-json. You may or may not want to
+ * This file was generated by qmk json2c. You may or may not want to
* edit it directly.
*/
@@ -39,6 +38,15 @@ def template(keyboard):
return DEFAULT_KEYMAP_C
+def _strip_any(keycode):
+ """Remove ANY() from a keycode.
+ """
+ if keycode.startswith('ANY(') and keycode.endswith(')'):
+ keycode = keycode[4:-1]
+
+ return keycode
+
+
def generate(keyboard, layout, layers):
"""Returns a keymap.c for the specified keyboard, layout, and layers.
@@ -53,9 +61,12 @@ def generate(keyboard, layout, layers):
An array of arrays describing the keymap. Each item in the inner array should be a string that is a valid QMK keycode.
"""
layer_txt = []
+
for layer_num, layer in enumerate(layers):
if layer_num != 0:
layer_txt[-1] = layer_txt[-1] + ','
+
+ layer = map(_strip_any, layer)
layer_keys = ', '.join(layer)
layer_txt.append('\t[%s] = %s(%s)' % (layer_num, layout, layer_keys))
@@ -115,7 +126,7 @@ def list_keymaps(keyboard_name):
while kb_path != keyboards_dir:
keymaps_dir = kb_path / "keymaps"
if keymaps_dir.exists():
- names = names.union([keymap for keymap in os.listdir(str(keymaps_dir)) if (keymaps_dir / keymap / "keymap.c").is_file()])
+ names = names.union([keymap for keymap in keymaps_dir.iterdir() if (keymaps_dir / keymap / "keymap.c").is_file()])
kb_path = kb_path.parent
# if community layouts are supported, get them
@@ -123,6 +134,6 @@ def list_keymaps(keyboard_name):
for layout in rules_mk["LAYOUTS"].split():
cl_path = Path.cwd() / "layouts" / "community" / layout
if cl_path.exists():
- names = names.union([keymap for keymap in os.listdir(str(cl_path)) if (cl_path / keymap / "keymap.c").is_file()])
+ names = names.union([keymap for keymap in cl_path.iterdir() if (cl_path / keymap / "keymap.c").is_file()])
return sorted(names)