@@ -529,6 +529,12 @@ def __init__(self):
529529 self ._view .text_item .editingFinished .connect (self .set_name )
530530
531531 def draw (self , force = True ):
532+ """
533+ Redraws the node in the scene.
534+
535+ Args:
536+ force (bool): force redraw if not visible.
537+ """
532538 if force :
533539 if not self .model .visible :
534540 self ._has_draw = False
@@ -544,14 +550,16 @@ def hide(self):
544550 Hide node.
545551 """
546552 super (BaseNode , self ).hide ()
547- [pipe .hide () for port in self ._inputs + self ._outputs for pipe in port .view .connected_pipes ]
553+ [pipe .hide () for port in self ._inputs + self ._outputs
554+ for pipe in port .view .connected_pipes ]
548555
549556 def show (self ):
550557 """
551558 Show node.
552559 """
553560 super (BaseNode , self ).show ()
554- [pipe .show () for port in self ._inputs + self ._outputs for pipe in port .view .connected_pipes ]
561+ [pipe .show () for port in self ._inputs + self ._outputs
562+ for pipe in port .view .connected_pipes ]
555563 self .draw (False )
556564
557565 def update_model (self ):
@@ -755,7 +763,7 @@ def add_checkbox(self, name, label='', text='', state=False, tab=None):
755763 self .view .add_widget (widget )
756764
757765 def add_input (self , name = 'input' , multi_input = False , display_name = True ,
758- color = None , data_type = 'None' ):
766+ color = None , data_type = 'None' , painter_func = None ):
759767 """
760768 Add input :class:`Port` to node.
761769
@@ -764,19 +772,26 @@ def add_input(self, name='input', multi_input=False, display_name=True,
764772 multi_input (bool): allow port to have more than one connection.
765773 display_name (bool): display the port name on the node.
766774 color (tuple): initial port color (r, g, b) ``0-255``.
767- data_type(str): port data type name.
775+ data_type (str): port data type name.
776+ painter_func (function): custom function to override the drawing
777+ of the port shape see example: :ref:`Creating Custom Shapes`
768778
769779 Returns:
770780 NodeGraphQt.Port: the created port object.
771781 """
772782 if name in self .inputs ().keys ():
773783 raise PortRegistrationError (
774784 'port name "{}" already registered.' .format (name ))
775- view = self .view .add_input (name , multi_input , display_name )
785+
786+ port_args = [name , multi_input , display_name ]
787+ if painter_func and callable (painter_func ):
788+ port_args .append (painter_func )
789+ view = self .view .add_input (* port_args )
776790
777791 if color :
778792 view .color = color
779793 view .border_color = [min ([255 , max ([0 , i + 80 ])]) for i in color ]
794+
780795 port = Port (self , view )
781796 port .model .type_ = IN_PORT
782797 port .model .name = name
@@ -788,7 +803,7 @@ def add_input(self, name='input', multi_input=False, display_name=True,
788803 return port
789804
790805 def add_output (self , name = 'output' , multi_output = True , display_name = True ,
791- color = None , data_type = 'None' ):
806+ color = None , data_type = 'None' , painter_func = None ):
792807 """
793808 Add output :class:`Port` to node.
794809
@@ -798,14 +813,21 @@ def add_output(self, name='output', multi_output=True, display_name=True,
798813 display_name (bool): display the port name on the node.
799814 color (tuple): initial port color (r, g, b) ``0-255``.
800815 data_type(str): port data type name.
816+ painter_func (function): custom function to override the drawing
817+ of the port shape see example: :ref:`Creating Custom Shapes`
801818
802819 Returns:
803820 NodeGraphQt.Port: the created port object.
804821 """
805822 if name in self .outputs ().keys ():
806823 raise PortRegistrationError (
807824 'port name "{}" already registered.' .format (name ))
808- view = self .view .add_output (name , multi_output , display_name )
825+
826+ port_args = [name , multi_output , display_name ]
827+ if painter_func and callable (painter_func ):
828+ port_args .append (painter_func )
829+ view = self .view .add_output (* port_args )
830+
809831 if color :
810832 view .color = color
811833 view .border_color = [min ([255 , max ([0 , i + 80 ])]) for i in color ]
@@ -914,9 +936,25 @@ def set_ports(self, port_data):
914936 Set node input and output ports.
915937
916938 Args:
917- port_data(dict): {'input_ports':[{'name':...,'multi_connection':...,'display_name':...,'data_type':...}, ...],
918- " 'output_ports':[{'name':...,'multi_connection':...,'display_name':...,'data_type':...}, ...]}
919- """
939+ port_data(dict): port data.
940+ """
941+
942+ # port data eg.
943+ # {
944+ # 'input_ports':
945+ # [{'name': ...,
946+ # 'multi_connection': ...,
947+ # 'display_name': ...,
948+ # 'data_type': ...
949+ # }, ...],
950+ # 'output_ports':
951+ # [{'name': ...,
952+ # 'multi_connection': ...,
953+ # 'display_name': ...,
954+ # 'data_type': ...
955+ # }, ...]
956+ # }
957+
920958 for port in self ._inputs :
921959 self ._view .delete_input (port .view )
922960 port .model .node = None
@@ -927,11 +965,15 @@ def set_ports(self, port_data):
927965 self ._outputs = []
928966 self ._model .outputs = {}
929967 self ._model .inputs = {}
930- [self .add_input (name = port ['name' ], multi_input = port ['multi_connection' ],
931- display_name = port ['display_name' ], data_type = port ['data_type' ])
968+ [self .add_input (name = port ['name' ],
969+ multi_input = port ['multi_connection' ],
970+ display_name = port ['display_name' ],
971+ data_type = port ['data_type' ])
932972 for port in port_data ['input_ports' ]]
933- [self .add_output (name = port ['name' ], multi_output = port ['multi_connection' ],
934- display_name = port ['display_name' ], data_type = port ['data_type' ])
973+ [self .add_output (name = port ['name' ],
974+ multi_output = port ['multi_connection' ],
975+ display_name = port ['display_name' ],
976+ data_type = port ['data_type' ])
935977 for port in port_data ['output_ports' ]]
936978 self .draw ()
937979
@@ -1196,6 +1238,12 @@ class SubGraph(object):
11961238 """
11971239 The ``NodeGraphQt.SubGraph`` class is the base class that all
11981240 Sub Graph Node inherit from.
1241+
1242+ *Implemented on NodeGraphQt: * ``v0.1.0``
1243+
1244+ .. image:: _images/example_subgraph.gif
1245+ :width: 80%
1246+
11991247 """
12001248
12011249 def __init__ (self ):
@@ -1210,8 +1258,9 @@ def children(self):
12101258 def create_from_nodes (self , nodes ):
12111259 """
12121260 Create sub graph from the nodes.
1261+
12131262 Args:
1214- nodes(list): nodes to create the sub graph.
1263+ nodes (list[NodeGraphQt.NodeObject] ): nodes to create the sub graph.
12151264 """
12161265 if self in nodes :
12171266 nodes .remove (self )
@@ -1220,16 +1269,18 @@ def create_from_nodes(self, nodes):
12201269 def add_child (self , node ):
12211270 """
12221271 Add a node to the sub graph.
1272+
12231273 Args:
1224- node(NodeGraphQt.BaseNode).
1274+ node (NodeGraphQt.BaseNode): node object .
12251275 """
12261276 self ._children .add (node )
12271277
12281278 def remove_child (self , node ):
12291279 """
12301280 Remove a node from the sub graph.
1281+
12311282 Args:
1232- node(NodeGraphQt.BaseNode).
1283+ node (NodeGraphQt.BaseNode): node object .
12331284 """
12341285 if node in self ._children :
12351286 self ._children .remove (node )
0 commit comments