def add_link(self, end1: NodeAttribute, end2: NodeAttribute) -> Optional[NodeLink]: """Adds a link between two :class:`.NodeAttribute` objects. Returns: A :class:`.NodeLink` representing the link that was created, or ``None`` if the link was invalid. """ dpgcore.add_node_link(self.id, end1.id, end2.id) return _get_link(end1, end2)
def create_ui_node(self, parent): y = IncludeNode.levels[self.level] IncludeNode.levels[self.level] += 80 with dpg.node(label=self.name, pos=(250*self.level, y), parent=editor_id): if self.level > 0: with dpg.node_attribute(label=self.name + "-in") as node_from_id: dpg.add_text("from") if len(self.links) > 0: with dpg.node_attribute(label=self.name + "-out", attribute_type=dpg.mvNode_Attr_Output) as node_out_id: dpg.add_text("Includes:") if parent != 0: dpg.add_node_link(parent, node_from_id, parent=editor_id) for i in range(0, len(self.links)): self.links[i].create_ui_node(node_out_id)
def on_link(sender, link): """ When a link is created it is stored as a topic_out in the node with the output and as a topic_in in the node with the input :param sender: The node editor (not used) :param link: The link list :return: Nothing """ global links_dict link0_name = dpg.get_item_label(link[0]) link1_name = dpg.get_item_label(link[1]) if link0_name in links_dict: inputs = links_dict[link0_name] if link1_name not in links_dict[link0_name]: inputs.append(link1_name) else: inputs = [link1_name] link_id = dpg.add_node_link(link[0], link[1], parent=sender, user_data={}) links_dict[link0_name] = inputs output_node_label = dpg.get_item_label(link[0]) input_node_label = dpg.get_item_label(link[1]) output_node = output_node_label.split('##')[-2] + '##' + output_node_label.split('##')[-1] input_node = input_node_label.split('##')[-2] + '##' + input_node_label.split('##')[-1] for n in nodes_list: if output_node == n.name: topic_out = '{}->{}'.format(output_node_label, input_node_label) n.add_topic_out(topic_out) n.links_list.append(link_id) user_data = dpg.get_item_user_data(link_id) user_data['topic_out'] = topic_out user_data['node_id_out'] = n.id dpg.set_item_user_data(link_id, user_data) if input_node == n.name: topic_in = '{}->{}'.format(output_node_label, input_node_label) n.add_topic_in(topic_in) n.links_list.append(link_id) user_data = dpg.get_item_user_data(link_id) user_data['topic_in'] = topic_in user_data['node_id_in'] = n.id dpg.set_item_user_data(link_id, user_data)
def _link_node(sender, app_data, user_data): if nodes.connect(app_data[0], app_data[1]): dpg.add_node_link(app_data[0], app_data[1], parent=sender, user_data=app_data)
def add_child(self, parent, child): dpg.add_node_link(self.uuid, child.uuid, parent=parent) child.set_parent(self) self._children.append(child)