Skip to content

Commit 3e15f8e

Browse files
committed
update callbacks code for #3549
1 parent 91c1e1e commit 3e15f8e

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

modules/script_callbacks.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,21 @@ def ui_settings_callback():
4949
report_exception(c, 'ui_settings_callback')
5050

5151

52+
def image_saved_callback(image, p, fullfn, txt_fullfn):
53+
for c in callbacks_image_saved:
54+
try:
55+
c.callback(image, p, fullfn, txt_fullfn)
56+
except Exception:
57+
report_exception(c, 'image_saved_callback')
58+
59+
5260
def add_callback(callbacks, fun):
5361
stack = [x for x in inspect.stack() if x.filename != __file__]
5462
filename = stack[0].filename if len(stack) > 0 else 'unknown file'
5563

5664
callbacks.append(ScriptCallback(filename, fun))
5765

5866

59-
def image_saved_callback(image, p, fullfn, txt_fullfn):
60-
for callback in callbacks_image_saved:
61-
callback(image, p, fullfn, txt_fullfn)
6267

6368
def on_model_loaded(callback):
6469
"""register a function to be called when the stable diffusion model is created; the model is
@@ -82,9 +87,14 @@ def on_ui_tabs(callback):
8287
def on_ui_settings(callback):
8388
"""register a function to be called before UI settings are populated; add your settings
8489
by using shared.opts.add_option(shared.OptionInfo(...)) """
85-
callbacks_ui_settings.append(callback)
90+
add_callback(callbacks_ui_settings, callback)
8691

8792

8893
def on_save_imaged(callback):
89-
"""register a function to call after modules.images.save_image is called returning same values, original image and p """
90-
callbacks_image_saved.append(callback)
94+
"""register a function to be called after modules.images.save_image is called.
95+
The callback is called with three arguments:
96+
- p - procesing object (or a dummy object with same fields if the image is saved using save button)
97+
- fullfn - image filename
98+
- txt_fullfn - text file with parameters; may be None
99+
"""
100+
add_callback(callbacks_image_saved, callback)

0 commit comments

Comments
 (0)