Skip to content

Commit 35ab27f

Browse files
committed
refactored node widgets module and cleanup.
1 parent 2f0f87f commit 35ab27f

File tree

7 files changed

+342
-199
lines changed

7 files changed

+342
-199
lines changed

NodeGraphQt/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,15 @@ def __init__(self):
9898
from .widgets.node_tree import NodeTreeWidget
9999
from .widgets.properties_bin import PropertiesBinWidget
100100
from .widgets.node_publish_widget import NodePublishWidget
101+
from .widgets.node_widgets import NodeBaseWidget
101102

102103

103104
__version__ = VERSION
104105
__all__ = [
105106
'BackdropNode',
106107
'BaseNode',
107108
'LICENSE',
109+
'NodeBaseWidget',
108110
'NodeGraph',
109111
'NodeGraphCommand',
110112
'NodeGraphMenu',

NodeGraphQt/base/node.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from .port import Port
55
from .utils import update_node_down_stream
66
from ..constants import (NODE_PROP,
7+
NODE_PROP_QLABEL,
78
NODE_PROP_QLINEEDIT,
89
NODE_PROP_QTEXTEDIT,
910
NODE_PROP_QCOMBO,
@@ -15,7 +16,7 @@
1516
NODE_LAYOUT_VERTICAL,
1617
NODE_LAYOUT_HORIZONTAL,
1718
NODE_LAYOUT_DIRECTION)
18-
from ..errors import PortRegistrationError,NodeWidgetError
19+
from ..errors import PortRegistrationError, NodeWidgetError
1920
from ..qgraphics.node_backdrop import BackdropNodeItem
2021
from ..qgraphics.node_base import NodeItem, NodeItemVertical
2122
from ..widgets.node_widgets import (NodeBaseWidget,
@@ -628,28 +629,31 @@ def get_widget(self, name):
628629
"""
629630
return self.view.widgets.get(name)
630631

631-
def add_custom_widget(self, name, widget=None, widget_type=NODE_PROP,
632-
tab=None):
632+
def add_custom_widget(self, widget, widget_type=NODE_PROP_QLABEL, tab=None):
633633
"""
634634
Add a custom node widget into the node.
635635
636+
see example :ref:`Embedding Custom Widgets`.
637+
636638
Note:
637639
The ``value_changed`` signal from the added node widget is wired
638640
up to the :meth:`NodeObject.set_property` function.
639641
640642
Args:
641-
name (str): name for the custom property.
642-
widget (NodeBaseWidget): custom node widget.
643+
widget_cls (NodeBaseWidget): node widget class object.
643644
widget_type: widget flag to display in the
644-
:class:`NodeGraphQt.PropertiesBinWidget`.
645+
:class:`NodeGraphQt.PropertiesBinWidget` (default: QLabel).
645646
tab (str): name of the widget tab to display in.
646647
"""
647648
if not isinstance(widget, NodeBaseWidget):
648649
raise NodeWidgetError(
649650
'\'widget\' must be an instance of a NodeBaseWidget')
650-
self.create_property(
651-
name, widget.value, widget_type=widget_type, tab=tab)
651+
self.create_property(widget.get_name(),
652+
widget.get_value(),
653+
widget_type=widget_type,
654+
tab=tab)
652655
widget.value_changed.connect(lambda k, v: self.set_property(k, v))
656+
widget._node = self
653657
self.view.add_widget(widget)
654658

655659
def add_combo_menu(self, name, label='', items=None, tab=None):

NodeGraphQt/qgraphics/node_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ def height(self, height=0.0):
608608
def disabled(self, state=False):
609609
AbstractNodeItem.disabled.fset(self, state)
610610
for n, w in self._widgets.items():
611-
w.widget.setDisabled(state)
611+
w.get_custom_widget().setDisabled(state)
612612
self._tooltip_disable(state)
613613
self._x_item.setVisible(state)
614614

@@ -800,7 +800,7 @@ def widgets(self):
800800
return self._widgets.copy()
801801

802802
def add_widget(self, widget):
803-
self._widgets[widget.name] = widget
803+
self._widgets[widget.get_name()] = widget
804804

805805
def get_widget(self, name):
806806
widget = self._widgets.get(name)

0 commit comments

Comments
 (0)