Skip to content

Commit

Permalink
Merge pull request #388 from jchanvfx/bug_fixes_tweaks
Browse files Browse the repository at this point in the history
address issues from the last release.
  • Loading branch information
jchanvfx authored Sep 18, 2023
2 parents bea91e9 + f13d0c8 commit 1a6d3fc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
19 changes: 12 additions & 7 deletions NodeGraphQt/base/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -1660,7 +1660,8 @@ def clear_session(self):
"""
Clears the current node graph session.
"""
for n in self.all_nodes():
nodes = self.all_nodes()
for n in nodes:
if isinstance(n, BaseNode):
for p in n.input_ports():
if p.locked():
Expand All @@ -1670,7 +1671,7 @@ def clear_session(self):
if p.locked():
p.set_locked(False, connected_ports=False)
p.clear_connections()
self._undo_stack.push(NodeRemovedCmd(self, n))
self._undo_stack.push(NodesRemovedCmd(self, nodes))
self._undo_stack.clear()
self._model.session = ''

Expand Down Expand Up @@ -1819,9 +1820,12 @@ def _deserialize(self, data, relative_pos=False, pos=None):
allow_connection = any([not in_port.model.connected_ports,
in_port.model.multi_connection])
if allow_connection:
self._undo_stack.push(PortConnectedCmd(in_port, out_port))
self._undo_stack.push(
PortConnectedCmd(in_port, out_port, emit_signal=False)
)

# Run on_input_connected to ensure connections are fully set up after deserialization.
# Run on_input_connected to ensure connections are fully set up
# after deserialization.
in_node.on_input_connected(in_port, out_port)

node_objs = nodes.values()
Expand Down Expand Up @@ -2009,8 +2013,7 @@ def cut_nodes(self, nodes=None):
if isinstance(node, GroupNode) and node.is_expanded:
node.collapse()

self._undo_stack.push(NodeRemovedCmd(self, node))

self._undo_stack.push(NodesRemovedCmd(self, nodes))
self._undo_stack.endMacro()

def paste_nodes(self):
Expand Down Expand Up @@ -2681,7 +2684,9 @@ def _deserialize(self, data, relative_pos=False, pos=None):
out_port = out_node.outputs().get(pname) if out_node else None

if in_port and out_port:
self._undo_stack.push(PortConnectedCmd(in_port, out_port))
self._undo_stack.push(
PortConnectedCmd(in_port, out_port, emit_signal=False)
)

node_objs = list(nodes.values())
if relative_pos:
Expand Down
16 changes: 12 additions & 4 deletions NodeGraphQt/nodes/base_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,13 @@ def add_checkbox(self, name, label='', text='', state=False, tooltip=None,
#: redraw node to address calls outside the "__init__" func.
self.view.draw_node()

def hide_widget(self, name):
def hide_widget(self, name, push_undo=True):
"""
Hide an embedded node widget.
Args:
name (str): node property name for the widget.
push_undo (bool): register the command to the undo stack. (default: True)
See Also:
:meth:`BaseNode.add_custom_widget`,
Expand All @@ -316,14 +317,18 @@ def hide_widget(self, name):
if not self.view.has_widget(name):
return
undo_cmd = NodeWidgetVisibleCmd(self, name, visible=False)
self.graph.undo_stack().push(undo_cmd)
if push_undo:
self.graph.undo_stack().push(undo_cmd)
else:
undo_cmd.redo()

def show_widget(self, name):
def show_widget(self, name, push_undo=True):
"""
Show an embedded node widget.
Args:
name (str): node property name for the widget.
push_undo (bool): register the command to the undo stack. (default: True)
See Also:
:meth:`BaseNode.add_custom_widget`,
Expand All @@ -333,7 +338,10 @@ def show_widget(self, name):
if not self.view.has_widget(name):
return
undo_cmd = NodeWidgetVisibleCmd(self, name, visible=True)
self.graph.undo_stack().push(undo_cmd)
if push_undo:
self.graph.undo_stack().push(undo_cmd)
else:
undo_cmd.redo()

def add_input(self, name='input', multi_input=False, display_name=True,
color=None, locked=False, painter_func=None):
Expand Down
2 changes: 1 addition & 1 deletion NodeGraphQt/nodes/group_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def add_output(self, name='output', multi_output=True, display_name=True,

def delete_input(self, port):
if type(port) in [int, str]:
port = self.get_output(port)
port = self.get_input(port)
if port is None:
return

Expand Down

0 comments on commit 1a6d3fc

Please sign in to comment.