From 590c6db929ed44c292f2750ed7d46b1f8e5fe49f Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Fri, 1 Dec 2023 08:06:20 -0300 Subject: [PATCH] [KiRi] Patching the JS to get the selected colors This approach isn't good, will look for a CSS solution --- kibot/out_kiri.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/kibot/out_kiri.py b/kibot/out_kiri.py index 20565c57..c14a255d 100644 --- a/kibot/out_kiri.py +++ b/kibot/out_kiri.py @@ -21,6 +21,7 @@ Dependencies: """ import datetime import pwd +import re import os from shutil import copy2 from subprocess import CalledProcessError @@ -47,6 +48,7 @@ PCB_IMG = ('') HASH_LOCAL = '_local_' +UNDEF_COLOR = '#DBDBDB' def get_cur_user(): @@ -136,7 +138,7 @@ class KiRiOptions(VariantOptions): if la._id in layer_id2color: la.color = layer_id2color[la._id] else: - la.color = "#000000" + la.color = UNDEF_COLOR def create_layers(self, f): template = self.load_html_template('layers', 11) @@ -251,7 +253,17 @@ class KiRiOptions(VariantOptions): copy2(os.path.join(src_dir, 'blank.svg'), os.path.join(web_dir, 'blank.svg')) copy2(os.path.join(src_dir, 'favicon.ico'), os.path.join(web_dir, 'favicon.ico')) copy2(os.path.join(src_dir, 'kiri.css'), os.path.join(web_dir, 'kiri.css')) - copy2(os.path.join(src_dir, 'kiri.js'), os.path.join(web_dir, 'kiri.js')) + # Patch the JS + with open(os.path.join(src_dir, 'kiri.js'), 'rt') as f: + code = f.read() + layer_color = "function layer_color(layer_id) {\n switch(layer_id) {\n" + for id, color in self._color_theme.layer_id2color.items(): + layer_color += f' case {id}: return "{color[:7]}";\n' + layer_color += f' default: return "{UNDEF_COLOR}";\n '+'}\n}\n' + logger.error('Replace') + code = re.sub('function layer_color(.*)color;.}', layer_color, code, flags=re.S) + with open(os.path.join(web_dir, 'kiri.js'), 'wt') as f: + f.write(code) def run(self, name): self.cache_dir = self._parent.output_dir