diff options
author | AUTOMATIC1111 <16777216c@gmail.com> | 2023-01-13 11:43:42 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-13 11:43:42 +0000 |
commit | 7bf3cfc427099184874b021208c52eece71b7eaa (patch) | |
tree | 85d1474ef55149ffb4f17464dbf4dc73fa15b2b5 /modules/script_callbacks.py | |
parent | a176d89487d92f5a5b152401e5c424b34ff43b96 (diff) | |
parent | 6c88eaed4f5efca54a882eb1f8f30f01f350332a (diff) | |
download | stable-diffusion-webui-gfx803-7bf3cfc427099184874b021208c52eece71b7eaa.tar.gz stable-diffusion-webui-gfx803-7bf3cfc427099184874b021208c52eece71b7eaa.tar.bz2 stable-diffusion-webui-gfx803-7bf3cfc427099184874b021208c52eece71b7eaa.zip |
Merge pull request #6685 from space-nuko/script-callback-fix-infotext
Add script callback for fixing infotext parameters
Diffstat (limited to 'modules/script_callbacks.py')
-rw-r--r-- | modules/script_callbacks.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/modules/script_callbacks.py b/modules/script_callbacks.py index 608c5300..a9e19236 100644 --- a/modules/script_callbacks.py +++ b/modules/script_callbacks.py @@ -2,7 +2,7 @@ import sys import traceback
from collections import namedtuple
import inspect
-from typing import Optional
+from typing import Optional, Dict, Any
from fastapi import FastAPI
from gradio import Blocks
@@ -71,6 +71,7 @@ callback_map = dict( callbacks_before_component=[],
callbacks_after_component=[],
callbacks_image_grid=[],
+ callbacks_infotext_pasted=[],
callbacks_script_unloaded=[],
)
@@ -172,6 +173,14 @@ def image_grid_callback(params: ImageGridLoopParams): report_exception(c, 'image_grid')
+def infotext_pasted_callback(infotext: str, params: Dict[str, Any]):
+ for c in callback_map['callbacks_infotext_pasted']:
+ try:
+ c.callback(infotext, params)
+ except Exception:
+ report_exception(c, 'infotext_pasted')
+
+
def script_unloaded_callback():
for c in reversed(callback_map['callbacks_script_unloaded']):
try:
@@ -290,6 +299,15 @@ def on_image_grid(callback): add_callback(callback_map['callbacks_image_grid'], callback)
+def on_infotext_pasted(callback):
+ """register a function to be called before applying an infotext.
+ The callback is called with two arguments:
+ - infotext: str - raw infotext.
+ - result: Dict[str, any] - parsed infotext parameters.
+ """
+ add_callback(callback_map['callbacks_infotext_pasted'], callback)
+
+
def on_script_unloaded(callback):
"""register a function to be called before the script is unloaded. Any hooks/hijacks/monkeying about that
the script did should be reverted here"""
|