images history delete a number of images consecutively next
This commit is contained in:
parent
df97947b21
commit
716a9e034f
2 changed files with 39 additions and 29 deletions
|
@ -101,7 +101,7 @@ function images_history_get_current_img(tabname, image_path, files){
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
function images_history_delete(tabname, img_path, img_file_name, page_index, filenames, image_index){
|
function images_history_delete(del_num, tabname, img_path, img_file_name, page_index, filenames, image_index){
|
||||||
image_index = parseInt(image_index);
|
image_index = parseInt(image_index);
|
||||||
var tab = gradioApp().getElementById(tabname + '_images_history');
|
var tab = gradioApp().getElementById(tabname + '_images_history');
|
||||||
var set_btn = tab.querySelector(".images_history_set_index");
|
var set_btn = tab.querySelector(".images_history_set_index");
|
||||||
|
@ -112,23 +112,29 @@ function images_history_delete(tabname, img_path, img_file_name, page_index, fil
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var img_num = buttons.length / 2;
|
var img_num = buttons.length / 2;
|
||||||
if (img_num === 1){
|
if (img_num <= del_num){
|
||||||
setTimeout(function(tabname){
|
setTimeout(function(tabname){
|
||||||
gradioApp().getElementById(tabname + '_images_history_renew_page').click();
|
gradioApp().getElementById(tabname + '_images_history_renew_page').click();
|
||||||
}, 30, tabname);
|
}, 30, tabname);
|
||||||
} else {
|
} else {
|
||||||
buttons[image_index].style.display = 'none';
|
var next_img
|
||||||
buttons[image_index + img_num].style.display = 'none';
|
for (var i = 0; i < del_num; i++){
|
||||||
|
if (image_index + i < image_index + img_num){
|
||||||
|
buttons[image_index + i].style.display = 'none';
|
||||||
|
buttons[image_index + img_num + 1].style.display = 'none';
|
||||||
|
next_img = image_index + i + 1
|
||||||
|
}
|
||||||
|
}
|
||||||
var bnt;
|
var bnt;
|
||||||
if (image_index >= img_num - 1){
|
if (next_img >= img_num){
|
||||||
btn = buttons[img_num - 2];
|
btn = buttons[image_index - del_num];
|
||||||
} else {
|
} else {
|
||||||
btn = buttons[image_index + 1] ;
|
btn = buttons[next_img];
|
||||||
}
|
}
|
||||||
setTimeout(function(btn){btn.click()}, 30, btn);
|
setTimeout(function(btn){btn.click()}, 30, btn);
|
||||||
}
|
}
|
||||||
images_history_disabled_del();
|
images_history_disabled_del();
|
||||||
return [tabname, img_path, img_file_name, page_index, filenames, image_index];
|
return [del_num, tabname, img_path, img_file_name, page_index, filenames, image_index];
|
||||||
}
|
}
|
||||||
|
|
||||||
function images_history_turnpage(img_path, page_index, image_index, tabname){
|
function images_history_turnpage(img_path, page_index, image_index, tabname){
|
||||||
|
|
|
@ -54,23 +54,26 @@ def show_image_info(num, image_path, filenames):
|
||||||
#print(f"select image {num}")
|
#print(f"select image {num}")
|
||||||
file = filenames[int(num)]
|
file = filenames[int(num)]
|
||||||
return file, num, os.path.join(image_path, file)
|
return file, num, os.path.join(image_path, file)
|
||||||
def delete_image(tabname, dir_name, name, page_index, filenames, image_index):
|
def delete_image(delete_num, tabname, dir_name, name, page_index, filenames, image_index):
|
||||||
path = os.path.join(dir_name, name)
|
delete_num = int(delete_num)
|
||||||
if os.path.exists(path):
|
index = list(filenames).index(name)
|
||||||
print(f"Delete file {path}")
|
i = 0
|
||||||
os.remove(path)
|
new_file_list = []
|
||||||
txt_file = os.path.splitext(path)[0] + ".txt"
|
for name in filenames:
|
||||||
if os.path.exists(txt_file):
|
if i >= index and i < index + delete_num:
|
||||||
os.remove(txt_file)
|
path = os.path.join(dir_name, name)
|
||||||
new_file_list = []
|
if os.path.exists(path):
|
||||||
for f in filenames:
|
print(f"Delete file {path}")
|
||||||
if f == name:
|
os.remove(path)
|
||||||
continue
|
txt_file = os.path.splitext(path)[0] + ".txt"
|
||||||
new_file_list.append(f)
|
if os.path.exists(txt_file):
|
||||||
else:
|
os.remove(txt_file)
|
||||||
print(f"Not exists file {path}")
|
else:
|
||||||
new_file_list = filenames
|
print(f"Not exists file {path}")
|
||||||
return page_index, new_file_list
|
else:
|
||||||
|
new_file_list.append(name)
|
||||||
|
i += 1
|
||||||
|
return page_index, new_file_list, 1
|
||||||
|
|
||||||
def show_images_history(gr, opts, tabname, run_pnginfo, switch_dict):
|
def show_images_history(gr, opts, tabname, run_pnginfo, switch_dict):
|
||||||
if tabname == "txt2img":
|
if tabname == "txt2img":
|
||||||
|
@ -90,10 +93,11 @@ def show_images_history(gr, opts, tabname, run_pnginfo, switch_dict):
|
||||||
with gr.Row():
|
with gr.Row():
|
||||||
with gr.Column(scale=2):
|
with gr.Column(scale=2):
|
||||||
history_gallery = gr.Gallery(show_label=False, elem_id=tabname + "_images_history_gallery").style(grid=6)
|
history_gallery = gr.Gallery(show_label=False, elem_id=tabname + "_images_history_gallery").style(grid=6)
|
||||||
delete = gr.Button('Delete', elem_id=tabname + "_images_history_del_button")
|
with gr.Row():
|
||||||
|
delete = gr.Button('Delete', elem_id=tabname + "_images_history_del_button")
|
||||||
|
delete_num = gr.Number(value=1, interactive=True, label="number of images to delete consecutively next")
|
||||||
with gr.Column():
|
with gr.Column():
|
||||||
with gr.Row():
|
with gr.Row():
|
||||||
#pnginfo = gr.Button('PNG info')
|
|
||||||
pnginfo_send_to_txt2img = gr.Button('Send to txt2img')
|
pnginfo_send_to_txt2img = gr.Button('Send to txt2img')
|
||||||
pnginfo_send_to_img2img = gr.Button('Send to img2img')
|
pnginfo_send_to_img2img = gr.Button('Send to img2img')
|
||||||
with gr.Row():
|
with gr.Row():
|
||||||
|
@ -127,7 +131,7 @@ def show_images_history(gr, opts, tabname, run_pnginfo, switch_dict):
|
||||||
#other funcitons
|
#other funcitons
|
||||||
set_index.click(show_image_info, _js="images_history_get_current_img", inputs=[tabname_box, img_path, filenames], outputs=[img_file_name, image_index, hide_image])
|
set_index.click(show_image_info, _js="images_history_get_current_img", inputs=[tabname_box, img_path, filenames], outputs=[img_file_name, image_index, hide_image])
|
||||||
img_file_name.change(fn=None, _js="images_history_enable_del_buttons", inputs=None, outputs=None)
|
img_file_name.change(fn=None, _js="images_history_enable_del_buttons", inputs=None, outputs=None)
|
||||||
delete.click(delete_image,_js="images_history_delete", inputs=[tabname_box, img_path, img_file_name, page_index, filenames, image_index], outputs=[page_index, filenames])
|
delete.click(delete_image,_js="images_history_delete", inputs=[delete_num, tabname_box, img_path, img_file_name, page_index, filenames, image_index], outputs=[page_index, filenames, delete_num])
|
||||||
hide_image.change(fn=run_pnginfo, inputs=[hide_image], outputs=[info1, img_file_info, info2])
|
hide_image.change(fn=run_pnginfo, inputs=[hide_image], outputs=[info1, img_file_info, info2])
|
||||||
|
|
||||||
#pnginfo.click(fn=run_pnginfo, inputs=[hide_image], outputs=[info1, img_file_info, info2])
|
#pnginfo.click(fn=run_pnginfo, inputs=[hide_image], outputs=[info1, img_file_info, info2])
|
||||||
|
|
Loading…
Reference in a new issue