Skip to content

Conversation

@filip-dobrocky
Copy link
Contributor

@filip-dobrocky filip-dobrocky commented Mar 14, 2023

Hi,
is there a reason why paste_nodes() does not return node instances like duplicate_nodes() does? This small change takes care of that.

I find this possibility useful, because I am able to emit the node_created signal on those nodes and am able to check whether instances of the same type already exist in the graph and if so, to prevent pasting/duplicating of those nodes (in my application it does not make sense for certain nodes to be in the graph more than once...). That begs the question: shouldn't paste_nodes() and duplicate_nodes() emit node_created by default?

@jchanvfx
Copy link
Owner

Hi, @filip-dobrocky, thanks for the update, the paste_nodes() func not returning node objects might of been an oversight as for why they were not emitting the node_created signal I can't remember what the main reason was why I didn't add it but thinking about it now the node_created signal only emits a node object and not a list of nodes.

@jchanvfx jchanvfx merged commit b7e2086 into jchanvfx:master Mar 14, 2023
@filip-dobrocky
Copy link
Contributor Author

filip-dobrocky commented Mar 15, 2023

Thanks for accepting the change, and most of all, for creating this library!
This is the way I got around it, a signal is emitted for each node:

nodes = graph.duplicate_nodes(graph.selected_nodes()) if nodes is not None: for n in nodes: graph.node_created.emit(n) 

The way my app works is the graph is being evaluated in real-time, so essentially every time a connection is made/removed, a connected node is changed etc. So most of the logic is implemented via the port_connected and port_disconnected signals. Because of this, I needed to evaluate the graph also immediately when a session is loaded. I achieved it like this:

 def session_changed(self, session): nodes = self.graph.all_nodes() for n in nodes: self.graph.node_created.emit(n) if not isinstance(n, BaseNode): continue for input in n.inputs().values(): for output in input.connected_ports(): self.graph.port_connected.emit(input, output) 

So a signal is emitted for each created node and for each connection when a session is loaded from a file.

Now there wouldn't be need for any of this if those signals were emitted in the Graph._deserialize() method which is also used in the methods for duplication and pasting. So a signal could be emitted for every deserialized (created) node and for every connection.

But that is for your consideration, the way I am using the library might not be the "standard way". After all, the workarounds are not that big of a deal, I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants