Skip to content

Commit 71a1eca

Browse files
committed
updated disable_nodes func #291
1 parent 3f68aa8 commit 71a1eca

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

NodeGraphQt/base/graph.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1800,28 +1800,43 @@ def duplicate_nodes(self, nodes):
18001800

18011801
def disable_nodes(self, nodes, mode=None):
18021802
"""
1803-
Set weather to Disable or Enable specified nodes.
1803+
Toggle nodes to be either disabled or enabled state.
18041804
18051805
See Also:
18061806
:meth:`NodeObject.set_disabled`
18071807
18081808
Args:
1809-
nodes (list[NodeGraphQt.BaseNode]): list of node instances.
1810-
mode (bool): (optional) disable state of the nodes.
1809+
nodes (list[NodeGraphQt.BaseNode]): list of nodes.
1810+
mode (bool): (optional) override state of the nodes.
18111811
"""
18121812
if not nodes:
18131813
return
1814-
if mode is None:
1815-
mode = not nodes[0].disabled()
1814+
18161815
if len(nodes) == 1:
1816+
if mode is None:
1817+
mode = not nodes[0].disabled()
18171818
nodes[0].set_disabled(mode)
18181819
return
18191820

1820-
text = '{} ({}) nodes'.format(
1821-
{False: 'enable', True: 'disable'}[mode], len(nodes)
1822-
)
1821+
if mode is not None:
1822+
states = {False: 'enable', True: 'disable'}
1823+
text = '{} ({}) nodes'.format(states[mode], len(nodes))
1824+
self._undo_stack.beginMacro(text)
1825+
[n.set_disabled(mode) for n in nodes]
1826+
self._undo_stack.endMacro()
1827+
return
1828+
1829+
text = []
1830+
enabled_count = len([n for n in nodes if n.disabled()])
1831+
disabled_count = len([n for n in nodes if not n.disabled()])
1832+
if enabled_count > 0:
1833+
text.append('enabled ({})'.format(enabled_count))
1834+
if disabled_count > 0:
1835+
text.append('disabled ({})'.format(disabled_count))
1836+
text = ' / '.join(text) + ' nodes'
1837+
18231838
self._undo_stack.beginMacro(text)
1824-
[n.set_disabled(mode) for n in nodes]
1839+
[n.set_disabled(not n.disabled()) for n in nodes]
18251840
self._undo_stack.endMacro()
18261841

18271842
def use_OpenGL(self):

0 commit comments

Comments
 (0)