Browse Source

Allow class name to be provided in SVG panel metadata.

pull/1545/head
Xavier Shay 5 years ago
parent
commit
13b3fa5b0a
1 changed files with 21 additions and 8 deletions
  1. +21
    -8
      helper.py

+ 21
- 8
helper.py View File

@@ -32,12 +32,19 @@ def is_valid_slug(slug):




def slug_to_identifier(slug): def slug_to_identifier(slug):
slug = slug.split('|')[0]
if len(slug) == 0 or slug[0].isdigit(): if len(slug) == 0 or slug[0].isdigit():
slug = "_" + slug slug = "_" + slug
slug = slug[0].upper() + slug[1:] slug = slug[0].upper() + slug[1:]
slug = slug.replace('-', '_') slug = slug.replace('-', '_')
return slug return slug


def slug_to_class(slug):
tokens = slug.split('|')
if len(tokens) > 1:
return tokens[1]
else:
return None


def create_plugin(slug, plugin_dir=None): def create_plugin(slug, plugin_dir=None):
# Check slug # Check slug
@@ -284,6 +291,8 @@ def panel_to_components(tree):
name = el.get('{http://www.inkscape.org/namespaces/inkscape}label') name = el.get('{http://www.inkscape.org/namespaces/inkscape}label')
if name is None: if name is None:
name = el.get('id') name = el.get('id')
c['class'] = slug_to_class(name)

name = slug_to_identifier(name).upper() name = slug_to_identifier(name).upper()
c['name'] = name c['name'] = name


@@ -418,45 +427,49 @@ struct {identifier}Widget : ModuleWidget {{
if len(components['params']) > 0: if len(components['params']) > 0:
source += "\n" source += "\n"
for c in components['params']: for c in components['params']:
class_name = c['class'] if c['class'] else "RoundBlackKnob"
if 'x' in c: if 'x' in c:
source += f""" source += f"""
addParam(createParam<RoundBlackKnob>(mm2px(Vec({c['x']}, {c['y']})), module, {identifier}::{c['name']}_PARAM));"""
addParam(createParam<{class_name}>(mm2px(Vec({c['x']}, {c['y']})), module, {identifier}::{c['name']}_PARAM));"""
else: else:
source += f""" source += f"""
addParam(createParamCentered<RoundBlackKnob>(mm2px(Vec({c['cx']}, {c['cy']})), module, {identifier}::{c['name']}_PARAM));"""
addParam(createParamCentered<{class_name}>(mm2px(Vec({c['cx']}, {c['cy']})), module, {identifier}::{c['name']}_PARAM));"""


# Inputs # Inputs
if len(components['inputs']) > 0: if len(components['inputs']) > 0:
source += "\n" source += "\n"
for c in components['inputs']: for c in components['inputs']:
class_name = c['class'] if c['class'] else "PJ301MPort"
if 'x' in c: if 'x' in c:
source += f""" source += f"""
addInput(createInput<PJ301MPort>(mm2px(Vec({c['x']}, {c['y']})), module, {identifier}::{c['name']}_INPUT));"""
addInput(createInput<{class_name}>(mm2px(Vec({c['x']}, {c['y']})), module, {identifier}::{c['name']}_INPUT));"""
else: else:
source += f""" source += f"""
addInput(createInputCentered<PJ301MPort>(mm2px(Vec({c['cx']}, {c['cy']})), module, {identifier}::{c['name']}_INPUT));"""
addInput(createInputCentered<{class_name}>(mm2px(Vec({c['cx']}, {c['cy']})), module, {identifier}::{c['name']}_INPUT));"""


# Outputs # Outputs
if len(components['outputs']) > 0: if len(components['outputs']) > 0:
source += "\n" source += "\n"
for c in components['outputs']: for c in components['outputs']:
class_name = c['class'] if c['class'] else "PJ301MPort"
if 'x' in c: if 'x' in c:
source += f""" source += f"""
addOutput(createOutput<PJ301MPort>(mm2px(Vec({c['x']}, {c['y']})), module, {identifier}::{c['name']}_OUTPUT));"""
addOutput(createOutput<{class_name}>(mm2px(Vec({c['x']}, {c['y']})), module, {identifier}::{c['name']}_OUTPUT));"""
else: else:
source += f""" source += f"""
addOutput(createOutputCentered<PJ301MPort>(mm2px(Vec({c['cx']}, {c['cy']})), module, {identifier}::{c['name']}_OUTPUT));"""
addOutput(createOutputCentered<{class_name}>(mm2px(Vec({c['cx']}, {c['cy']})), module, {identifier}::{c['name']}_OUTPUT));"""


# Lights # Lights
if len(components['lights']) > 0: if len(components['lights']) > 0:
source += "\n" source += "\n"
for c in components['lights']: for c in components['lights']:
class_name = c['class'] if c['class'] else "MediumLight<RedLight>"
if 'x' in c: if 'x' in c:
source += f""" source += f"""
addChild(createLight<MediumLight<RedLight>>(mm2px(Vec({c['x']}, {c['y']})), module, {identifier}::{c['name']}_LIGHT));"""
addChild(createLight<{class_name}>(mm2px(Vec({c['x']}, {c['y']})), module, {identifier}::{c['name']}_LIGHT));"""
else: else:
source += f""" source += f"""
addChild(createLightCentered<MediumLight<RedLight>>(mm2px(Vec({c['cx']}, {c['cy']})), module, {identifier}::{c['name']}_LIGHT));"""
addChild(createLightCentered<{class_name}>(mm2px(Vec({c['cx']}, {c['cy']})), module, {identifier}::{c['name']}_LIGHT));"""


# Widgets # Widgets
if len(components['widgets']) > 0: if len(components['widgets']) > 0:


Loading…
Cancel
Save