1515 NODE_LAYOUT_VERTICAL ,
1616 NODE_LAYOUT_HORIZONTAL ,
1717 NODE_LAYOUT_DIRECTION )
18- from ..errors import PortRegistrationError
18+ from ..errors import PortRegistrationError , NodeWidgetError
1919from ..qgraphics .node_backdrop import BackdropNodeItem
2020from ..qgraphics .node_base import NodeItem , NodeItemVertical
21- from ..widgets .node_widgets import (NodeComboBox ,
21+ from ..widgets .node_widgets import (NodeBaseWidget ,
22+ NodeComboBox ,
2223 NodeLineEdit ,
2324 NodeFloatEdit ,
2425 NodeIntEdit ,
@@ -627,15 +628,39 @@ def get_widget(self, name):
627628 """
628629 return self .view .widgets .get (name )
629630
631+ def add_custom_widget (self , name , widget = None , widget_type = NODE_PROP ,
632+ tab = None ):
633+ """
634+ Add a custom node widget into the node.
635+
636+ Note:
637+ The ``value_changed`` signal from the added node widget is wired
638+ up to the :meth:`NodeObject.set_property` function.
639+
640+ Args:
641+ name (str): name for the custom property.
642+ widget (NodeBaseWidget): custom node widget.
643+ widget_type: widget flag to display in the
644+ :class:`NodeGraphQt.PropertiesBinWidget`.
645+ tab (str): name of the widget tab to display in.
646+ """
647+ if not isinstance (widget , NodeBaseWidget ):
648+ raise NodeWidgetError (
649+ '\' widget\' must be an instance of a NodeBaseWidget' )
650+ self .create_property (
651+ name , widget .value , widget_type = widget_type , tab = tab )
652+ widget .value_changed .connect (lambda k , v : self .set_property (k , v ))
653+ self .view .add_widget (widget )
654+
630655 def add_combo_menu (self , name , label = '' , items = None , tab = None ):
631656 """
632657 Creates a custom property with the :meth:`NodeObject.create_property`
633658 function and embeds a :class:`PySide2.QtWidgets.QComboBox` widget
634659 into the node.
635660
636- Important :
637- The embedded widget is wired up to the :meth:`NodeObject.set_property`
638- function use this function to to update the widget .
661+ Note :
662+ The ``value_changed`` signal from the added node widget is wired
663+ up to the :meth:`NodeObject.set_property` function .
639664
640665 Args:
641666 name (str): name for the custom property.
@@ -657,9 +682,9 @@ def add_text_input(self, name, label='', text='', tab=None, multi_line=False):
657682 function and embeds a :class:`PySide2.QtWidgets.QLineEdit` widget
658683 into the node.
659684
660- Important :
661- The embedded widget is wired up to the :meth:`NodeObject.set_property`
662- function use this function to to update the widget .
685+ Note :
686+ The ``value_changed`` signal from the added node widget is wired
687+ up to the :meth:`NodeObject.set_property` function .
663688
664689 Args:
665690 name (str): name for the custom property.
@@ -682,9 +707,9 @@ def add_file_input(self, name, label='', text='', tab=None, ext="*"):
682707 function and embeds a :class:`PySide2.QtWidgets.QLineEdit` widget
683708 into the node.
684709
685- Important :
686- The embedded widget is wired up to the :meth:`NodeObject.set_property`
687- function use this function to to update the widget .
710+ Note :
711+ The ``value_changed`` signal from the added node widget is wired
712+ up to the :meth:`NodeObject.set_property` function .
688713
689714 Args:
690715 name (str): name for the custom property.
@@ -705,9 +730,9 @@ def add_float_input(self, name, label='', value=0.0, range=None, tab=None):
705730 function and embeds a :class:`PySide2.QtWidgets.QLineEdit` widget
706731 into the node.
707732
708- Important :
709- The embedded widget is wired up to the :meth:`NodeObject.set_property`
710- function use this function to to update the widget .
733+ Note :
734+ The ``value_changed`` signal from the added node widget is wired
735+ up to the :meth:`NodeObject.set_property` function .
711736
712737 Args:
713738 name (str): name for the custom property.
@@ -728,9 +753,9 @@ def add_int_input(self, name, label='', value=0, range=None, tab=None):
728753 function and embeds a :class:`PySide2.QtWidgets.QLineEdit` widget
729754 into the node.
730755
731- Important :
732- The embedded widget is wired up to the :meth:`NodeObject.set_property`
733- function use this function to to update the widget .
756+ Note :
757+ The ``value_changed`` signal from the added node widget is wired
758+ up to the :meth:`NodeObject.set_property` function .
734759
735760 Args:
736761 name (str): name for the custom property.
@@ -751,9 +776,9 @@ def add_checkbox(self, name, label='', text='', state=False, tab=None):
751776 function and embeds a :class:`PySide2.QtWidgets.QCheckBox` widget
752777 into the node.
753778
754- Important :
755- The embedded widget is wired up to the :meth:`NodeObject.set_property`
756- function use this function to to update the widget .
779+ Note :
780+ The ``value_changed`` signal from the added node widget is wired
781+ up to the :meth:`NodeObject.set_property` function .
757782
758783 Args:
759784 name (str): name for the custom property.
0 commit comments