|
4 | 4 | from .port import Port |
5 | 5 | from .utils import update_node_down_stream |
6 | 6 | from ..constants import (NODE_PROP, |
| 7 | + NODE_PROP_QLABEL, |
7 | 8 | NODE_PROP_QLINEEDIT, |
8 | 9 | NODE_PROP_QTEXTEDIT, |
9 | 10 | NODE_PROP_QCOMBO, |
|
15 | 16 | NODE_LAYOUT_VERTICAL, |
16 | 17 | NODE_LAYOUT_HORIZONTAL, |
17 | 18 | NODE_LAYOUT_DIRECTION) |
18 | | -from ..errors import PortRegistrationError,NodeWidgetError |
| 19 | +from ..errors import PortRegistrationError, NodeWidgetError |
19 | 20 | from ..qgraphics.node_backdrop import BackdropNodeItem |
20 | 21 | from ..qgraphics.node_base import NodeItem, NodeItemVertical |
21 | 22 | from ..widgets.node_widgets import (NodeBaseWidget, |
@@ -628,28 +629,31 @@ def get_widget(self, name): |
628 | 629 | """ |
629 | 630 | return self.view.widgets.get(name) |
630 | 631 |
|
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): |
633 | 633 | """ |
634 | 634 | Add a custom node widget into the node. |
635 | 635 |
|
| 636 | + see example :ref:`Embedding Custom Widgets`. |
| 637 | +
|
636 | 638 | Note: |
637 | 639 | The ``value_changed`` signal from the added node widget is wired |
638 | 640 | up to the :meth:`NodeObject.set_property` function. |
639 | 641 |
|
640 | 642 | Args: |
641 | | - name (str): name for the custom property. |
642 | | - widget (NodeBaseWidget): custom node widget. |
| 643 | + widget_cls (NodeBaseWidget): node widget class object. |
643 | 644 | widget_type: widget flag to display in the |
644 | | - :class:`NodeGraphQt.PropertiesBinWidget`. |
| 645 | + :class:`NodeGraphQt.PropertiesBinWidget` (default: QLabel). |
645 | 646 | tab (str): name of the widget tab to display in. |
646 | 647 | """ |
647 | 648 | if not isinstance(widget, NodeBaseWidget): |
648 | 649 | raise NodeWidgetError( |
649 | 650 | '\'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) |
652 | 655 | widget.value_changed.connect(lambda k, v: self.set_property(k, v)) |
| 656 | + widget._node = self |
653 | 657 | self.view.add_widget(widget) |
654 | 658 |
|
655 | 659 | def add_combo_menu(self, name, label='', items=None, tab=None): |
|
0 commit comments