@@ -457,14 +457,16 @@ def add_checkbox(self, name='', label='', text='', state=False, tab=None):
457457 widget .value_changed .connect (lambda k , v : self .set_property (k , v ))
458458 self .view .add_widget (widget )
459459
460- def add_input (self , name = 'input' , multi_input = False , display_name = True ):
460+ def add_input (self , name = 'input' , multi_input = False , display_name = True ,
461+ color = None ):
461462 """
462463 Add input :class:`Port` to node.
463464
464465 Args:
465466 name (str): name for the input port.
466467 multi_input (bool): allow port to have more than one connection.
467468 display_name (bool): display the port name on the node.
469+ color (tuple): initial port color (r, g, b) 0-255.
468470
469471 Returns:
470472 NodeGraphQt.Port: the created port object.
@@ -473,6 +475,9 @@ def add_input(self, name='input', multi_input=False, display_name=True):
473475 raise PortRegistrationError (
474476 'port name "{}" already registered.' .format (name ))
475477 view = self .view .add_input (name , multi_input , display_name )
478+ if color :
479+ view .color = color
480+ view .border_color = [min ([255 , max ([0 , i + 80 ])]) for i in color ]
476481 port = Port (self , view )
477482 port .model .type_ = IN_PORT
478483 port .model .name = name
@@ -482,14 +487,16 @@ def add_input(self, name='input', multi_input=False, display_name=True):
482487 self .model .inputs [port .name ()] = port .model
483488 return port
484489
485- def add_output (self , name = 'output' , multi_output = True , display_name = True ):
490+ def add_output (self , name = 'output' , multi_output = True , display_name = True ,
491+ color = None ):
486492 """
487493 Add output :class:`Port` to node.
488494
489495 Args:
490496 name (str): name for the output port.
491497 multi_output (bool): allow port to have more than one connection.
492498 display_name (bool): display the port name on the node.
499+ color (tuple): initial port color (r, g, b) 0-255.
493500
494501 Returns:
495502 NodeGraphQt.Port: the created port object.
@@ -498,6 +505,9 @@ def add_output(self, name='output', multi_output=True, display_name=True):
498505 raise PortRegistrationError (
499506 'port name "{}" already registered.' .format (name ))
500507 view = self .view .add_output (name , multi_output , display_name )
508+ if color :
509+ view .color = color
510+ view .border_color = [min ([255 , max ([0 , i + 80 ])]) for i in color ]
501511 port = Port (self , view )
502512 port .model .type_ = OUT_PORT
503513 port .model .name = name
0 commit comments