2
from bee.segments import *
4
from ..models import nodeio
5
from bee.types import stringtupleparser
7
class _python_base(bee.worker):
10
f.code.name = "Python code"
11
f.code.type = "pythoncode"
12
f.persistent.name = "Persistent"
13
f.persistent.tooltip = "Output values persist between invocations"
14
f.memberorder = "persistent", "code"
16
raise NotImplementedError("sparta.processors.python has not been implemented yet")
19
"""A snippet of custom Python code.
20
Activated by trigger. Can have any number of pull inputs and any number of outputs, which can be push, pull or trigger.
21
When the Python processor is activated, all inputs are pulled in, and made available to the code as variables of the same name.
22
If persistent, previous pull output values are likewise added.
23
After the code has run, its locals() are inspected for output variables.
24
All pull output variables must be set (unless persistent).
25
If a push output variable has been set, it is fired towards its targets when the processor has finished.
26
If a trigger output variable has been set to True, it is fired towards its targets when the processor has finished"""
28
"inputs" : "NodeIOArray",
29
"outputs" : "AdvancedNodeIOArray",
30
"autocreate" : {"inputs": Spyder.NodeIOArray(), "outputs" : Spyder.AdvancedNodeIOArray()},
34
f.inputs.name = "Inputs"
36
f.inputs.count_from_one = True
37
f.inputs.form = "soft"
38
f.inputs.arraymanager = "dynamic"
40
f.outputs.name = "Outputs"
42
f.outputs.count_from_one = True
43
f.outputs.form = "soft"
44
f.outputs.arraymanager = "dynamic"
46
def __new__(cls, inputs, outputs):
48
reserved = ("trig", "code", "code_parameter_", "persistent", "persistent_parameter_", "form")
50
if inp.ioname in reserved: raise ValueError("Reserved input name: %s" % inp.ioname)
51
if inp.ioname in ionames: raise ValueError("Duplicate input name: %s" % inp.ioname)
52
ionames.add(inp.ioname)
54
if outp.ioname in reserved: raise ValueError("Reserved output name: %s" % outp.ioname)
55
if outp.ioname in ionames: raise ValueError("Duplicate input/output name: %s" % outp.ioname)
56
ionames.add(outp.ioname)
58
"trig": antenna("push", "trigger"),
59
"code": variable("str"),
60
"persistent": variable("bool"),
62
dic["code_parameter_"] = parameter(dic["code"], "")
63
dic["persistent_parameter_"] = parameter(dic["persistent"], False)
65
guiparams["trig"] = {"name" : "Trigger"}
66
guiparams["_memberorder"] = ["trig"]
72
if typ == "custom": typ = inp.customtype
73
if typ: typ = stringtupleparser(typ)
74
dic[name2] = antenna("pull", typ)
75
dic[name] = buffer("pull", typ)
76
guiparams[name2] = {"name": name}
79
conname = "con" + str(counter)
80
if conname not in ionames: break
81
dic[conname] = connect(name2, name)
87
guiparams[name2] = {"name": name}
88
if typ == "custom": typ = outp.customtype
89
if typ: typ = stringtupleparser(typ)
90
if outp.mode == "trigger":
91
dic[name2] = output("push", "trigger")
92
dic[name2+"trig_"] = triggerfunc(dic[name2])
93
dic[name] = variable("bool")
95
dic[name2] = output(outp.mode, typ)
96
dic[name] = buffer(outp.mode, typ)
99
conname = "con" + str(counter)
100
if conname not in ionames: break
101
dic[conname] = connect(name, name2)
103
dic["guiparams"] = guiparams
104
return type("python", (_python_base,), dic)