From 0dc12861efee9d1e1eacb2d1903bf0fcd43fcfcc Mon Sep 17 00:00:00 2001 From: AUTOMATIC1111 <16777216c@gmail.com> Date: Mon, 4 Mar 2024 15:30:46 +0300 Subject: [PATCH] call script_callbacks.ui_settings_callback earlier; fix extra-options-section built-in extension killing the ui if using a setting that doesn't exist --- .../scripts/extra_options_section.py | 8 ++++++-- modules/ui.py | 4 +++- modules/ui_settings.py | 4 +++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/extensions-builtin/extra-options-section/scripts/extra_options_section.py b/extensions-builtin/extra-options-section/scripts/extra_options_section.py index 4c10d9c7d..a91bea4fa 100644 --- a/extensions-builtin/extra-options-section/scripts/extra_options_section.py +++ b/extensions-builtin/extra-options-section/scripts/extra_options_section.py @@ -1,7 +1,7 @@ import math import gradio as gr -from modules import scripts, shared, ui_components, ui_settings, infotext_utils +from modules import scripts, shared, ui_components, ui_settings, infotext_utils, errors from modules.ui_components import FormColumn @@ -42,7 +42,11 @@ class ExtraOptionsSection(scripts.Script): setting_name = extra_options[index] with FormColumn(): - comp = ui_settings.create_setting_component(setting_name) + try: + comp = ui_settings.create_setting_component(setting_name) + except KeyError: + errors.report(f"Can't add extra options for {setting_name} in ui") + continue self.comps.append(comp) self.setting_names.append(setting_name) diff --git a/modules/ui.py b/modules/ui.py index dcba8e885..7b4341627 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -269,6 +269,9 @@ def create_ui(): parameters_copypaste.reset() + settings = ui_settings.UiSettings() + settings.register_settings() + scripts.scripts_current = scripts.scripts_txt2img scripts.scripts_txt2img.initialize_scripts(is_img2img=False) @@ -1116,7 +1119,6 @@ def create_ui(): loadsave = ui_loadsave.UiLoadsave(cmd_opts.ui_config_file) ui_settings_from_file = loadsave.ui_settings.copy() - settings = ui_settings.UiSettings() settings.create_ui(loadsave, dummy_component) interfaces = [ diff --git a/modules/ui_settings.py b/modules/ui_settings.py index e054d00ab..d17ef1d95 100644 --- a/modules/ui_settings.py +++ b/modules/ui_settings.py @@ -98,6 +98,9 @@ class UiSettings: return get_value_for_setting(key), opts.dumpjson() + def register_settings(self): + script_callbacks.ui_settings_callback() + def create_ui(self, loadsave, dummy_component): self.components = [] self.component_dict = {} @@ -105,7 +108,6 @@ class UiSettings: shared.settings_components = self.component_dict - script_callbacks.ui_settings_callback() opts.reorder() with gr.Blocks(analytics_enabled=False) as settings_interface: