| 358 | |
| 359 | |
| 360 | class ScriptRunner: |
| 361 | def __init__(self, name=''): |
| 362 | self.name = name |
| 363 | self.scripts: list[Script] = [] |
| 364 | self.selectable_scripts: list[Script] = [] |
| 365 | self.alwayson_scripts: list[Script] = [] |
| 366 | self.auto_processing_scripts: list[ScriptClassData] = [] |
| 367 | self.titles: list[str] = [] |
| 368 | self.alwayson_titles: list[str] = [] |
| 369 | self.infotext_fields: list[tuple[IOComponent, str]] = [] |
| 370 | self.paste_field_names: list[str] = [] |
| 371 | self.script_load_ctr = 0 |
| 372 | self.is_img2img = False |
| 373 | self.inputs: list = [None] |
| 374 | self.time = 0 |
| 375 | |
| 376 | def add_script(self, script_class, path, is_img2img, is_control): |
| 377 | try: |
| 378 | script = script_class() |
| 379 | script.filename = path |
| 380 | script.is_txt2img = not is_img2img |
| 381 | script.is_img2img = is_img2img |
| 382 | if path.startswith(paths.extensions_dir) and not path.startswith(paths.extensions_builtin_dir): |
| 383 | script.external = True |
| 384 | if is_control and script.external: |
| 385 | title = script.title() |
| 386 | if title not in control_extensions: |
| 387 | log.debug(f'Script: fn="{script.filename}" type=control title="{title}" skip') |
| 388 | return |
| 389 | if is_control: # this is messy but show is a legacy function that is not aware of control tab |
| 390 | v1 = script.show(script.is_txt2img) |
| 391 | v2 = script.show(script.is_img2img) |
| 392 | if v1 == AlwaysVisible or v2 == AlwaysVisible: |
| 393 | visibility = AlwaysVisible |
| 394 | else: |
| 395 | visibility = v1 or v2 |
| 396 | else: |
| 397 | visibility = script.show(script.is_img2img) |
| 398 | if visibility == AlwaysVisible: |
| 399 | self.scripts.append(script) |
| 400 | self.alwayson_scripts.append(script) |
| 401 | script.alwayson = True |
| 402 | elif visibility: |
| 403 | self.scripts.append(script) |
| 404 | self.selectable_scripts.append(script) |
| 405 | except Exception as e: |
| 406 | log.error(f'Script initialize: {path} {e}') |
| 407 | errors.display(e, 'script') |
| 408 | |
| 409 | def initialize_scripts(self, is_img2img=False, is_control=False): |
| 410 | from modules import scripts_auto_postprocessing |
| 411 | |
| 412 | self.scripts.clear() |
| 413 | self.selectable_scripts.clear() |
| 414 | self.alwayson_scripts.clear() |
| 415 | self.titles.clear() |
| 416 | self.alwayson_titles.clear() |
| 417 | self.infotext_fields.clear() |