From 3e8d32951aab58ff39f3103a21f7643166f2329a Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Thu, 29 Jul 2021 07:20:43 -0400 Subject: [PATCH] Make helper script handle `fill` attributes for component color. --- helper.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/helper.py b/helper.py index 8239928b..909cb6a5 100755 --- a/helper.py +++ b/helper.py @@ -228,7 +228,7 @@ def create_module(slug, panel_filename=None, source_filename=None): raise UserException(f"Panel not found at {panel_filename}.") if os.path.exists(source_filename): - if input_default(f"{source_filename} already exists. Overwrite?", "n").lower() != "y": + if input_default(f"{source_filename} already exists. Overwrite? (y/n)", "n").lower() != "y": return # Read SVG XML @@ -296,10 +296,16 @@ def panel_to_components(tree): c['name'] = name # Get color + fill = el.get('fill') style = el.get('style') - color_match = re.search(r'fill:\S*#(.{6});', style) - color = color_match.group(1).lower() - c['color'] = color + if fill: + color_match = re.search(r'#(.{6})', fill) + color = color_match.group(1).lower() + elif style: + color_match = re.search(r'fill:\S*#(.{6});', style) + color = color_match.group(1).lower() + else: + raise UserException("Cannot get color of component") # Get position if el.tag == "{http://www.w3.org/2000/svg}rect":