colour.utilities.Port#
- class colour.utilities.Port(name: str | None = None, value: Any = None, description: str | None = None, node: PortNode | None = None)[source]#
Bases:
MixinLogging
Define an object that can be added either as an input or output port, i.e., a pin, to a
colour.utilities.PortNode
class and connected to another input or output port.- Parameters:
Attributes
Methods
Examples
>>> port = Port("a", 1, "Port A Description") >>> port.name 'a' >>> port.value 1 >>> port.description 'Port A Description'
- __init__(name: str | None = None, value: Any = None, description: str | None = None, node: PortNode | None = None) None [source]#
- property name: str#
Getter and setter property for the port name.
- Parameters:
value – Value to set the port name with.
- Returns:
Port name.
- Return type:
- property value: Any#
Getter and setter property for the port value.
- Parameters:
value – Value to set the port value with.
- Returns:
Port value.
- Return type:
- property description: str | None#
Getter and setter property for the port description.
- Parameters:
value – Value to set the port description with.
- Returns:
Port description.
- Return type:
str
or None
- property node: PortNode | None#
Getter property for the port node.
- Returns:
Port node.
- Return type:
PortNode
or None
- property connections: Dict[Port, None]#
Getter property for the port connections.
- Returns:
Port connections.
- Return type:
- __str__() str [source]#
Return a formatted string representation of the port.
- Returns:
Formatted string representation of the port.
- Return type:
Examples
>>> print(Port("a")) None.a (-> []) >>> print(Port("a", node=PortNode("Port Node"))) Port Node.a (-> [])
- is_input_port() bool [source]#
Return whether the port is an input port.
- Returns:
Whether the port is an input port.
- Return type:
Examples
>>> Port().is_input_port() False >>> node = PortNode() >>> node.add_input_port("a").is_input_port() True
- is_output_port() bool [source]#
Return whether the port is an output port.
- Returns:
Whether the port is an output port.
- Return type:
Examples
>>> Port().is_output_port() False >>> node = PortNode() >>> node.add_output_port("output").is_output_port() True
- connect(port: Port) None [source]#
Connect the port to the other given port.
- Parameters:
port (Port) – Port to connect to.
- Raises:
ValueError – if an attempt is made to connect an input port to multiple output ports.
- Return type:
None
Examples
>>> port_a = Port() >>> port_b = Port() >>> port_a.connections {} >>> port_b.connections {} >>> port_a.connect(port_b) >>> port_a.connections {<...Port object at 0x...>: None} >>> port_b.connections {<...Port object at 0x...>: None}
- disconnect(port: Port) None [source]#
Disconnect the port from the other given port.
- Parameters:
port (Port) – Port to disconnect from.
- Return type:
None
Examples
>>> port_a = Port() >>> port_b = Port() >>> port_a.connect(port_b) >>> port_a.connections {<...Port object at 0x...>: None} >>> port_b.connections {<...Port object at 0x...>: None} >>> port_a.disconnect(port_b) >>> port_a.connections {} >>> port_b.connections {}