diff options
| author | Cody Bender <50554676+cfbender@users.noreply.github.com> | 2019-11-12 21:55:41 -0700 |
|---|---|---|
| committer | skullydazed <skullydazed@users.noreply.github.com> | 2019-11-12 20:55:41 -0800 |
| commit | 7329c2d02d38f40a23d38f789de34057fd2acd42 (patch) | |
| tree | bb4e0640164b71d60714b964a72025517c2ade61 /lib/python/qmk/converter.py | |
| parent | 00fb1bd1f0550645997b61870d7d092494265a60 (diff) | |
| download | qmk_firmware-7329c2d02d38f40a23d38f789de34057fd2acd42.tar.gz qmk_firmware-7329c2d02d38f40a23d38f789de34057fd2acd42.zip | |
Add cli convert subcommand, from raw KLE to JSON (#6898)
* Add initial pass at KLE convert
* Add cli log on convert
* Move kle2xy, add absolute filepath arg support
* Add overwrite flag, and context sensitive conversion
* Update docs/cli.md
* Fix converter.py typo
* Add convert unit test
* Rename to kle2qmk
* Rename subcommand
* Rename subcommand to kle2json
* Change tests to cover rename
* Rename in __init__.py
* Update CLI docs with new subcommand name
* Fix from suggestions in PR #6898
* Help with cases of case sensitivity
* Update cli.md
* Use angle brackets to indicate required option
* Make the output text more accurate
Diffstat (limited to 'lib/python/qmk/converter.py')
| -rw-r--r-- | lib/python/qmk/converter.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/python/qmk/converter.py b/lib/python/qmk/converter.py new file mode 100644 index 000000000..bbd353131 --- /dev/null +++ b/lib/python/qmk/converter.py | |||
| @@ -0,0 +1,33 @@ | |||
| 1 | """Functions to convert to and from QMK formats | ||
| 2 | """ | ||
| 3 | from collections import OrderedDict | ||
| 4 | |||
| 5 | |||
| 6 | def kle2qmk(kle): | ||
| 7 | """Convert a KLE layout to QMK's layout format. | ||
| 8 | """ | ||
| 9 | layout = [] | ||
| 10 | |||
| 11 | for row in kle: | ||
| 12 | for key in row: | ||
| 13 | if key['decal']: | ||
| 14 | continue | ||
| 15 | |||
| 16 | qmk_key = OrderedDict( | ||
| 17 | label="", | ||
| 18 | x=key['column'], | ||
| 19 | y=key['row'], | ||
| 20 | ) | ||
| 21 | |||
| 22 | if key['width'] != 1: | ||
| 23 | qmk_key['w'] = key['width'] | ||
| 24 | if key['height'] != 1: | ||
| 25 | qmk_key['h'] = key['height'] | ||
| 26 | if 'name' in key and key['name']: | ||
| 27 | qmk_key['label'] = key['name'].split('\n', 1)[0] | ||
| 28 | else: | ||
| 29 | del (qmk_key['label']) | ||
| 30 | |||
| 31 | layout.append(qmk_key) | ||
| 32 | |||
| 33 | return layout | ||
