| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- """Functions to convert to and from QMK formats
- """
- from milc import cli
- def kle2qmk(kle):
- """Convert a KLE layout to QMK's layout format.
- """
- layout = []
- top_left_corner = None
- # Iterate through the KLE classifying keys by layout
- for row in kle:
- for key in row:
- if key['decal']:
- continue
- if key['label_style'] in [0, 4]:
- key_name = key['name'].split('\n')
- if len(key_name) == 7:
- matrix, _, _, alt_layout, layout_name, _, keycode = key_name
- elif len(key_name) == 5:
- matrix, _, _, alt_layout, layout_name = key_name
- cli.log.warning('Missing Keycode for key at matrix %s layout %s.', matrix, alt_layout)
- else:
- cli.log.error('Unknown label format: %s', repr(key['name']))
- continue
- else:
- cli.log.error('Unknown label style: %s', key['label_style'])
- continue
- matrix = list(map(int, matrix.split(',', 1)))
- qmk_key = {
- 'label': keycode,
- 'x': key['column'],
- 'y': key['row'],
- 'matrix': matrix,
- }
- if not top_left_corner and (not alt_layout or alt_layout.endswith(',0')):
- top_left_corner = key['column'], key['row']
- # Figure out what layout this key is part of
- # FIXME(skullydazed): In the future this will populate `layout_options` in info.json
- if alt_layout:
- alt_group, layout_index = map(int, alt_layout.split(',', 1))
- if layout_index != 0:
- continue
- # Set the key size
- if key['width'] != 1:
- qmk_key['w'] = key['width']
- if key['height'] != 1:
- qmk_key['h'] = key['height']
- layout.append(qmk_key)
- # Adjust the keys to account for the top-left corner
- for key in layout:
- key['x'] -= top_left_corner[0]
- key['y'] -= top_left_corner[1]
- return layout
|