fire checkbox change event (#77)

pull/79/head
Won-Kyu Park 2023-10-14 01:58:15 +09:00 committed by GitHub
parent 4a3c7a86e0
commit 3889ebc8e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View File

@ -1,3 +1,7 @@
let dynthres_update_enabled = function() {
return Array.from(arguments);
};
(function(){
let accordions = {};
let enabled = {};
@ -5,6 +9,16 @@
let accordion_id_prefix = "#dynthres_";
let extension_checkbox_class = ".dynthres-enabled";
dynthres_update_enabled = function() {
let res = Array.from(arguments);
let tabname = res[1] ? "img2img" : "txt2img";
let checkbox = accordions[tabname]?.querySelector(extension_checkbox_class + ' input');
checkbox?.dispatchEvent(new Event('change'));
return res;
};
function attachEnabledButtonListener(checkbox, accordion) {
let span = accordion.querySelector('.label-wrap span');
let badge = document.createElement('input');

View File

@ -42,6 +42,8 @@ class Script(scripts.Script):
def vis_change(isVis):
return {"visible": isVis, "__type__": "update"}
# "Dynamic Thresholding (CFG Scale Fix)"
dtrue = gr.Checkbox(value=True, visible=False)
dfalse = gr.Checkbox(value=False, visible=False)
with gr.Accordion("Dynamic Thresholding (CFG Scale Fix)", open=False, elem_id="dynthres_" + ("img2img" if is_img2img else "txt2img")):
with gr.Row():
enabled = gr.Checkbox(value=False, label="Enable Dynamic Thresholding (CFG Scale Fix)", elem_classes=["dynthres-enabled"])
@ -68,8 +70,9 @@ class Script(scripts.Script):
cfg_mode.change(shouldShowSchedulerValue, inputs=[cfg_mode, mimic_mode], outputs=[sched_val, mimic_scale_min, cfg_scale_min])
mimic_mode.change(shouldShowSchedulerValue, inputs=[cfg_mode, mimic_mode], outputs=[sched_val, mimic_scale_min, cfg_scale_min])
enabled.change(
fn=lambda x: {"visible": x, "__type__": "update"},
inputs=[enabled],
_js="dynthres_update_enabled",
fn=lambda x, y: {"visible": x, "__type__": "update"},
inputs=[enabled, dtrue if is_img2img else dfalse],
outputs=[accordion],
show_progress = False)
self.infotext_fields = (