diff --git a/build-scripts/gen-layout.py b/build-scripts/gen-layout.py index d028ff5..56adcf6 100755 --- a/build-scripts/gen-layout.py +++ b/build-scripts/gen-layout.py @@ -8,6 +8,15 @@ import sys # ----------------------------------------------------------------------------- +class Namespace(): + pass + +template = Namespace() +doc = Namespace() +info = Namespace() + +# ----------------------------------------------------------------------------- + def main(): arg_parser = argparse.ArgumentParser( description = "Generate a picture of the firmware's " @@ -19,33 +28,53 @@ def main(): args = arg_parser.parse_args(sys.argv[1:]) - args.template_file = './build-scripts/gen-layout--template.svg' + # constant file paths + args.template_svg_file = './build-scripts/gen_layout/template.svg' + args.template_js_file = './build-scripts/gen_layout/template.js' # normalize paths args.ui_info_file = os.path.abspath(args.ui_info_file) + args.template_svg_file = os.path.abspath(args.template_svg_file) + args.template_js_file = os.path.abspath(args.template_js_file) - # do stuff - doc = '' # to store the html document we're generating - template = open(args.template_file).read() - info = json.loads(open(args.ui_info_file).read()) + # set vars + doc.main = '' # to store the html document we're generating + template.svg = open(args.template_svg_file).read() + template.js = open(args.template_js_file).read() + info.all = json.loads(open(args.ui_info_file).read()) - matrix_positions = info['mappings']['matrix-positions'] - matrix_layout = info['mappings']['matrix-layout'] + info.matrix_positions = info.all['mappings']['matrix-positions'] + info.matrix_layout = info.all['mappings']['matrix-layout'] - # initial stuff - doc += """ + # prefix + doc.prefix = (""" - + -

It's sad that this doesn't look as pretty as it should... but it works for now, and I've spent too much time on it for the moment. Oh well.. maybe later :) .

+ + + -"""[1:-1] + - # not that smart at the moment... - for layout in matrix_layout: - template_copy = template +""")[1:-1] + + # suffix + doc.suffix = (""" + + + +""")[1:-1] + + # substitute into template + for (layout, layer) in zip( info.matrix_layout, + range(len(info.matrix_layout))): + svg = template.svg for (name, (code, press, release)) \ - in zip(matrix_positions, layout): + in zip(info.matrix_positions, layout): replace = '' if press == '&kbfun_jump_to_bootloader': replace = '[btldr]' @@ -54,11 +83,16 @@ def main(): else: replace = keycode_to_string.get(code, '[n/a]') - template_copy = re.sub(name, replace, template_copy) + svg = re.sub( + '>'+name+'<', '>'+replace+'<', svg ) + svg = re.sub( + r"\('(" + name + r".*)'\)", + r"('\1', " + str(layer) + r")", + svg ) - doc += template_copy + doc.main += svg - print(doc+'\n\n') + print(doc.prefix + doc.main + doc.suffix) # ----------------------------------------------------------------------------- # ----------------------------------------------------------------------------- diff --git a/build-scripts/gen_layout/template.js b/build-scripts/gen_layout/template.js new file mode 100644 index 0000000..ae1c21d --- /dev/null +++ b/build-scripts/gen_layout/template.js @@ -0,0 +1,4 @@ +function keyclick(position, layer) { + alert(position + ' ' + layer); +} + diff --git a/build-scripts/gen-layout--template.svg b/build-scripts/gen_layout/template.svg similarity index 100% rename from build-scripts/gen-layout--template.svg rename to build-scripts/gen_layout/template.svg