aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorw-e-w <40751091+w-e-w@users.noreply.github.com>2024-01-27 05:42:52 +0000
committerw-e-w <40751091+w-e-w@users.noreply.github.com>2024-01-27 05:42:52 +0000
commit36d1fefc19ecb7f1f8b11a8f3bc269be0a36de5e (patch)
tree8a7fdcaafaf5cb5033fb505ae1f0874f54fe0297
parent4d5db58a3e82b441fa0ca15df0370d49175e2aea (diff)
downloadstable-diffusion-webui-gfx803-36d1fefc19ecb7f1f8b11a8f3bc269be0a36de5e.tar.gz
stable-diffusion-webui-gfx803-36d1fefc19ecb7f1f8b11a8f3bc269be0a36de5e.tar.bz2
stable-diffusion-webui-gfx803-36d1fefc19ecb7f1f8b11a8f3bc269be0a36de5e.zip
rework set_named_arg
change identifying a script from using Scripts class name to Scripts internal name an as not all Script have unique names raise RuntimeError when there's issue
-rw-r--r--modules/scripts.py27
1 files changed, 19 insertions, 8 deletions
diff --git a/modules/scripts.py b/modules/scripts.py
index 060069cf..4b38ca32 100644
--- a/modules/scripts.py
+++ b/modules/scripts.py
@@ -939,22 +939,33 @@ class ScriptRunner:
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, args, script_name, arg_elem_id, value):
+ """Locate an arg of a specific script in script_args and set its value
+ Args:
+ args: all script args of process p, 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
+ when script_name in not found or arg_elem_id is not found in script controls, raise RuntimeError
+ """
+ script = next((x for x in self.scripts if x.name == script_name), None)
if script is None:
- return
+ raise RuntimeError(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):
+ if isinstance(args, tuple):
+ return args[:index] + (value,) + args[index + 1:]
+ elif isinstance(args, list):
args[index] = value
return args
- elif isinstance(args, tuple):
- return args[:index] + (value,) + args[index+1:]
else:
- return None
+ raise RuntimeError(f"args is not a list or tuple, but {type(args)}")
+ raise RuntimeError(f"arg_elem_id {arg_elem_id} not found in script {script_name}")
scripts_txt2img: ScriptRunner = None