From 118a2273ed63e7eaedd399bbd5189512da7488f2 Mon Sep 17 00:00:00 2001 From: w-e-w <40751091+w-e-w@users.noreply.github.com> Date: Mon, 22 Jan 2024 21:27:38 +0900 Subject: [PATCH] rework set_named_arg change set_named_arg script identifier from script type to script name "in" can cause issues assigning the wrong arg change arg_elem_id control.elem_id two equals as opposed to "in" add assertion if issues happens during set_named_arg add doc string --- modules/scripts.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/modules/scripts.py b/modules/scripts.py index 060069cf36a..796a99c4ec1 100644 --- a/modules/scripts.py +++ b/modules/scripts.py @@ -939,22 +939,33 @@ def setup_scrips(self, p, *, is_ui=True): except Exception: errors.report(f"Error running setup: {script.filename}", exc_info=True) - def set_named_arg(self, args, script_type, arg_elem_id, value): - script = next((x for x in self.scripts if type(x).__name__ == script_type), None) + def set_named_arg(self, all_script_args, script_name, arg_elem_id, value): + """Locate an arg of a specific script in script_args and set its value + + Args: + all_script_args: all script args, p.script_args + script_name: the name target script name to + arg_elem_id: the elem_id of the target arg + value: the value to set + + Returns: + Updated script args + """ + script = next((x for x in self.scripts if x.name == script_name), None) if script is None: - return + assert False, f"script {script_name} not found" for i, control in enumerate(script.controls): - if arg_elem_id in control.elem_id: + if arg_elem_id == control.elem_id: index = script.args_from + i - if isinstance(args, list): - args[index] = value - return args - elif isinstance(args, tuple): - return args[:index] + (value,) + args[index+1:] + if isinstance(all_script_args, list): + all_script_args[index] = value + return all_script_args else: - return None + return all_script_args[:index] + (value,) + all_script_args[index + 1:] + + assert False, f"arg_elem_id {arg_elem_id} not found in script {script_name}" scripts_txt2img: ScriptRunner = None