def parse_node(self, node_config, package_path, package_name): new_node = Node() # setting the Node's attributes new_node.title = node_config['title'] new_node.description = node_config['description'] new_node.type_ = node_config['type'] new_node.package = package_name new_node.has_main_widget = node_config['has main widget'] inputs_config = node_config['inputs'] inputs = [] num_inputs = len(inputs_config) for ii in range(num_inputs): input_config = inputs_config[ii] new_input = NodePort() new_input.type_ = input_config['type'] new_input.label = input_config['label'] inputs.append(new_input) outputs_config = node_config['outputs'] outputs = [] num_outputs = len(outputs_config) for oi in range(num_outputs): j_output = outputs_config[oi] new_output = NodePort() new_output.type_ = j_output['type'] new_output.label = j_output['label'] outputs.append(new_output) new_node.inputs = inputs new_node.outputs = outputs node_module_name = node_config['module name'] node_class_name = node_config['class 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_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.node_instance_classes[new_node] = new_node_instance_class if new_node.title.lower( ) == 'button' and new_node.package == 'std': # convenience feature for exec. buttons self.buttonNIClass = new_node_instance_class # --------------------------------------------------------------------------------------------------- return new_node
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')