Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions modules/script_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def __init__(self, imgs, cols, rows):
callbacks_infotext_pasted=[],
callbacks_script_unloaded=[],
callbacks_before_ui=[],
callbacks_after_ui=[],
)


Expand Down Expand Up @@ -219,6 +220,14 @@ def before_ui_callback():
report_exception(c, 'before_ui')


def after_ui_callback():
for c in reversed(callback_map['callbacks_after_ui']):
try:
c.callback()
except Exception:
report_exception(c, 'after_ui')


def add_callback(callbacks, fun):
stack = [x for x in inspect.stack() if x.filename != __file__]
filename = stack[0].filename if len(stack) > 0 else 'unknown file'
Expand Down Expand Up @@ -357,3 +366,10 @@ def on_before_ui(callback):
"""register a function to be called before the UI is created."""

add_callback(callback_map['callbacks_before_ui'], callback)


def on_after_ui(callback):
"""register a function to be called after the UI is created."""

add_callback(callback_map['callbacks_after_ui'], callback)

3 changes: 3 additions & 0 deletions modules/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ def create_ui():
negative_token_button.click(fn=wrap_queued_call(update_token_counter), inputs=[txt2img_negative_prompt, steps], outputs=[negative_token_counter])

ui_extra_networks.setup_ui(extra_networks_ui, txt2img_gallery)
modules.script_callbacks.after_ui_callback()

modules.scripts.scripts_current = modules.scripts.scripts_img2img
modules.scripts.scripts_img2img.initialize_scripts(is_img2img=True)
Expand Down Expand Up @@ -969,6 +970,8 @@ def select_img2img_tab(tab):
paste_button=img2img_paste, tabname="img2img", source_text_component=img2img_prompt, source_image_component=None,
))

modules.script_callbacks.after_ui_callback()

modules.scripts.scripts_current = None

with gr.Blocks(analytics_enabled=False) as extras_interface:
Expand Down