diff --git a/ppp_comfyui.py b/ppp_comfyui.py index 79450c2..c3ef556 100644 --- a/ppp_comfyui.py +++ b/ppp_comfyui.py @@ -63,8 +63,6 @@ class PromptPostProcessorComfyUINode: Node for processing prompts. """ - logger = None - def __init__(self): lf = PromptPostProcessorLogFactory() self.logger = lf.log @@ -809,7 +807,8 @@ class PromptPostProcessorSelectVariableComfyUINode: """ def __init__(self): - pass + lf = PromptPostProcessorLogFactory() + self.logger = lf.log @classmethod def INPUT_TYPES(cls): @@ -834,6 +833,23 @@ class PromptPostProcessorSelectVariableComfyUINode: "tooltip": "Name of the variable to select", }, ), + "if_not_found": ( + "COMBO", + { + "options": [e.value for e in ONWARNING_CHOICES], + "default": ONWARNING_CHOICES.warn.value, + "tooltip": "How to handle the case when the variable name is not found in the input dictionary", + }, + ), + "default": ( + "STRING", + { + "default": "", + "multiline": False, + "dynamicPrompts": False, + "tooltip": "Default value if the variable is not found", + }, + ), }, } @@ -848,13 +864,18 @@ class PromptPostProcessorSelectVariableComfyUINode: self, variables: dict[str, Any], name: str, + if_not_found: str = ONWARNING_CHOICES.warn.value, + default: str = "", ): if variables: if name == "": return ("\n".join(f"{k}: {v}" for k, v in variables.items()),) if name in variables: return (variables[name],) - raise ValueError(f"Variable '{name}' not found in the input variables") + if if_not_found == ONWARNING_CHOICES.stop.value: + raise ValueError(f"Variable '{name}' not found in the input variables") + self.logger.warning(f"Variable '{name}' not found in the input variables") + return (default,) raise ValueError("No variables provided to select from") diff --git a/ppp_logging.py b/ppp_logging.py index 0914ae2..174a22c 100644 --- a/ppp_logging.py +++ b/ppp_logging.py @@ -56,13 +56,12 @@ class PromptPostProcessorLogFactory: # pylint: disable=too-few-public-methods def __init__(self, filename=None): """ - Initializes the PromptPostProcessor class. + Initializes the PromptPostProcessorLogFactory class. This method sets up the logger for the PromptPostProcessor class and configures its log level and handlers. Args: filename (str, optional): The name of the file to log to. Defaults to None. - app (SUPPORTED_APPS): The application for which the logger is being created. Returns: None