Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion NodeGraphQt/base/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def update_prop_bin(self, name, value):
prop_wgt = properties_wgt.get_widget(name)
# check if previous value is identical to current value,
# prevent signals from causing a infinite loop.
if prop_wgt.get_value() != value:
if prop_wgt and prop_wgt.get_value() != value:
prop_wgt.set_value(value)

def undo(self):
Expand Down Expand Up @@ -161,6 +161,8 @@ def undo(self):
[port.connect_to(p) for p in connected_ports]

def redo(self):
self.graph.properties_bin().remove_node(self.node)

for port, connected_ports in self.inputs:
[port.disconnect_from(p) for p in connected_ports]
for port, connected_ports in self.outputs:
Expand Down
36 changes: 14 additions & 22 deletions NodeGraphQt/base/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,12 +424,13 @@ def create_node(self, node_type, name=None, selected=True, color=None, pos=None)
return node
raise Exception('\n\n>> Cannot find node:\t"{}"\n'.format(node_type))

def add_node(self, node):
def add_node(self, node, pos=None):
"""
Add a node into the node graph.

Args:
node (NodeGraphQt.Node): node object.
pos (list[float]): node x,y position. (optional)
"""
assert isinstance(node, NodeObject), 'node must be a Node instance.'

Expand All @@ -449,7 +450,7 @@ def add_node(self, node):
node.model._graph_model = self.model
node.model.name = node.NODE_NAME
node.update()
self._undo_stack.push(NodeAddedCmd(self, node))
self._undo_stack.push(NodeAddedCmd(self, node, pos))

def delete_node(self, node):
"""
Expand Down Expand Up @@ -651,27 +652,17 @@ def _deserialize(self, data, relative_pos=False, pos=None):
NodeCls = self._node_factory.create_node_instance(identifier)
if NodeCls:
node = NodeCls()
node._graph = self

name = self.get_unique_name(n_data.get('name', node.NODE_NAME))
n_data['name'] = name

node.NODE_NAME = n_data.get('name', node.NODE_NAME)
# set properties.
for prop, val in node.model.properties.items():
for prop in node.model.properties.keys():
if prop in n_data.keys():
setattr(node.model, prop, n_data[prop])

node.model.set_property(prop, n_data[prop])
# set custom properties.
for prop, val in n_data.get('custom', {}).items():
if prop in node.model.custom_properties.keys():
node.model.custom_properties[prop] = val

node.update()
node.model.set_property(prop, val)

self._undo_stack.push(
NodeAddedCmd(self, node, n_data.get('pos'))
)
nodes[n_id] = node
self.add_node(node, n_data.get('pos'))

# build the connections.
for connection in data.get('connections', []):
Expand All @@ -693,9 +684,10 @@ def _deserialize(self, data, relative_pos=False, pos=None):
node_objs = list(nodes.values())
if relative_pos:
self._viewer.move_nodes([n.view for n in node_objs])
[setattr(n.model, 'pos', n.view.pos) for n in node_objs]
[setattr(n.model, 'pos', n.view.xy_pos) for n in node_objs]
elif pos:
self._viewer.move_nodes([n.view for n in node_objs], pos=pos)
[setattr(n.model, 'pos', n.view.xy_pos) for n in node_objs]

return node_objs

Expand Down Expand Up @@ -770,14 +762,14 @@ def paste_nodes(self):
Pastes nodes copied from the clipboard.
"""
clipboard = QtWidgets.QApplication.clipboard()
cb_string = clipboard.text()
if not cb_string:
cb_text = clipboard.text()
if not cb_text:
return

self._undo_stack.beginMacro('pasted nodes')
serial_data = json.loads(cb_string)
serial_data = json.loads(cb_text)
self.clear_selection()
nodes = self._deserialize(serial_data, True)
nodes = self._deserialize(serial_data, relative_pos=True)
[n.set_selected(True) for n in nodes]
self._undo_stack.endMacro()

Expand Down
2 changes: 1 addition & 1 deletion NodeGraphQt/base/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __get__(self, instance, owner):

class NodeObject(object):
"""
base skeleton class for all node objects.
base class for all node objects.

Args:
node (AbstractNodeItem): graphic item used for drawing.
Expand Down
2 changes: 1 addition & 1 deletion NodeGraphQt/widgets/node_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class AbstractNodeItem(QtWidgets.QGraphicsItem):
"""
The abstract base class of a node.
The abstract base class of a node item.
"""

def __init__(self, name='node', parent=None):
Expand Down
2 changes: 1 addition & 1 deletion NodeGraphQt/widgets/node_backdrop.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class BackdropSizer(QtWidgets.QGraphicsItem):
"""
Sizer item for resizing a backdrop node.
Sizer item for resizing a backdrop item.

Args:
parent (BackdropNodeItem): the parent node item.
Expand Down