Skip to content

Commit 3889ebc

Browse files
authored
fire checkbox change event (#77)
1 parent 4a3c7a8 commit 3889ebc

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

javascript/active.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
1+
let dynthres_update_enabled = function() {
2+
return Array.from(arguments);
3+
};
4+
15
(function(){
26
let accordions = {};
37
let enabled = {};
48
onUiUpdate(() => {
59
let accordion_id_prefix = "#dynthres_";
610
let extension_checkbox_class = ".dynthres-enabled";
711

12+
dynthres_update_enabled = function() {
13+
let res = Array.from(arguments);
14+
let tabname = res[1] ? "img2img" : "txt2img";
15+
16+
let checkbox = accordions[tabname]?.querySelector(extension_checkbox_class + ' input');
17+
checkbox?.dispatchEvent(new Event('change'));
18+
19+
return res;
20+
};
21+
822
function attachEnabledButtonListener(checkbox, accordion) {
923
let span = accordion.querySelector('.label-wrap span');
1024
let badge = document.createElement('input');

scripts/dynamic_thresholding.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ def ui(self, is_img2img):
4242
def vis_change(isVis):
4343
return {"visible": isVis, "__type__": "update"}
4444
# "Dynamic Thresholding (CFG Scale Fix)"
45+
dtrue = gr.Checkbox(value=True, visible=False)
46+
dfalse = gr.Checkbox(value=False, visible=False)
4547
with gr.Accordion("Dynamic Thresholding (CFG Scale Fix)", open=False, elem_id="dynthres_" + ("img2img" if is_img2img else "txt2img")):
4648
with gr.Row():
4749
enabled = gr.Checkbox(value=False, label="Enable Dynamic Thresholding (CFG Scale Fix)", elem_classes=["dynthres-enabled"])
@@ -68,8 +70,9 @@ def shouldShowSchedulerValue(cfgMode, mimicMode):
6870
cfg_mode.change(shouldShowSchedulerValue, inputs=[cfg_mode, mimic_mode], outputs=[sched_val, mimic_scale_min, cfg_scale_min])
6971
mimic_mode.change(shouldShowSchedulerValue, inputs=[cfg_mode, mimic_mode], outputs=[sched_val, mimic_scale_min, cfg_scale_min])
7072
enabled.change(
71-
fn=lambda x: {"visible": x, "__type__": "update"},
72-
inputs=[enabled],
73+
_js="dynthres_update_enabled",
74+
fn=lambda x, y: {"visible": x, "__type__": "update"},
75+
inputs=[enabled, dtrue if is_img2img else dfalse],
7376
outputs=[accordion],
7477
show_progress = False)
7578
self.infotext_fields = (

0 commit comments

Comments
 (0)