def addNode(self): # My First Node _input = [1, 2, 3] _output = [1] node1 = Node(self.scene, 'First Node', _input, _output) node2 = Node(self.scene, 'Second First Node', _input, _output) node3 = Node(self.scene, 'Third First Node', _input, _output) node1.setNodePos(-250, -250) node2.setNodePos(250, -250) # print('node1 id: ',id(node1)) # print('node2 id: ',id(node2)) # print('node3 id: ',id(node3)) Link1 = Link(self.scene, node1.outputs[0], node2.inputs[0], 2)
def deserializeFromClipboard(self, data): hashmap = {} # paste on mouse pointer view = self.scene.grScene.views()[0] mouse_scene_pos = view.last_scene_mouse_position # # claculate scene object + center minx, maxx, miny, maxy = 0, 0, 0, 0 for node_data in data['nodes']: x, y = node_data['pos_x'], node_data['pos_y'] if x < minx: minx = x if x > maxx: maxx = x if y < miny: miny = y if y > maxy: maxy = y bbox_center_x = (minx + maxx) / 2 bbox_center_y = (miny + maxy) / 2 center = view.mapToScene(view.rect().center()) # calculate offset offset_x = (mouse_scene_pos.x() - bbox_center_x) offset_y = (mouse_scene_pos.y() - bbox_center_y) if DEBUG: print('node_scene_clipboard ::', data) # create each node for node_data in data['nodes']: new_node = Node(self.scene) new_node.deserialize(node_data, hashmap, restore_id=False) # read just the new node's position pos = new_node.pos new_node.setNodePos(pos.x() + offset_x, pos.y() + offset_y) # create each links if 'links' in data: for link_data in data['links']: new_link = Link(self.scene) new_link.deserialize(link_data, hashmap, restore_id=False) # store history self.scene.history.storeHistory( 'node_scene_clipboard :: Pasted Elements in scene', setModified=True)