# -*- coding: utf-8 -*-
"""
A module containing the Edge Validator functions which can be registered as callbacks to
:class:`~node_editor.node_edge.Edge` class.
Example of registering Edge Validator callbacks:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
You can register validation callbacks once for example on the bottom of node_edge.py file or on the
application start with calling this:
.. code-block:: python
from node_editor.node_edge_validators import *
Edge.registerEdgeValidator(edge_validator_debug)
Edge.registerEdgeValidator(edge_cannot_connect_two_outputs_or_two_inputs)
Edge.registerEdgeValidator(edge_cannot_connect_input_and_output_of_same_node)
Edge.registerEdgeValidator(edge_cannot_connect_input_and_output_of_different_type)
"""
DEBUG = False
[docs]def print_error(*args):
"""Helper method which prints to console if `DEBUG` is set to `True`"""
if DEBUG: print("Edge Validation Error:", *args)
[docs]def edge_validator_debug(input: 'Socket', output: 'Socket') -> bool:
"""This will consider edge always valid, however writes bunch of debug stuff into console"""
print("VALIDATING:")
print(input, "input" if input.is_input else "output", "of node", input.node)
for s in input.node.inputs + input.node.outputs: print("\t", s, "input" if s.is_input else "output")
print(output, "input" if input.is_input else "output", "of node", output.node)
for s in output.node.inputs + output.node.outputs: print("\t", s, "input" if s.is_input else "output")
return True