Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Layout direction bug when duplicating nodes #398

Open
aloytag opened this issue Jan 7, 2024 · 1 comment
Open

Layout direction bug when duplicating nodes #398

aloytag opened this issue Jan 7, 2024 · 1 comment

Comments

@aloytag
Copy link

aloytag commented Jan 7, 2024

If the layout direction in a node is changed to vertical, then duplicating that node causes a strange behavior. For example, consider node_a in vertical layout. Then use the NodeGraph.duplicate_nodes() method to duplicate it. The result: The duplicated node and the original node (node_a) are both in horizontal layout.

Basic example case:

import sys
from Qt import QtWidgets
from NodeGraphQt import NodeGraph, BaseNode


class SimpleNode(BaseNode):
    __identifier__ = 'SimpleNode'
    NODE_NAME = 'SimpleNode'
    
    def __init__(self):
        super().__init__()
        
        self.add_input(name='', multi_input=True)
        self.add_output(name='')



if __name__=='__main__':
    app = QtWidgets.QApplication(sys.argv)
    
    graph = NodeGraph()
    graph.register_node(SimpleNode)
    
    graph_widget = graph.widget
    graph_widget.show()
    
    node_a = graph.create_node('SimpleNode.SimpleNode', name='Node 0')
    node_a.set_layout_direction(1)  # Vertical layout
    
    graph.duplicate_nodes([node_a])
    
    app.exec_()

I think the problem may be in one of the NodeGraph._serialize() or NodeGraph._deserialize() methods. I've been using these methods in my application in order to save and load a graph into/from a file, and have been experiencing some errors with layout directions.

Regards.

NodeGraphQt version: 0.6.29
Qt.py version: 1.3.7
PySide2 version: 5.15.2.1
Python version: 3.9.2

@aloytag
Copy link
Author

aloytag commented Jan 7, 2024

I found the problem in NodeGraph._serialize() and NodeGraph._deserialize() methods.

Remove this line in NodeGraph._serialize():

serial_data['graph']['layout_direction'] = self.layout_direction()

With that line, the graph layout setting overwrites every node layout. But instead, we want to respect particular node layouts.

And add this line in NodeGraph._deserialize() when building the nodes:

node.set_layout_direction(n_data['layout_direction'])

This way, the new (deserialized) nodes copy the layout direction from the original (serialized) nodes.

Attached is a file with the modified methods.
modified_graph.zip

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

No branches or pull requests

2 participants