Skip to content

Commit

Permalink
Merge pull request #361 from jchanvfx/node_widget_visibility_undo_#360
Browse files Browse the repository at this point in the history
node widget visibility undo logic #360
  • Loading branch information
jchanvfx authored Jul 26, 2023
2 parents 174a89a + ecc8a6d commit 184d83a
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 25 deletions.
27 changes: 27 additions & 0 deletions NodeGraphQt/base/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,33 @@ def redo(self):
self.set_node_visible(self.visible)


class NodeWidgetVisibleCmd(QtWidgets.QUndoCommand):
"""
Node widget visibility command.
Args:
node (NodeGraphQt.NodeObject): node object.
name (str): node widget name.
visible (bool): initial visibility state.
"""

def __init__(self, node, name, visible):
QtWidgets.QUndoCommand.__init__(self)
label = 'show' if visible else 'hide'
self.setText('{} node widget "{}"'.format(label, name))
self.view = node.view
self.node_widget = self.view.get_widget(name)
self.visible = visible

def undo(self):
self.node_widget.setVisible(not self.visible)
self.view.draw_node()

def redo(self):
self.node_widget.setVisible(self.visible)
self.view.draw_node()


class NodeMovedCmd(QtWidgets.QUndoCommand):
"""
Node moved command.
Expand Down
38 changes: 16 additions & 22 deletions NodeGraphQt/nodes/base_node.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
#!/usr/bin/python
from collections import OrderedDict

from NodeGraphQt.base.commands import NodeVisibleCmd
from NodeGraphQt.base.commands import NodeVisibleCmd, NodeWidgetVisibleCmd
from NodeGraphQt.base.node import NodeObject
from NodeGraphQt.base.port import Port
from NodeGraphQt.constants import NodePropWidgetEnum, PortTypeEnum
from NodeGraphQt.errors import (PortError,
PortRegistrationError,
NodeWidgetError)
from NodeGraphQt.errors import (
PortError,
PortRegistrationError,
NodeWidgetError
)
from NodeGraphQt.qgraphics.node_base import NodeItem
from NodeGraphQt.widgets.node_widgets import (NodeBaseWidget,
NodeComboBox,
NodeLineEdit,
NodeCheckBox)
from NodeGraphQt.widgets.node_widgets import (
NodeBaseWidget,
NodeCheckBox,
NodeComboBox,
NodeLineEdit
)


class BaseNode(NodeObject):
Expand Down Expand Up @@ -290,9 +294,6 @@ def hide_widget(self, name):
"""
Hide an embedded node widget.
Warnings:
Undo is NOT yet supported for this function.
Args:
name (str): node property name for the widget.
Expand All @@ -301,20 +302,15 @@ def hide_widget(self, name):
:meth:`BaseNode.show_widget`,
:meth:`BaseNode.get_widget`
"""
# TODO: implement this logic to the undo stack.
if not self.view.has_widget(name):
return
widget = self.view.get_widget(name)
widget.hide()
self.view.draw_node()
undo_cmd = NodeWidgetVisibleCmd(self, name, visible=False)
self.graph.undo_stack().push(undo_cmd)

def show_widget(self, name):
"""
Show an embedded node widget.
Warnings:
Undo is NOT yet supported for this function.
Args:
name (str): node property name for the widget.
Expand All @@ -323,12 +319,10 @@ def show_widget(self, name):
:meth:`BaseNode.hide_widget`,
:meth:`BaseNode.get_widget`
"""
# TODO: implement this logic to the undo stack.
if not self.view.has_widget(name):
return
widget = self.view.get_widget(name)
widget.show()
self.view.draw_node()
undo_cmd = NodeWidgetVisibleCmd(self, name, visible=True)
self.graph.undo_stack().push(undo_cmd)

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/pkg_info.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
__version__ = '0.6.10'
__version__ = '0.6.11'
__status__ = 'Work in Progress'
__license__ = 'MIT'

Expand Down
2 changes: 1 addition & 1 deletion docs/custom_widgets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Built-in Widgets

| The ``NodeGraphQt`` framework comes included with a few custom widgets.
**Classes:**
**Widget Types:**

.. autosummary::
NodeGraphQt.PropertiesBinWidget
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ script or checkout the :ref:`General Overview` section.
:hidden:
:caption: Widgets
:name: wdgtstoc
:maxdepth: 1
:maxdepth: 2

custom_widgets
node_widgets

0 comments on commit 184d83a

Please sign in to comment.