def on_add_node(sender, data): """ The callback that creates a Heron.gui.node.Node in the node editor for the operation defined by the button calling the callback. :param sender: The button's node_name :param data: Not used :return: Nothing """ sender_name = dpg.get_item_label(sender) # Get corresponding operation operation = None for op in operations_list: if op.name == sender_name: operation = op break # Find how many other nodes there are already on the editor for the same operation num_of_same_nodes = 0 all_nodes = dpg.get_item_children(node_editor)[1] for n in all_nodes: name = dpg.get_item_label(n) if operation.name in name: num_of_same_nodes = num_of_same_nodes + 1 # Create the Node name = operation.name + '##{}'.format(num_of_same_nodes) n = Node(name=name, parent=node_editor) n.spawn_node_on_editor() n.starting_port = next(port_generator) nodes_list.append(n)
def get_attribute_id_from_label(label): all_editors_children = dpg.get_item_children(node_editor, 1) for node_id in all_editors_children: all_nodes_childern = dpg.get_item_children(node_id, slot=1) for child_id in all_nodes_childern: child_label = dpg.get_item_label(child_id) if child_label == label: return child_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 on_edit(self, item, data): item_label = dpg.get_item_label(item) row = int(item_label.split('_')[-2]) col = int(item_label.split('_')[-1]) id = dpg.get_value(self.rows_ids[f"##{self.name}_{row}_{1}"]) col_name = self.header[col] self.ssh_info[id][col_name] = dpg.get_value( self.rows_ids[f"##{self.name}_{row}_{col}"])
def connect(a, b): global node_connections sender_node = dpg.get_item_parent(a) sender_class = dpg.get_item_user_data(sender_node) receiver_node = dpg.get_item_parent(b) receiver_class = dpg.get_item_user_data(receiver_node) # check a_key = (type(sender_class), dpg.get_item_label(a)) b_key = (type(receiver_class), dpg.get_item_label(b)) if a_key in node_connections and b_key in node_connections[a_key]: setattr(receiver_class, dpg.get_item_label(b), sender_class) sender_class.connect_output(receiver_node) receiver_class.update() return True return False
def on_del_pressed(sender, key_value): indices_to_remove = [] for node in dpg.get_selected_nodes(node_editor=node_editor): node_name = dpg.get_item_label(node) for i in np.arange(len(nodes_list) - 1, -1, -1): if nodes_list[i].name == node_name: indices_to_remove.append(i) for i in indices_to_remove: node = nodes_list[i] for link in node.links_list: delete_link(None, link) nodes_list[i].remove_from_editor() del nodes_list[i] for link in dpg.get_selected_links(node_editor=node_editor): delete_link(None, link)
def resize_r(node, w, h): def _compute_value(input_value, total_size): if input_value < 0: return total_size + input_value if input_value > 1: return input_value return int(input_value * total_size) label = dpg.get_item_label(node) if label in layout: if layout[label][0] != 0: dpg.set_item_width(node, _compute_value(layout[label][0], w)) if layout[label][1] != 0: dpg.set_item_height(node, _compute_value(layout[label][1], h)) children = dpg.get_item_children(node) for item, value in children.items(): if len(value): for v in value: resize_r(v, w, h)
def resize_all(w, h): for win in dpg.get_windows(): if dpg.get_item_label(win) == 'Main': resize_r(win, w, h)