Commit d37cfffd authored by AUTOMATIC's avatar AUTOMATIC

added callback for creating new settings in extensions

parent 7fd90128
callbacks_model_loaded = []
callbacks_ui_tabs = []
callbacks_ui_settings = []
def clear_callbacks():
......@@ -22,6 +23,11 @@ def ui_tabs_callback():
return res
def ui_settings_callback():
for callback in callbacks_ui_settings:
callback()
def on_model_loaded(callback):
"""register a function to be called when the stable diffusion model is created; the model is
passed as an argument"""
......@@ -40,3 +46,8 @@ def on_ui_tabs(callback):
"""
callbacks_ui_tabs.append(callback)
def on_ui_settings(callback):
"""register a function to be called before UI settingsare populated; add your settings
by using shared.opts.add_option(shared.OptionInfo(...)) """
callbacks_ui_settings.append(callback)
......@@ -165,13 +165,13 @@ def realesrgan_models_names():
class OptionInfo:
def __init__(self, default=None, label="", component=None, component_args=None, onchange=None, show_on_main_page=False, refresh=None):
def __init__(self, default=None, label="", component=None, component_args=None, onchange=None, section=None, refresh=None):
self.default = default
self.label = label
self.component = component
self.component_args = component_args
self.onchange = onchange
self.section = None
self.section = section
self.refresh = refresh
......@@ -327,6 +327,7 @@ options_templates.update(options_section(('images-history', "Images Browser"), {
}))
class Options:
data = None
data_labels = options_templates
......@@ -389,6 +390,20 @@ class Options:
d = {k: self.data.get(k, self.data_labels.get(k).default) for k in self.data_labels.keys()}
return json.dumps(d)
def add_option(self, key, info):
self.data_labels[key] = info
def reorder(self):
"""reorder settings so that all items related to section always go together"""
section_ids = {}
settings_items = self.data_labels.items()
for k, item in settings_items:
if item.section not in section_ids:
section_ids[item.section] = len(section_ids)
self.data_labels = {k: v for k, v in sorted(settings_items, key=lambda x: section_ids[x[1].section])}
opts = Options()
if os.path.exists(config_filename):
......
......@@ -1461,6 +1461,9 @@ def create_ui(wrap_gradio_gpu_call):
components = []
component_dict = {}
script_callbacks.ui_settings_callback()
opts.reorder()
def open_folder(f):
if not os.path.exists(f):
print(f'Folder "{f}" does not exist. After you create an image, the folder will be created.')
......@@ -1564,7 +1567,8 @@ Requested path was: {f}
previous_section = item.section
gr.HTML(elem_id="settings_header_text_{}".format(item.section[0]), value='<h1 class="gr-button-lg">{}</h1>'.format(item.section[1]))
elem_id, text = item.section
gr.HTML(elem_id="settings_header_text_{}".format(elem_id), value='<h1 class="gr-button-lg">{}</h1>'.format(text))
if k in quicksettings_names:
quicksettings_list.append((i, k, item))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment