2023-02-14 15:20:30 +00:00
|
|
|
class Example:
|
|
|
|
"""
|
|
|
|
A example node
|
|
|
|
|
|
|
|
Class methods
|
|
|
|
-------------
|
|
|
|
INPUT_TYPES (dict):
|
|
|
|
Tell the main program input parameters of nodes.
|
|
|
|
|
|
|
|
Attributes
|
|
|
|
----------
|
|
|
|
RETURN_TYPES (`tuple`):
|
|
|
|
The type of each element in the output tulple.
|
2023-04-02 14:27:01 +00:00
|
|
|
RETURN_NAMES (`tuple`):
|
|
|
|
Optional: The name of each output in the output tulple.
|
2023-02-14 15:20:30 +00:00
|
|
|
FUNCTION (`str`):
|
2023-02-17 16:19:49 +00:00
|
|
|
The name of the entry-point method. For example, if `FUNCTION = "execute"` then it will run Example().execute()
|
2023-02-14 15:20:30 +00:00
|
|
|
OUTPUT_NODE ([`bool`]):
|
2023-02-17 16:19:49 +00:00
|
|
|
If this node is an output node that outputs a result/image from the graph. The SaveImage node is an example.
|
|
|
|
The backend iterates on these output nodes and tries to execute all their parents if their parent graph is properly connected.
|
|
|
|
Assumed to be False if not present.
|
2023-02-14 15:20:30 +00:00
|
|
|
CATEGORY (`str`):
|
2023-02-17 16:19:49 +00:00
|
|
|
The category the node should appear in the UI.
|
2023-02-14 15:20:30 +00:00
|
|
|
execute(s) -> tuple || None:
|
|
|
|
The entry point method. The name of this method must be the same as the value of property `FUNCTION`.
|
|
|
|
For example, if `FUNCTION = "execute"` then this method's name must be `execute`, if `FUNCTION = "foo"` then it must be `foo`.
|
|
|
|
"""
|
|
|
|
def __init__(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def INPUT_TYPES(s):
|
|
|
|
"""
|
|
|
|
Return a dictionary which contains config for all input fields.
|
2023-02-17 16:19:49 +00:00
|
|
|
Some types (string): "MODEL", "VAE", "CLIP", "CONDITIONING", "LATENT", "IMAGE", "INT", "STRING", "FLOAT".
|
|
|
|
Input types "INT", "STRING" or "FLOAT" are special values for fields on the node.
|
|
|
|
The type can be a list for selection.
|
|
|
|
|
2023-02-14 15:20:30 +00:00
|
|
|
Returns: `dict`:
|
|
|
|
- Key input_fields_group (`string`): Can be either required, hidden or optional. A node class must have property `required`
|
|
|
|
- Value input_fields (`dict`): Contains input fields config:
|
|
|
|
* Key field_name (`string`): Name of a entry-point method's argument
|
|
|
|
* Value field_config (`tuple`):
|
|
|
|
+ First value is a string indicate the type of field or a list for selection.
|
|
|
|
+ Secound value is a config for type "INT", "STRING" or "FLOAT".
|
|
|
|
"""
|
|
|
|
return {
|
|
|
|
"required": {
|
2023-02-17 16:19:49 +00:00
|
|
|
"image": ("IMAGE",),
|
2023-02-14 15:20:30 +00:00
|
|
|
"int_field": ("INT", {
|
|
|
|
"default": 0,
|
|
|
|
"min": 0, #Minimum value
|
|
|
|
"max": 4096, #Maximum value
|
|
|
|
"step": 64 #Slider's step
|
|
|
|
}),
|
|
|
|
"float_field": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 10.0, "step": 0.01}),
|
2023-02-17 16:19:49 +00:00
|
|
|
"print_to_screen": (["enable", "disable"],),
|
|
|
|
"string_field": ("STRING", {
|
|
|
|
"multiline": False, #True if you want the field to look like the one on the ClipTextEncode node
|
|
|
|
"default": "Hello World!"
|
|
|
|
}),
|
2023-02-14 15:20:30 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-02-17 16:19:49 +00:00
|
|
|
RETURN_TYPES = ("IMAGE",)
|
2023-04-02 14:27:01 +00:00
|
|
|
#RETURN_NAMES = ("image_output_name",)
|
|
|
|
|
2023-02-14 15:20:30 +00:00
|
|
|
FUNCTION = "test"
|
|
|
|
|
2023-02-17 16:19:49 +00:00
|
|
|
#OUTPUT_NODE = False
|
2023-02-14 15:20:30 +00:00
|
|
|
|
|
|
|
CATEGORY = "Example"
|
|
|
|
|
2023-02-17 16:19:49 +00:00
|
|
|
def test(self, image, string_field, int_field, float_field, print_to_screen):
|
|
|
|
if print_to_screen == "enable":
|
2023-02-14 15:20:30 +00:00
|
|
|
print(f"""Your input contains:
|
|
|
|
string_field aka input text: {string_field}
|
|
|
|
int_field: {int_field}
|
|
|
|
float_field: {float_field}
|
|
|
|
""")
|
2023-02-17 16:19:49 +00:00
|
|
|
#do some processing on the image, in this example I just invert it
|
|
|
|
image = 1.0 - image
|
|
|
|
return (image,)
|
2023-02-14 15:20:30 +00:00
|
|
|
|
|
|
|
|
2023-02-17 16:19:49 +00:00
|
|
|
# A dictionary that contains all nodes you want to export with their names
|
|
|
|
# NOTE: names should be globally unique
|
2023-02-14 15:20:30 +00:00
|
|
|
NODE_CLASS_MAPPINGS = {
|
|
|
|
"Example": Example
|
|
|
|
}
|