Skip to content

Commit e16cab6

Browse files
authored
Merge pull request #4 from Tencent/Branch_dev
Branch dev
2 parents e9b61fd + ceee81d commit e16cab6

File tree

8 files changed

+613
-121
lines changed

8 files changed

+613
-121
lines changed

ChangeLog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 2.1.0
2+
3+
### Bug Fixes:
4+
* py实现与js一样的创建组件编号,优化导入逻辑,部分dropdown组件改由py处理,降低UI面板无限转圈概率。
5+
* 修复了一些已知的问题。
6+
17
## 2.0.4
28

39
### Bug Fixes:

javascript/state.core.js

Lines changed: 76 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ state.core = (function () {
8686
fetch('/lightdiffusionflow/local/need_preload')
8787
.then(response => response.json())
8888
.then(data => {
89-
//console.log(`fn_timer ${data}`)
89+
//console.log(`fn_timer`)
9090
if (data != ""){
9191
//state.core.actions.handleLightDiffusionFlow([{"name":data}]);
9292
const btn1 = gradioApp().querySelector(`button#set_lightdiffusionflow_file`);
@@ -104,6 +104,11 @@ state.core = (function () {
104104
}
105105

106106
let img_elem_keys=[];
107+
108+
function get_imgs_elem_key(){
109+
return img_elem_keys;
110+
}
111+
107112
function init() {
108113

109114
//console.log(window.localization)
@@ -163,7 +168,6 @@ state.core = (function () {
163168
}
164169

165170
function load(config) {
166-
167171
config.hasSetting = hasSetting
168172

169173
//loadUI(); // 往页面上添加按钮
@@ -476,8 +480,9 @@ state.core = (function () {
476480
// alert('All state values deleted!');
477481
// }
478482
// },
479-
applyState: function () {
480-
fetch('/lightdiffusionflow/local/config.json?_=' + (+new Date()))
483+
applyState: async function () {
484+
console.log("applyState")
485+
await fetch('/lightdiffusionflow/local/config.json?_=' + (+new Date()))
481486
.then(response => response.json())
482487
.then(config => {
483488
try {
@@ -639,7 +644,6 @@ state.core = (function () {
639644
actions.output_log("Please select a valid lightdiffusionflow or image file!")
640645
return;
641646
}
642-
console.log(json_obj)
643647

644648
forEachElement_WithoutTabs(IMAGES_WITHOUT_PREFIX, (image_id) => {
645649
json_obj[image_id] = ""
@@ -648,54 +652,86 @@ state.core = (function () {
648652
store.clear();
649653
store.load(json_obj);
650654
actions.applyState();
651-
652655
return;
653656
},
654657
startImportImage: function (index){
658+
index = Number(index)
659+
660+
if(index+1 < img_elem_keys.length){
661+
//console.log(`---------${img_elem_keys}---------------`)
662+
//console.log(`---------${index}-----${img_elem_keys.length}-----------`)
663+
switch_tab_dict = {
664+
"txt2img_invisible_img2img_image": "switch_to_img2img()",
665+
"txt2img_invisible_img2img_sketch": "switch_to_sketch()",
666+
"txt2img_invisible_img2maskimg": "switch_to_inpaint()",
667+
"txt2img_invisible_inpaint_sketch": "switch_to_inpaint_sketch()",
668+
"txt2img_invisible_img_inpaint_base": "state.utils.switch_to_img_inpaint()",
669+
"txt2img_invisible_img_inpaint_mask": "state.utils.switch_to_img_inpaint()",
670+
"txt2img_invisible_txt2img_controlnet_ControlNet_input_image": "state.utils.switch_to_txt2img_ControlNet(0)",
671+
"txt2img_invisible_img2img_controlnet_ControlNet_input_image": "state.utils.switch_to_img2img_ControlNet(0)"
672+
}
673+
674+
for (let i = 0; i < 10; i++) {
675+
switch_tab_dict[`txt2img_invisible_txt2img_controlnet_ControlNet-${i}_input_image`] = `state.utils.switch_to_txt2img_ControlNet(${i})`
676+
switch_tab_dict[`txt2img_invisible_img2img_controlnet_ControlNet-${i}_input_image`] = `state.utils.switch_to_img2img_ControlNet(${i})`
677+
}
655678

656-
switch_tab_dict = {
657-
"txt2img_invisible_img2img_image": "switch_to_img2img()",
658-
"txt2img_invisible_img2img_sketch": "switch_to_sketch()",
659-
"txt2img_invisible_img2maskimg": "switch_to_inpaint()",
660-
"txt2img_invisible_inpaint_sketch": "switch_to_inpaint_sketch()",
661-
"txt2img_invisible_img_inpaint_base": "state.utils.switch_to_img_inpaint()",
662-
"txt2img_invisible_img_inpaint_mask": "state.utils.switch_to_img_inpaint()",
663-
"txt2img_invisible_txt2img_controlnet_ControlNet_input_image": "state.utils.switch_to_txt2img_ControlNet(0)",
664-
"txt2img_invisible_img2img_controlnet_ControlNet_input_image": "state.utils.switch_to_img2img_ControlNet(0)"
665-
}
666-
667-
for (let i = 0; i < 10; i++) {
668-
switch_tab_dict[`txt2img_invisible_txt2img_controlnet_ControlNet-${i}_input_image`] = `state.utils.switch_to_txt2img_ControlNet(${i})`
669-
switch_tab_dict[`txt2img_invisible_img2img_controlnet_ControlNet-${i}_input_image`] = `state.utils.switch_to_img2img_ControlNet(${i})`
679+
state.utils.sleep(300).then(() => {
680+
try{
681+
key = "txt2img_invisible_"+img_elem_keys[index+1]
682+
eval( switch_tab_dict[key] ) // 跳转界面
683+
const button = gradioApp().getElementById(key);
684+
button.click();
685+
} catch (error) {
686+
console.warn('[startImportImage]: Error:', error);
687+
if(index+1 < img_elem_keys.length){
688+
// 图片组件设置出错了,但是需要继续后续的流程
689+
690+
index = img_elem_keys.length-1
691+
}
692+
}
693+
});
670694
}
671695

672-
state.utils.sleep(300).then(() => {
673-
674-
try{
675-
key = "txt2img_invisible_"+img_elem_keys[Number(index)+1]
676-
//console.log(key)
677-
eval( switch_tab_dict[key] ) // 跳转界面
678-
const button = gradioApp().getElementById(key);
679-
button.click();
680-
} catch (error) {
681-
console.warn('[startImportImage]: Error:', error);
682-
}
683-
684-
});
696+
switch(index+1 - img_elem_keys.length){
697+
case 0:// 图片导入完成,开始导入Dropdown
698+
state.utils.sleep(500).then(() => {
699+
try{
700+
const button = gradioApp().getElementById("lightdiffusionflow_set_dropdowns");
701+
button.click();
702+
} catch (error) {
703+
console.warn('[set_dropdowns]: Error:', error);
704+
}
705+
});
706+
break
707+
// case 1:// 触发了导入Dropdown,现在导入其他参数会卡死,触发导入按钮,等下一轮正式开始导入
708+
// state.utils.sleep(500).then(() => {
709+
// const button = gradioApp().getElementById("lightdiffusionflow_set_js_params");
710+
// console.log("lightdiffusionflow_set_js_params")
711+
// button.click();
712+
// });
713+
// break
714+
// case 2:// 导入其他参数
715+
// state.utils.sleep(500).then(() => {
716+
// console.log("导入其他参数")
717+
// actions.applyState();
718+
// });
719+
// break
720+
}
685721

686722
},
687-
output_log: function (msg, style=""){
688-
fetch(`/lightdiffusionflow/local/output_log?msg=${msg}&style=${style}`).then(() => {
723+
output_log: function (msg, msg_style=""){
724+
fetch(`/lightdiffusionflow/local/output_log?msg=${msg}&style=${msg_style}`).then(() => {
689725
gradioApp().getElementById("txt2img_invisible_refresh_log").click();
690726
});
691727
},
692-
output_warning: function (msg, style="color:Orange;"){
693-
actions.output_log(msg,style)
728+
output_warning: function (msg, msg_style="color:Orange;"){
729+
actions.output_log(msg,msg_style)
694730
},
695-
output_error: function (msg, style="color:Tomato;"){
696-
actions.output_log(msg,style)
731+
output_error: function (msg, msg_style="color:Tomato;"){
732+
actions.output_log(msg,msg_style)
697733
}
698734
};
699735

700-
return { init,actions };
736+
return { init, actions };
701737
}());

javascript/state.ext.general.js

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ function general_ext(tab_name, extension_name, root_container) {
116116
textarea.addEventListener('change', function () {
117117
let text = this.value;
118118
store.set(id, text);
119-
console.log(`id = ${id} value = ${text}`)
119+
//console.log(`id = ${id} value = ${text}`)
120120
});
121121
}
122122
function handleTextAreas() {
@@ -154,27 +154,46 @@ function general_ext(tab_name, extension_name, root_container) {
154154

155155
}
156156

157-
function handleSelect(select, store) {
157+
function handleSelect(select, index, store) {
158158
let translations = state.utils.reverseTranslation(select.querySelector('label').firstChild.textContent)
159-
for (var text of translations){
160-
var id = state.utils.txtToId(text);
161-
var value = store.get(id);
162-
if (value) {break}
163-
}
159+
// for (var text of translations){
160+
// var id = state.utils.txtToId(text);
161+
// var value = store.get(id);
162+
// if (value) {break}
163+
// }
164164
//id = state.utils.txtToId(translations[0]);
165165
//if (value) { //前面不需要判断是否有值,因为需要执行handleSelect绑定onchange事件
166-
state.utils.handleSelect(select, id, store, force=true);
166+
//state.utils.handleSelect(select, id, store, force=true);
167167
//}
168+
169+
let id = state.constants.LS_PREFIX+LS_PREFIX+"dropdown_"+index
170+
state.utils.onContentChange(select, function (el) {
171+
console.log(`onContentChange ${id}`)
172+
let selected = el.querySelector('span.single-select');
173+
if (selected) {
174+
store.setWithNoPrefix(id, selected.textContent);
175+
} else {
176+
// new gradio version...
177+
let input = el.querySelector('input');
178+
if (input) {
179+
store.setWithNoPrefix(id, input.value);
180+
}
181+
}
182+
183+
});
184+
168185
if (id === 'preprocessor' && value && value.toLowerCase() !== 'none') {
169186
state.utils.onNextUiUpdates(handleSliders); // update new sliders if needed
170187
}
171188
}
172189
function handleSelects() {
173-
190+
//let select_index = 0
174191
let root_selects = root_not_tabs.container.querySelectorAll('.gradio-dropdown');
175192
root_selects.forEach(function (root_select) {
176193
if(cnTabs.length == 0){
177-
handleSelect(root_select, root_not_tabs.store)
194+
handleSelect(root_select, global_dropdown_index[ext_name], root_not_tabs.store)
195+
global_dropdown_index[ext_name] += 1
196+
console.log(`global_dropdown_index = ${global_dropdown_index[ext_name]}`)
178197
}
179198
else{
180199
let needsHandle = true
@@ -184,13 +203,19 @@ function general_ext(tab_name, extension_name, root_container) {
184203
break
185204
}
186205
}
187-
if(needsHandle){handleCheckbox(root_select, root_not_tabs.store)}
206+
if(needsHandle){
207+
handleSelect(root_select, global_dropdown_index[ext_name], root_not_tabs.store)
208+
global_dropdown_index[ext_name] += 1
209+
console.log(`global_dropdown_index = ${global_dropdown_index[ext_name]}`)
210+
}
188211
} // else
189212
});
190213

191214
cnTabs.forEach(({ container, store }) => {
192215
container.querySelectorAll('.gradio-dropdown').forEach(select => {
193-
handleSelect(select, store)
216+
handleSelect(select, global_dropdown_index[ext_name], store)
217+
global_dropdown_index[ext_name] += 1
218+
console.log(`global_dropdown_index = ${global_dropdown_index[ext_name]}`)
194219
});
195220
});
196221

@@ -302,7 +327,7 @@ function general_ext(tab_name, extension_name, root_container) {
302327
handleTabs();
303328
handleCheckboxes();
304329
handleTextAreas();
305-
handleSelects();
330+
//handleSelects();
306331
handleSliders();
307332
handleRadioButtons();
308333
}, 500);
@@ -397,13 +422,19 @@ function general_ext_main(tab){
397422

398423
let ext_name = title.replace(" ","-").toLowerCase()
399424
console.log(ext_name)
425+
426+
if(!global_dropdown_index[ext_name]){
427+
global_dropdown_index[ext_name] = 0
428+
}
400429
general_ext(cur_tab_name, ext_name, root_container).init();
401430
}
402431

403432
}
404433
return {init}
405434
}
406435

436+
global_dropdown_index = {} // py里是不分txt2img和img2img的,但是这里是需要区分的。。
437+
407438
const TABS = ['txt2img', 'img2img'];
408439
for (tab of TABS){
409440
state.extensions[`${tab}-ext-general`] = general_ext_main(tab);

javascript/state.store.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ state.Store = function Store (prefix) {
55
this.prefix = state.constants.LS_PREFIX + (prefix ? prefix + '-' : '');
66
}
77

8+
state.Store.prototype.setWithNoPrefix = function (key, value) {
9+
localStorage.setItem(key, value);
10+
};
11+
812
state.Store.prototype.set = function (key, value) {
913
if (key.startsWith(this.prefix)) {
1014
localStorage.setItem(key, value);

0 commit comments

Comments
 (0)