| 540 | |
| 541 | |
| 542 | class ScriptRunner: |
| 543 | def __init__(self): |
| 544 | self.scripts = [] |
| 545 | self.selectable_scripts = [] |
| 546 | self.alwayson_scripts = [] |
| 547 | self.titles = [] |
| 548 | self.title_map = {} |
| 549 | self.infotext_fields = [] |
| 550 | self.paste_field_names = [] |
| 551 | self.inputs = [None] |
| 552 | |
| 553 | self.callback_map = {} |
| 554 | self.callback_names = [ |
| 555 | 'before_process', |
| 556 | 'process', |
| 557 | 'before_process_batch', |
| 558 | 'after_extra_networks_activate', |
| 559 | 'process_batch', |
| 560 | 'postprocess', |
| 561 | 'postprocess_batch', |
| 562 | 'postprocess_batch_list', |
| 563 | 'post_sample', |
| 564 | 'on_mask_blend', |
| 565 | 'postprocess_image', |
| 566 | 'postprocess_maskoverlay', |
| 567 | 'postprocess_image_after_composite', |
| 568 | 'before_component', |
| 569 | 'after_component', |
| 570 | ] |
| 571 | |
| 572 | self.on_before_component_elem_id = {} |
| 573 | """dict of callbacks to be called before an element is created; key=elem_id, value=list of callbacks""" |
| 574 | |
| 575 | self.on_after_component_elem_id = {} |
| 576 | """dict of callbacks to be called after an element is created; key=elem_id, value=list of callbacks""" |
| 577 | |
| 578 | def initialize_scripts(self, is_img2img): |
| 579 | from modules import scripts_auto_postprocessing |
| 580 | |
| 581 | self.scripts.clear() |
| 582 | self.alwayson_scripts.clear() |
| 583 | self.selectable_scripts.clear() |
| 584 | |
| 585 | auto_processing_scripts = scripts_auto_postprocessing.create_auto_preprocessing_script_data() |
| 586 | |
| 587 | for script_data in auto_processing_scripts + scripts_data: |
| 588 | try: |
| 589 | script = script_data.script_class() |
| 590 | except Exception: |
| 591 | errors.report(f"Error # failed to initialize Script {script_data.module}: ", exc_info=True) |
| 592 | continue |
| 593 | |
| 594 | script.filename = script_data.path |
| 595 | script.is_txt2img = not is_img2img |
| 596 | script.is_img2img = is_img2img |
| 597 | script.tabname = "img2img" if is_img2img else "txt2img" |
| 598 | |
| 599 | visibility = script.show(script.is_img2img) |