jchanvfx / NodeGraphQt

Node graph framework that can be re-implemented into applications that supports PySide2
http://chantonic.com/NodeGraphQt/
MIT License
1.29k stars 264 forks source link

NodeGraph.deserialize_session() doesn't respesct nodes layout #313

Closed aloytag closed 1 year ago

aloytag commented 1 year ago

After creating a graph (NodeGraph instance) and saving it with graph.serialize_session(), I load it again using graph.deserialize_session() and detect that the vertical nodes are now in horizontal layout.

It might be interesting if the node had a property with the configured layout. This way it could be possible to recover the layout direction after serializing and deserializing back. I tried to do it without changing the library code. So in my code I created a function the deserializes the graph, then checks for that property and uses node.set_layout_direction(1) when appropriate. It works but, however, port names show in vertical nodes (when it is supposed to be hidden). If I go deeper, I see the I have have to zoom (mouse scroll) before executing node.set_layout_direction(1). This way the node changes to vertical layout direction and port names remain hidden.

Regards.

aloytag commented 1 year ago

In order to test the port names problem, add this piece of code to the _deserialize() method in NodeGraph class definition, just before the return line:

for node in self.all_nodes():
    layout_vert = node.get_property('layout_vert')
    if layout_vert is True:
        node.set_layout_direction(1)

Then, create a graph with some nodes in a vertical layout. Create a layout_vert custom property with a True value in those vertical nodes. Save the graph using the serialize_session() method and then get it back with deserialize_session(). You will see that port names are not hidden in vertical nodes.

jchanvfx commented 1 year ago

Closing this issue as release v0.5.5 now has the session serialize the layout direction.