diff --git a/CHANGELOG.md b/CHANGELOG.md index 5bbfd5e..2182ca6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +### v2.2.6 - 2024 Sep.18 +- Allow disabling `do_not_save_to_config` to use **Defaults** + ### v2.2.5 - 2024 Aug.30 - Correct Y'CbCr **Conversion**? diff --git a/lib_cc/__init__.py b/lib_cc/__init__.py index 09d0517..e69de29 100644 --- a/lib_cc/__init__.py +++ b/lib_cc/__init__.py @@ -1,2 +0,0 @@ -from .callback import * -from .settings import * diff --git a/lib_cc/callback.py b/lib_cc/callback.py index bbf121c..31d1147 100644 --- a/lib_cc/callback.py +++ b/lib_cc/callback.py @@ -1,10 +1,11 @@ from modules.sd_samplers_kdiffusion import KDiffusionSampler -from modules.script_callbacks import on_script_unloaded +from modules.script_callbacks import on_script_unloaded, on_ui_settings from functools import wraps from random import random import torch from .scaling import apply_scaling +from .settings import settings class NoiseMethods: @@ -177,3 +178,4 @@ def restore_callback(): on_script_unloaded(restore_callback) +on_ui_settings(settings) diff --git a/lib_cc/settings.py b/lib_cc/settings.py index e100168..ac01193 100644 --- a/lib_cc/settings.py +++ b/lib_cc/settings.py @@ -1,5 +1,9 @@ -from modules.script_callbacks import on_ui_settings from modules.shared import OptionInfo, opts +from modules import scripts +from json import load, dump +import os + +section = ("cc", "Vectorscope CC") def settings(): @@ -8,9 +12,37 @@ def settings(): OptionInfo( True, "Append Vectorscope CC parameters to generation information", - section=("infotext", "Infotext"), + section=section, + category_id="sd", + ), + ) + + opts.add_option( + "cc_no_defaults", + OptionInfo( + True, + 'Add the "do_not_save_to_config" flag to all components', + section=section, + category_id="sd", + onchange=reset_ui_config, + ) + .needs_reload_ui() + .info( + "Uncheck this option if you wish to use the built-in Defaults function) (enable this option again if the extension is not functioning correctly after an update" ), ) -on_ui_settings(settings) +def reset_ui_config(): + extension = "cc.py" + ui_config = os.path.join(scripts.basedir(), "ui-config.json") + + with open(ui_config, "r", encoding="utf-8") as json_file: + configs = load(json_file) + + cleaned_configs = { + key: value for key, value in configs.items() if extension not in key + } + + with open(ui_config, "w", encoding="utf-8") as json_file: + dump(cleaned_configs, json_file) diff --git a/scripts/cc.py b/scripts/cc.py index 7877c6f..d769f2b 100644 --- a/scripts/cc.py +++ b/scripts/cc.py @@ -4,14 +4,14 @@ from modules import shared, scripts from lib_cc.colorpicker import create_colorpicker from lib_cc.style import StyleManager from lib_cc.xyz import xyz_support +from lib_cc import callback from lib_cc import const from random import seed import gradio as gr -import lib_cc -VERSION = "2.2.5" +VERSION = "2.2.6" style_manager = StyleManager() @@ -131,6 +131,18 @@ class VectorscopeCC(scripts.Script): ) delete_btn = gr.Button(value="Delete Style", scale=2) + [ + setattr(comp, "do_not_save_to_config", True) + for comp in ( + style_choice, + apply_btn, + refresh_btn, + style_name, + save_btn, + delete_btn, + ) + ] + with gr.Accordion("Advanced Settings", open=False): with gr.Row(): doHR = gr.Checkbox(label="Process Hires. fix") @@ -269,7 +281,8 @@ class VectorscopeCC(scripts.Script): ] for comp, name in self.infotext_fields: - comp.do_not_save_to_config = True + if getattr(shared.opts, "cc_no_defaults", True): + comp.do_not_save_to_config = True self.paste_field_names.append(name) return [enable, *comps]