Skip to content

Commit ecc8a6d

Browse files
committed
node widget visibility undo logic #360
1 parent 174a89a commit ecc8a6d

File tree

5 files changed

+46
-25
lines changed

5 files changed

+46
-25
lines changed

NodeGraphQt/base/commands.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,33 @@ def redo(self):
103103
self.set_node_visible(self.visible)
104104

105105

106+
class NodeWidgetVisibleCmd(QtWidgets.QUndoCommand):
107+
"""
108+
Node widget visibility command.
109+
110+
Args:
111+
node (NodeGraphQt.NodeObject): node object.
112+
name (str): node widget name.
113+
visible (bool): initial visibility state.
114+
"""
115+
116+
def __init__(self, node, name, visible):
117+
QtWidgets.QUndoCommand.__init__(self)
118+
label = 'show' if visible else 'hide'
119+
self.setText('{} node widget "{}"'.format(label, name))
120+
self.view = node.view
121+
self.node_widget = self.view.get_widget(name)
122+
self.visible = visible
123+
124+
def undo(self):
125+
self.node_widget.setVisible(not self.visible)
126+
self.view.draw_node()
127+
128+
def redo(self):
129+
self.node_widget.setVisible(self.visible)
130+
self.view.draw_node()
131+
132+
106133
class NodeMovedCmd(QtWidgets.QUndoCommand):
107134
"""
108135
Node moved command.

NodeGraphQt/nodes/base_node.py

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
#!/usr/bin/python
22
from collections import OrderedDict
33

4-
from NodeGraphQt.base.commands import NodeVisibleCmd
4+
from NodeGraphQt.base.commands import NodeVisibleCmd, NodeWidgetVisibleCmd
55
from NodeGraphQt.base.node import NodeObject
66
from NodeGraphQt.base.port import Port
77
from NodeGraphQt.constants import NodePropWidgetEnum, PortTypeEnum
8-
from NodeGraphQt.errors import (PortError,
9-
PortRegistrationError,
10-
NodeWidgetError)
8+
from NodeGraphQt.errors import (
9+
PortError,
10+
PortRegistrationError,
11+
NodeWidgetError
12+
)
1113
from NodeGraphQt.qgraphics.node_base import NodeItem
12-
from NodeGraphQt.widgets.node_widgets import (NodeBaseWidget,
13-
NodeComboBox,
14-
NodeLineEdit,
15-
NodeCheckBox)
14+
from NodeGraphQt.widgets.node_widgets import (
15+
NodeBaseWidget,
16+
NodeCheckBox,
17+
NodeComboBox,
18+
NodeLineEdit
19+
)
1620

1721

1822
class BaseNode(NodeObject):
@@ -290,9 +294,6 @@ def hide_widget(self, name):
290294
"""
291295
Hide an embedded node widget.
292296
293-
Warnings:
294-
Undo is NOT yet supported for this function.
295-
296297
Args:
297298
name (str): node property name for the widget.
298299
@@ -301,20 +302,15 @@ def hide_widget(self, name):
301302
:meth:`BaseNode.show_widget`,
302303
:meth:`BaseNode.get_widget`
303304
"""
304-
# TODO: implement this logic to the undo stack.
305305
if not self.view.has_widget(name):
306306
return
307-
widget = self.view.get_widget(name)
308-
widget.hide()
309-
self.view.draw_node()
307+
undo_cmd = NodeWidgetVisibleCmd(self, name, visible=False)
308+
self.graph.undo_stack().push(undo_cmd)
310309

311310
def show_widget(self, name):
312311
"""
313312
Show an embedded node widget.
314313
315-
Warnings:
316-
Undo is NOT yet supported for this function.
317-
318314
Args:
319315
name (str): node property name for the widget.
320316
@@ -323,12 +319,10 @@ def show_widget(self, name):
323319
:meth:`BaseNode.hide_widget`,
324320
:meth:`BaseNode.get_widget`
325321
"""
326-
# TODO: implement this logic to the undo stack.
327322
if not self.view.has_widget(name):
328323
return
329-
widget = self.view.get_widget(name)
330-
widget.show()
331-
self.view.draw_node()
324+
undo_cmd = NodeWidgetVisibleCmd(self, name, visible=True)
325+
self.graph.undo_stack().push(undo_cmd)
332326

333327
def add_input(self, name='input', multi_input=False, display_name=True,
334328
color=None, locked=False, painter_func=None):

NodeGraphQt/pkg_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/python
22
# -*- coding: utf-8 -*-
3-
__version__ = '0.6.10'
3+
__version__ = '0.6.11'
44
__status__ = 'Work in Progress'
55
__license__ = 'MIT'
66

docs/custom_widgets.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Built-in Widgets
55

66
| The ``NodeGraphQt`` framework comes included with a few custom widgets.
77
8-
**Classes:**
8+
**Widget Types:**
99

1010
.. autosummary::
1111
NodeGraphQt.PropertiesBinWidget

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ script or checkout the :ref:`General Overview` section.
6262
:hidden:
6363
:caption: Widgets
6464
:name: wdgtstoc
65-
:maxdepth: 1
65+
:maxdepth: 2
6666

6767
custom_widgets
6868
node_widgets

0 commit comments

Comments
 (0)