Print custom node loading for debug

This commit is contained in:
RobeSantoro 2024-03-25 15:04:38 +01:00
parent c6de09b02e
commit 29b94f61ec
2 changed files with 122 additions and 118 deletions

View File

@ -1,118 +1,118 @@
class Example: class Example:
""" """
A example node A example node
Class methods Class methods
------------- -------------
INPUT_TYPES (dict): INPUT_TYPES (dict):
Tell the main program input parameters of nodes. Tell the main program input parameters of nodes.
IS_CHANGED: IS_CHANGED:
optional method to control when the node is re executed. optional method to control when the node is re executed.
Attributes Attributes
---------- ----------
RETURN_TYPES (`tuple`): RETURN_TYPES (`tuple`):
The type of each element in the output tulple. The type of each element in the output tulple.
RETURN_NAMES (`tuple`): RETURN_NAMES (`tuple`):
Optional: The name of each output in the output tulple. Optional: The name of each output in the output tulple.
FUNCTION (`str`): FUNCTION (`str`):
The name of the entry-point method. For example, if `FUNCTION = "execute"` then it will run Example().execute() The name of the entry-point method. For example, if `FUNCTION = "execute"` then it will run Example().execute()
OUTPUT_NODE ([`bool`]): OUTPUT_NODE ([`bool`]):
If this node is an output node that outputs a result/image from the graph. The SaveImage node is an example. 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. 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. Assumed to be False if not present.
CATEGORY (`str`): CATEGORY (`str`):
The category the node should appear in the UI. The category the node should appear in the UI.
execute(s) -> tuple || None: execute(s) -> tuple || None:
The entry point method. The name of this method must be the same as the value of property `FUNCTION`. 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`. For example, if `FUNCTION = "execute"` then this method's name must be `execute`, if `FUNCTION = "foo"` then it must be `foo`.
""" """
def __init__(self): def __init__(self):
pass pass
@classmethod @classmethod
def INPUT_TYPES(s): def INPUT_TYPES(s):
""" """
Return a dictionary which contains config for all input fields. Return a dictionary which contains config for all input fields.
Some types (string): "MODEL", "VAE", "CLIP", "CONDITIONING", "LATENT", "IMAGE", "INT", "STRING", "FLOAT". 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. Input types "INT", "STRING" or "FLOAT" are special values for fields on the node.
The type can be a list for selection. The type can be a list for selection.
Returns: `dict`: Returns: `dict`:
- Key input_fields_group (`string`): Can be either required, hidden or optional. A node class must have property `required` - 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: - Value input_fields (`dict`): Contains input fields config:
* Key field_name (`string`): Name of a entry-point method's argument * Key field_name (`string`): Name of a entry-point method's argument
* Value field_config (`tuple`): * Value field_config (`tuple`):
+ First value is a string indicate the type of field or a list for selection. + 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". + Secound value is a config for type "INT", "STRING" or "FLOAT".
""" """
return { return {
"required": { "required": {
"image": ("IMAGE",), "image": ("IMAGE",),
"int_field": ("INT", { "int_field": ("INT", {
"default": 0, "default": 0,
"min": 0, #Minimum value "min": 0, #Minimum value
"max": 4096, #Maximum value "max": 4096, #Maximum value
"step": 64, #Slider's step "step": 64, #Slider's step
"display": "number" # Cosmetic only: display as "number" or "slider" "display": "number" # Cosmetic only: display as "number" or "slider"
}), }),
"float_field": ("FLOAT", { "float_field": ("FLOAT", {
"default": 1.0, "default": 1.0,
"min": 0.0, "min": 0.0,
"max": 10.0, "max": 10.0,
"step": 0.01, "step": 0.01,
"round": 0.001, #The value represeting the precision to round to, will be set to the step value by default. Can be set to False to disable rounding. "round": 0.001, #The value represeting the precision to round to, will be set to the step value by default. Can be set to False to disable rounding.
"display": "number"}), "display": "number"}),
"print_to_screen": (["enable", "disable"],), "print_to_screen": (["enable", "disable"],),
"string_field": ("STRING", { "string_field": ("STRING", {
"multiline": False, #True if you want the field to look like the one on the ClipTextEncode node "multiline": False, #True if you want the field to look like the one on the ClipTextEncode node
"default": "Hello World!" "default": "Hello World!"
}), }),
}, },
} }
RETURN_TYPES = ("IMAGE",) RETURN_TYPES = ("IMAGE",)
#RETURN_NAMES = ("image_output_name",) #RETURN_NAMES = ("image_output_name",)
FUNCTION = "test" FUNCTION = "test"
#OUTPUT_NODE = False #OUTPUT_NODE = False
CATEGORY = "Example" CATEGORY = "Example"
def test(self, image, string_field, int_field, float_field, print_to_screen): def test(self, image, string_field, int_field, float_field, print_to_screen):
if print_to_screen == "enable": if print_to_screen == "enable":
print(f"""Your input contains: print(f"""Your input contains:
string_field aka input text: {string_field} string_field aka input text: {string_field}
int_field: {int_field} int_field: {int_field}
float_field: {float_field} float_field: {float_field}
""") """)
#do some processing on the image, in this example I just invert it #do some processing on the image, in this example I just invert it
image = 1.0 - image image = 1.0 - image
return (image,) return (image,)
""" """
The node will always be re executed if any of the inputs change but The node will always be re executed if any of the inputs change but
this method can be used to force the node to execute again even when the inputs don't change. this method can be used to force the node to execute again even when the inputs don't change.
You can make this node return a number or a string. This value will be compared to the one returned the last time the node was You can make this node return a number or a string. This value will be compared to the one returned the last time the node was
executed, if it is different the node will be executed again. executed, if it is different the node will be executed again.
This method is used in the core repo for the LoadImage node where they return the image hash as a string, if the image hash This method is used in the core repo for the LoadImage node where they return the image hash as a string, if the image hash
changes between executions the LoadImage node is executed again. changes between executions the LoadImage node is executed again.
""" """
#@classmethod #@classmethod
#def IS_CHANGED(s, image, string_field, int_field, float_field, print_to_screen): #def IS_CHANGED(s, image, string_field, int_field, float_field, print_to_screen):
# return "" # return ""
# Set the web directory, any .js file in that directory will be loaded by the frontend as a frontend extension # Set the web directory, any .js file in that directory will be loaded by the frontend as a frontend extension
# WEB_DIRECTORY = "./somejs" # WEB_DIRECTORY = "./somejs"
# A dictionary that contains all nodes you want to export with their names # A dictionary that contains all nodes you want to export with their names
# NOTE: names should be globally unique # NOTE: names should be globally unique
NODE_CLASS_MAPPINGS = { NODE_CLASS_MAPPINGS = {
"Example": Example "Example": Example
} }
# A dictionary that contains the friendly/humanly readable titles for the nodes # A dictionary that contains the friendly/humanly readable titles for the nodes
NODE_DISPLAY_NAME_MAPPINGS = { NODE_DISPLAY_NAME_MAPPINGS = {
"Example": "Example Node" "Example": "Example Node"
} }

View File

@ -1917,6 +1917,10 @@ def load_custom_nodes():
possible_modules.remove("__pycache__") possible_modules.remove("__pycache__")
for possible_module in possible_modules: for possible_module in possible_modules:
from colorama import Fore, Style
print(Fore.LIGHTMAGENTA_EX + "\nLOADING " + possible_module + Style.RESET_ALL)
module_path = os.path.join(custom_node_path, possible_module) module_path = os.path.join(custom_node_path, possible_module)
if os.path.isfile(module_path) and os.path.splitext(module_path)[1] != ".py": continue if os.path.isfile(module_path) and os.path.splitext(module_path)[1] != ".py": continue
if module_path.endswith(".disabled"): continue if module_path.endswith(".disabled"): continue