@@ -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:
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 not 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:
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,8 +936,21 @@ 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':...}, ...]}
939+ port_data(dict):
940+ {
941+ 'input_ports':
942+ [{'name':...,
943+ 'multi_connection':...,
944+ 'display_name':...,
945+ 'data_type':...
946+ }, ...],
947+ 'output_ports':
948+ [{'name':...,
949+ 'multi_connection':...,
950+ 'display_name':...,
951+ 'data_type':...
952+ }, ...]
953+ }
919954 """
920955 for port in self ._inputs :
921956 self ._view .delete_input (port .view )
@@ -927,11 +962,15 @@ def set_ports(self, port_data):
927962 self ._outputs = []
928963 self ._model .outputs = {}
929964 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' ])
965+ [self .add_input (name = port ['name' ],
966+ multi_input = port ['multi_connection' ],
967+ display_name = port ['display_name' ],
968+ data_type = port ['data_type' ])
932969 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' ])
970+ [self .add_output (name = port ['name' ],
971+ multi_output = port ['multi_connection' ],
972+ display_name = port ['display_name' ],
973+ data_type = port ['data_type' ])
935974 for port in port_data ['output_ports' ]]
936975 self .draw ()
937976
@@ -1216,6 +1255,7 @@ def create_from_nodes(self, nodes):
12161255 def add_child (self , node ):
12171256 """
12181257 Add a node to the sub graph.
1258+
12191259 Args:
12201260 node(NodeGraphQt.BaseNode).
12211261 """
@@ -1224,6 +1264,7 @@ def add_child(self, node):
12241264 def remove_child (self , node ):
12251265 """
12261266 Remove a node from the sub graph.
1267+
12271268 Args:
12281269 node(NodeGraphQt.BaseNode).
12291270 """
0 commit comments