def _load_controls(self): from openalea.core.control.serialization import ControlLoader from openalea.core.service.control import register_control control_path = self.path / 'control.py' loader = ControlLoader() controls = loader.load(control_path) for control in controls: register_control(control)
def import_lpy_controls(filepath): if not path(filepath).isfile(): return control = dict() f = open(filepath, "r") script = f.read() f.close() if script is None: script = "" beginTag = LpyParsing.InitialisationBeginTag if not beginTag in script: return str(script), control else: txts = str(script).split(beginTag) new_script = txts[0] context_to_translate = txts[1] context = Lsystem().context() context.initialiseFrom(beginTag + context_to_translate) managers = get_managers() visualparameters = [] scalars = [] functions = [] curves = [] geoms = [] lpy_code_version = 1.0 if context.has_key("__lpy_code_version__"): lpy_code_version = context["__lpy_code_version__"] if context.has_key("__scalars__"): scalars_ = context["__scalars__"] scalars = [ProduceScalar(v) for v in scalars_] if context.has_key("__functions__") and lpy_code_version <= 1.0: functions = context["__functions__"] for n, c in functions: c.name = n functions = [c for n, c in functions] funcmanager = managers["Function"] geoms += [(funcmanager, func) for func in functions] if context.has_key("__curves__") and lpy_code_version <= 1.0: curves = context["__curves__"] for n, c in curves: c.name = n curves = [c for n, c in curves] curvemanager = managers["Curve2D"] geoms += [(curvemanager, curve) for curve in curves] if context.has_key("__parameterset__"): for panelinfo, objects in context["__parameterset__"]: for typename, obj in objects: visualparameters.append((managers[typename], obj)) for scalar in scalars: control[unicode(scalar.name)] = scalar.value for (manager, geom) in geoms: if geom != list(): control[geom.getName()] = geom for (manager, geom) in visualparameters: if geom != list(): control[geom.getName()] = geom new_controls = [] for name, value in control.items(): interfaces = guess_interface(value) if interfaces: new_controls.append(Control(name, interfaces[0], value)) try: control["color map"] = to_color(context.turtle.getColorList()) except AttributeError: pass else: new_controls.append(Control("color map", "IColorList", control["color map"])) for control in new_controls: register_control(control)
def import_lpy_controls(filepath): if not path(filepath).isfile(): return control = dict() f = open(filepath, 'r') script = f.read() f.close() if script is None: script = "" beginTag = LpyParsing.InitialisationBeginTag if not beginTag in script: return str(script), control else: txts = str(script).split(beginTag) new_script = txts[0] context_to_translate = txts[1] context = Lsystem().context() context.initialiseFrom(beginTag + context_to_translate) managers = get_managers() visualparameters = [] scalars = [] functions = [] curves = [] geoms = [] lpy_code_version = 1.0 if context.has_key('__lpy_code_version__'): lpy_code_version = context['__lpy_code_version__'] if context.has_key('__scalars__'): scalars_ = context['__scalars__'] scalars = [ProduceScalar(v) for v in scalars_] if context.has_key('__functions__') and lpy_code_version <= 1.0: functions = context['__functions__'] for n, c in functions: c.name = n functions = [c for n, c in functions] funcmanager = managers['Function'] geoms += [(funcmanager, func) for func in functions] if context.has_key('__curves__') and lpy_code_version <= 1.0: curves = context['__curves__'] for n, c in curves: c.name = n curves = [c for n, c in curves] curvemanager = managers['Curve2D'] geoms += [(curvemanager, curve) for curve in curves] if context.has_key('__parameterset__'): for panelinfo, objects in context['__parameterset__']: for typename, obj in objects: visualparameters.append((managers[typename], obj)) for scalar in scalars: control[unicode(scalar.name)] = scalar.value for (manager, geom) in geoms: if geom != list(): control[geom.getName()] = geom for (manager, geom) in visualparameters: if geom != list(): control[geom.getName()] = geom new_controls = [] for name, value in control.items(): interfaces = guess_interface(value) if interfaces: new_controls.append(Control(name, interfaces[0], value)) try: control["color map"] = to_color(context.turtle.getColorList()) except AttributeError: pass else: new_controls.append( Control("color map", 'IColorList', control["color map"])) for control in new_controls: register_control(control)