Exemplo n.º 1
0
    def add_output(self,
                   name='output',
                   multi_output=True,
                   display_name=True,
                   color=None):
        """
        Add output :class:`Port` to node.

        Args:
            name (str): name for the output port.
            multi_output (bool): allow port to have more than one connection.
            display_name (bool): display the port name on the node.
            color (tuple): initial port color (r, g, b) 0-255.

        Returns:
            NodeGraphQt.Port: the created port object.
        """
        if name in self.outputs().keys():
            raise PortRegistrationError(
                'port name "{}" already registered.'.format(name))
        view = self.view.add_output(name, multi_output, display_name)
        if color:
            view.color = color
            view.border_color = [min([255, max([0, i + 80])]) for i in color]
        port = Port(self, view)
        port.model.type_ = OUT_PORT
        port.model.name = name
        port.model.display_name = display_name
        port.model.multi_connection = multi_output
        self._outputs.append(port)
        self.model.outputs[port.name()] = port.model
        return port
Exemplo n.º 2
0
 def add_input(self,
               name='input',
               multi_input=False,
               display_name=True,
               color=None,
               locked=False,
               painter_func=None):
     """
     This is not available for the `PortInputNode` class.
     """
     raise PortRegistrationError(
         '"{}.add_input()" is not available for {}.'.format(
             self.__class__.__name__, self))
Exemplo n.º 3
0
    def add_input(self,
                  name='input',
                  multi_input=False,
                  display_name=True,
                  color=None,
                  locked=False,
                  painter_func=None):
        """
        Add input :class:`Port` to node.

        Warnings:
            Undo is NOT supported for this function.

        Args:
            name (str): name for the input port.
            multi_input (bool): allow port to have more than one connection.
            display_name (bool): display the port name on the node.
            color (tuple): initial port color (r, g, b) ``0-255``.
            locked (bool): locked state see :meth:`Port.set_locked`
            painter_func (function or None): custom function to override the drawing
                of the port shape see example: :ref:`Creating Custom Shapes`

        Returns:
            NodeGraphQt.Port: the created port object.
        """
        if name in self.inputs().keys():
            raise PortRegistrationError(
                'port name "{}" already registered.'.format(name))

        port_args = [name, multi_input, display_name, locked]
        if painter_func and callable(painter_func):
            port_args.append(painter_func)
        view = self.view.add_input(*port_args)

        if color:
            view.color = color
            view.border_color = [min([255, max([0, i + 80])]) for i in color]

        port = Port(self, view)
        port.model.type_ = PortTypeEnum.IN.value
        port.model.name = name
        port.model.display_name = display_name
        port.model.multi_connection = multi_input
        port.model.locked = locked
        self._inputs.append(port)
        self.model.inputs[port.name()] = port.model
        return port
Exemplo n.º 4
0
 def add_output(self,
                name='output',
                multi_output=True,
                display_name=True,
                color=None,
                locked=False,
                painter_func=None):
     if self._outputs:
         raise PortRegistrationError(
             '"{}.add_output()" only ONE output is allowed for this node.'.
             format(self.__class__.__name__, self))
     super(PortInputNode, self).add_output(name=name,
                                           multi_output=multi_output,
                                           display_name=False,
                                           color=color,
                                           locked=locked,
                                           painter_func=None)
Exemplo n.º 5
0
    def add_output(self, name='output', multi_output=True, display_name=True):
        """
        Add output :class:`Port` to node.

        Args:
            name (str): name for the output port.
            multi_output (bool): allow port to have more than one connection.
            display_name (bool): display the port name on the node.

        Returns:
            NodeGraphQt.Port: the created port object.
        """
        if name in self.outputs().keys():
            raise PortRegistrationError(
                'port name "{}" already registered.'.format(name))
        view = self.view.add_output(name, multi_output, display_name)
        port = Port(self, view)
        port.model.type_ = OUT_PORT
        port.model.name = name
        port.model.display_name = display_name
        port.model.multi_connection = multi_output
        self._outputs.append(port)
        self.model.outputs[port.name()] = port.model
        return port