diff options
author | brkirch <brkirch@users.noreply.github.com> | 2023-01-04 00:40:16 -0500 |
---|---|---|
committer | brkirch <brkirch@users.noreply.github.com> | 2023-01-06 00:14:20 -0500 |
commit | f6ab5a39d762a7791573d1c52ae5a3024b10e8ed (patch) | |
tree | c3958d77a6dae42457b571dbe0f1efec7ce45dd2 /modules/script_callbacks.py | |
parent | d782a95967c9eea753df3333cd1954b6ec73eba0 (diff) | |
parent | 3e22e294135ed0327ce9d9738655ff03c53df3c0 (diff) |
Merge branch 'AUTOMATIC1111:master' into sub-quad_attn_opt
Diffstat (limited to 'modules/script_callbacks.py')
-rw-r--r-- | modules/script_callbacks.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/modules/script_callbacks.py b/modules/script_callbacks.py index 8e22f875..de69fd9f 100644 --- a/modules/script_callbacks.py +++ b/modules/script_callbacks.py @@ -51,6 +51,13 @@ class UiTrainTabParams: self.txt2img_preview_params = txt2img_preview_params
+class ImageGridLoopParams:
+ def __init__(self, imgs, cols, rows):
+ self.imgs = imgs
+ self.cols = cols
+ self.rows = rows
+
+
ScriptCallback = namedtuple("ScriptCallback", ["script", "callback"])
callback_map = dict(
callbacks_app_started=[],
@@ -63,6 +70,7 @@ callback_map = dict( callbacks_cfg_denoiser=[],
callbacks_before_component=[],
callbacks_after_component=[],
+ callbacks_image_grid=[],
)
@@ -155,6 +163,14 @@ def after_component_callback(component, **kwargs): report_exception(c, 'after_component_callback')
+def image_grid_callback(params: ImageGridLoopParams):
+ for c in callback_map['callbacks_image_grid']:
+ try:
+ c.callback(params)
+ except Exception:
+ report_exception(c, 'image_grid')
+
+
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'
@@ -255,3 +271,11 @@ def on_before_component(callback): def on_after_component(callback):
"""register a function to be called after a component is created. See on_before_component for more."""
add_callback(callback_map['callbacks_after_component'], callback)
+
+
+def on_image_grid(callback):
+ """register a function to be called before making an image grid.
+ The callback is called with one argument:
+ - params: ImageGridLoopParams - parameters to be used for grid creation. Can be modified.
+ """
+ add_callback(callback_map['callbacks_image_grid'], callback)
|