main.py 3.37 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from utils import waste_cpu_resource
class ExampleFolder:
    """
    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.
    FUNCTION (`str`):
        The name of the entry-point method which will return a tuple. For example, if `FUNCTION = "execute"` then it will run Example().execute()
    OUTPUT_NODE ([`bool`]):
        WIP
    CATEGORY (`str`):
        WIP
    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.
            The type can be a string indicate a type or a list indicate selection.
            Prebuilt types (string): "MODEL", "VAE", "CLIP", "CONDITIONING", "LATENT", "IMAGE", "INT", "STRING", "FLOAT".
            Input in type "INT", "STRING" or "FLOAT" will be converted automatically from a string to the corresponse Python type before passing and have special config
            Argument: s (`None`): Useless ig
            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": {
                "string_field": ("STRING", {
                    "multiline": True, #Allow the input to be multilined
                    "default": "Hello World!"
                }),
                "int_field": ("INT", {
                    "default": 0, 
                    "min": 0, #Minimum value
                    "max": 4096, #Maximum value
                    "step": 64 #Slider's step
                }),
                #Like INT
                "print_to_screen": (["Enable", "Disable"], {"default": "Enable"})
            },
            #"hidden": {
            #    "prompt": "PROMPT", 
            #    "extra_pnginfo": "EXTRA_PNGINFO"
            #},
        }

    RETURN_TYPES = ("STRING", "INT", "FLOAT", "STRING")
    FUNCTION = "test"

    #OUTPUT_NODE = True

    CATEGORY = "Example"

    def test(self, string_field, int_field, print_to_screen):
        rand_float = waste_cpu_resource()
        if print_to_screen == "Enable":
            print(f"""Your input contains:
                string_field aka input text: {string_field}
                int_field: {int_field}
                A random float number: {rand_float}
            """)
        return (string_field, int_field, rand_float, print_to_screen)

NODE_CLASS_MAPPINGS = {
    "ExampleFolder": ExampleFolder
}
"""
NODE_CLASS_MAPPINGS (dict): A dictionary contains all nodes you want to export
"""