|
|
@@ -852,40 +852,45 @@ class MantisNode:
|
|
|
for conn in self.hierarchy_connections:
|
|
|
conn.reset_execution_recursive()
|
|
|
|
|
|
+ def get_interface_signature(self):
|
|
|
+ interface_signature = (*self.signature[:-1], 'InputInterface')
|
|
|
+ ui_name = self.ui_signature[-1]
|
|
|
+ name = self.signature[-1]
|
|
|
+ if ui_name != name:
|
|
|
+ schema_suffix = ''
|
|
|
+ for i in range(len(name)):
|
|
|
+ if name[i] == ui_name[i]: continue
|
|
|
+ break
|
|
|
+ schema_suffix = name[i+1:]
|
|
|
+ interface_signature = (*interface_signature[:-1],
|
|
|
+ 'InputInterface'+schema_suffix)
|
|
|
+ return interface_signature
|
|
|
|
|
|
# TODO: make this MUCH more efficient!
|
|
|
# alternatively: call this ONCE when initializing the tree, precache results?
|
|
|
def apply_string_variables(self, string):
|
|
|
# We get the mContext, iterate through the signature, and string-replace variables
|
|
|
# this function should be called by evaluate_input if the result is a string.
|
|
|
- all_vars = {} # maybe the individual nodes should store this as a class member, too...
|
|
|
- name=""
|
|
|
- do_once = False
|
|
|
+ result=string; name=""
|
|
|
for i in range(len(self.signature[:-1])):
|
|
|
- if i == 0:
|
|
|
- continue
|
|
|
+ if i == 0: continue # it is None or AUTOGENERATED or something
|
|
|
name+=self.signature[i]
|
|
|
- prWhite(name)
|
|
|
- vars = self.mContext.string_variables.get(name, None)
|
|
|
- if vars is None:
|
|
|
- prRed("Can't get string variables for node")
|
|
|
- print (vars, type(vars))
|
|
|
- prRed (name)
|
|
|
- prWhite(self.mContext.string_variables.keys())
|
|
|
- for k in self.mContext.string_variables.keys():
|
|
|
- print (name == k)
|
|
|
- print (len(name), name,)
|
|
|
- print (len(k), k)
|
|
|
- raise RuntimeError
|
|
|
- continue
|
|
|
- elif not vars:
|
|
|
- prRed(self)
|
|
|
- for var_name, var_value in vars.items():
|
|
|
- do_once=True
|
|
|
- string = string.replace("$"+var_name, var_value)
|
|
|
- if do_once == False:
|
|
|
- raise NotImplementedError
|
|
|
- return string
|
|
|
+ vars = self.mContext.string_variables.get(name, None)
|
|
|
+ if vars is None:
|
|
|
+ raise RuntimeError("Can't get string variables for node")
|
|
|
+ elif not vars:
|
|
|
+ prWhite(f"INFO: No vars available for {self}")
|
|
|
+ var_name_keys = list(vars.keys()); var_name_keys.sort(key=lambda a : -len(a))
|
|
|
+ for var_name in var_name_keys:
|
|
|
+ var_value = vars[var_name]
|
|
|
+ if var_value is None:
|
|
|
+ interface_signature = self.get_interface_signature()
|
|
|
+ interface_node = self.base_tree.parsed_tree.get(interface_signature)
|
|
|
+ from .utilities import set_string_variables_at_execution
|
|
|
+ set_string_variables_at_execution(interface_node, var_name)
|
|
|
+ var_value = vars[var_name]
|
|
|
+ result = result.replace("$"+var_name, var_value)
|
|
|
+ return result
|
|
|
|
|
|
def evaluate_input(self, input_name, index=0) -> Any:
|
|
|
from .node_container_common import trace_single_line
|
|
|
@@ -894,17 +899,9 @@ class MantisNode:
|
|
|
# this trace() should give a key error if there is a problem
|
|
|
# it is NOT handled here because it should NOT happen - so I want the error message.
|
|
|
trace = trace_single_line(self, input_name, index)
|
|
|
- try:
|
|
|
- prop = trace[0][-1].parameters[trace[1].name] #trace[0] = the list of traced nodes; read its parameters
|
|
|
- except Exception as e:
|
|
|
- print (trace[0][-1])
|
|
|
- print (trace[1].name)
|
|
|
- print (trace[0][-1].parameters.keys())
|
|
|
- print (trace[0][-1].parameters.values())
|
|
|
- raise e
|
|
|
- if isinstance(prop, str) and "$" in prop:
|
|
|
- print (self, prop)
|
|
|
- prop = self.apply_string_variables(prop)
|
|
|
+ prop = trace[0][-1].parameters[trace[1].name] #trace[0] = the list of traced nodes; read its parameters
|
|
|
+ # apply the string variables if possible
|
|
|
+ if isinstance(prop, str) and "$" in prop: prop = self.apply_string_variables(prop)
|
|
|
return prop
|
|
|
|
|
|
def fill_parameters(self, ui_node=None) -> None:
|