def __init__(self): super(SetVariable_Node, self).__init__() self.title = 'set var' self.type_ = 'set variable node' self.package = 'built in' self.description = 'sets the value of a variable' exec_input_port = NodePort() exec_input_port.type_ = 'exec' self.inputs.append(exec_input_port) var_name_data_input_port = NodePort() var_name_data_input_port.type_ = 'data' var_name_data_input_port.label = 'var' var_name_data_input_port.widget_name = 'std line edit m' var_name_data_input_port.widget_pos = 'besides' self.inputs.append(var_name_data_input_port) val_name_data_input_port = NodePort() val_name_data_input_port.type_ = 'data' val_name_data_input_port.label = 'val' val_name_data_input_port.widget_name = 'std line edit m' val_name_data_input_port.widget_pos = 'besides' self.inputs.append(val_name_data_input_port) exec_output_port = NodePort() exec_output_port.type_ = 'exec' self.outputs.append(exec_output_port) val_output_port = NodePort() val_output_port.type_ = 'data' val_output_port.label = 'val' self.outputs.append(val_output_port)
def __init__(self): super(Result_Node, self).__init__() self.title = 'result' self.type_ = 'result' self.description = 'displays any value' self.package = 'built in' self.has_main_widget = True self.main_widget_class = Result_NodeInstance_MainWidget self.main_widget_pos = 'between ports' self.design_style = 'extended' data_input_port = NodePort() data_input_port.type_ = 'data' data_input_port.label = '' data_input_port.widget_name = None self.inputs.append(data_input_port)
def __init__(self): super(GetVar_Node, self).__init__() self.title = 'get var' self.type_ = 'get variable node' self.package = 'built in' self.description = 'gets the value of a variable' data_input_port = NodePort() data_input_port.type_ = 'data' data_input_port.widget_name = 'std line edit' data_input_port.widget_pos = 'besides' self.inputs.append(data_input_port) data_output_port = NodePort() data_output_port.type_ = 'data' data_output_port.label = 'val' self.outputs.append(data_output_port)
def parse_node(self, j_node, package_name, package_path): new_node = Node() # loading the node's specifications which get finally set below after importing the classes node_title = j_node['title'] node_class_name = j_node['class name'] node_description = j_node['description'] node_type = j_node['type'] node_has_main_widget = j_node['has main widget'] node_main_widget_pos = j_node[ 'widget position'] if node_has_main_widget else None node_design_style = j_node['design style'] node_color = j_node['color'] # Every node has a custom module name which differs from it's name to prevent import issues when using # multiple (different) Nodes with same titles. For further info: see node manager node_module_name = j_node['module name'] module_name_separator = '___' # CUSTOM CLASS IMPORTS ---------------------------------------------------------------------------- # creating all the necessary path variables here for all potentially imported classes # IMPORT NODE INSTANCE SUBCLASS node_instance_class_file_path = package_path + '/nodes/' + node_module_name + '/' node_instance_widgets_file_path = node_instance_class_file_path + '/widgets' node_instance_filename = node_module_name # the NI file's name is just the 'module name' new_node_instance_class = self.get_class_from_file( file_path=node_instance_class_file_path, file_name=node_instance_filename, class_name=node_class_name + '_NodeInstance') self.all_node_instance_classes[new_node] = new_node_instance_class # IMPORT MAIN WIDGET if node_has_main_widget: main_widget_filename = node_module_name + module_name_separator + 'main_widget' new_node.main_widget_class = self.get_class_from_file( file_path=node_instance_widgets_file_path, file_name=main_widget_filename, class_name=node_class_name + '_NodeInstance_MainWidget') # IMPORT CUSTOM INPUT WIDGETS # I need to create the dict for the node's potential custom input widgets already here self.custom_node_input_widget_classes[new_node] = {} for w_name in j_node['custom input widgets']: input_widget_filename = node_module_name + module_name_separator + w_name custom_widget_class = self.get_class_from_file( file_path=node_instance_widgets_file_path, file_name=input_widget_filename, class_name=w_name + '_PortInstanceWidget') self.custom_node_input_widget_classes[new_node][ w_name] = custom_widget_class # --------------------------------------------------------------------------------------------------- j_n_inputs = j_node['inputs'] inputs = [] num_inputs = len(j_n_inputs) for ii in range(num_inputs): # loading info j_input = j_n_inputs[ii] i_type = j_input['type'] i_label = j_input['label'] i_has_widget = None i_widget_name = '' i_widget_pos = None if i_type == 'data': i_has_widget = j_input['has widget'] if i_has_widget: i_widget_name = j_input['widget name'] i_widget_pos = j_input['widget position'] # creating port new_input = NodePort() new_input.type_ = i_type new_input.label = i_label if i_has_widget: new_input.widget_name = i_widget_name new_input.widget_pos = i_widget_pos inputs.append(new_input) j_n_outputs = j_node['outputs'] outputs = [] num_outputs = len(j_n_outputs) for oi in range(num_outputs): # loading info j_output = j_n_outputs[oi] o_type = j_output['type'] o_label = j_output['label'] # creating port new_output = NodePort() new_output.type_ = o_type new_output.label = o_label outputs.append(new_output) # setting the Node's attributes new_node.title = node_title new_node.description = node_description new_node.type_ = node_type new_node.package = package_name new_node.has_main_widget = node_has_main_widget if node_has_main_widget: new_node.main_widget_pos = node_main_widget_pos new_node.design_style = node_design_style new_node.color = QColor(node_color) new_node.inputs = inputs new_node.outputs = outputs self.custom_nodes.append(new_node) self.all_nodes.append(new_node)
def parse_nodes(self, j_str, package_path, package_name): import json # strict=False is necessary to allow 'control characters' like '\n' for newline when loading the json j_obj = json.loads(j_str, strict=False) Debugger.debug(j_obj['type']) if j_obj['type'] != 'vyScriptFP nodes package': return # package_title = j_obj['title'] # package_description = j_obj['description'] j_nodes_list = j_obj['nodes'] num_nodes = len(j_nodes_list) for ni in range(num_nodes): # new node j_node = j_nodes_list[ni] new_node = Node() node_title = j_node['title'] node_class_name = j_node['class name'] node_description = j_node['description'] node_type = j_node['type'] node_has_main_widget = j_node['has main widget'] node_main_widget_pos = j_node['widget position'] if node_has_main_widget else None node_design_style = j_node['design style'] node_color = j_node['color'] # every node has a custom module name which differs from it's name to prevent import issues when using # multiple (different) Nodes with same titles # FOR FURTHER EXPLANATION: see node manager node_module_name = j_node['module name'] module_name_separator = '___' # CUSTOM CLASS IMPORTS ---------------------------------------------------------------------------- # creating all the necessary path variables here for all potentially imported classes # IMPORT NODE INSTANCE SUBCLASS node_instance_class_file_path = package_path+'/nodes/'+node_module_name+'/' node_instance_widgets_file_path = node_instance_class_file_path+'/widgets' node_instance_filename = node_module_name # the NI file's name is just the 'module name' new_node_instance_class = self.get_class_from_file(file_path=node_instance_class_file_path, file_name=node_instance_filename, class_name=node_class_name+'_NodeInstance') self.all_node_instance_classes[new_node] = new_node_instance_class # IMPORT MAIN WIDGET if node_has_main_widget: main_widget_filename = node_module_name+module_name_separator+'main_widget' new_node.main_widget_class = self.get_class_from_file(file_path=node_instance_widgets_file_path, file_name=main_widget_filename, class_name=node_class_name+'_NodeInstance_MainWidget') # I need to create the dict for the node's potential custom input widgets already here self.custom_node_input_widget_classes[new_node] = {} for w_name in j_node['custom input widgets']: input_widget_filename = node_module_name+module_name_separator+w_name custom_widget_class = self.get_class_from_file(file_path=node_instance_widgets_file_path, file_name=input_widget_filename, class_name=w_name+'_PortInstanceWidget') self.custom_node_input_widget_classes[new_node][w_name] = custom_widget_class # note: the input widget classes get imported below in the loop # --------------------------------------------------------------------------------------------------- j_n_inputs = j_node['inputs'] inputs = [] num_inputs = len(j_n_inputs) for ii in range(num_inputs): j_input = j_n_inputs[ii] i_type = j_input['type'] i_label = j_input['label'] i_has_widget = None i_widget_type = '' i_widget_name = '' i_widget_pos = None if i_type == 'data': i_has_widget = j_input['has widget'] if i_has_widget: i_widget_type = j_input['widget type'] i_widget_pos = j_input['widget position'] if i_widget_type == 'custom widget': i_widget_name = j_input['widget name'] new_input = NodePort() new_input.type_ = i_type new_input.label = i_label if i_has_widget: new_input.widget_type = i_widget_type new_input.widget_name = i_widget_name if i_widget_pos: new_input.widget_pos = i_widget_pos else: new_input.widget_type = 'None' inputs.append(new_input) j_n_outputs = j_node['outputs'] outputs = [] num_outputs = len(j_n_outputs) for oi in range(num_outputs): j_output = j_n_outputs[oi] o_type = j_output['type'] o_label = j_output['label'] new_output = NodePort() new_output.type_ = o_type new_output.label = o_label outputs.append(new_output) new_node.title = node_title new_node.description = node_description new_node.type_ = node_type new_node.package = package_name new_node.has_main_widget = node_has_main_widget if node_has_main_widget: new_node.main_widget_pos = node_main_widget_pos new_node.design_style = node_design_style new_node.color = QColor(node_color) new_node.inputs = inputs new_node.outputs = outputs self.custom_nodes.append(new_node) self.all_nodes.append(new_node) Debugger.debug(len(self.custom_nodes), 'nodes imported')