images history delete a number of images consecutively next

This commit is contained in:
yfszzx 2022-10-13 12:19:50 +08:00
parent df97947b21
commit 716a9e034f
2 changed files with 39 additions and 29 deletions

View file

@ -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);
var tab = gradioApp().getElementById(tabname + '_images_history');
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;
if (img_num === 1){
if (img_num <= del_num){
setTimeout(function(tabname){
gradioApp().getElementById(tabname + '_images_history_renew_page').click();
}, 30, tabname);
} else {
buttons[image_index].style.display = 'none';
buttons[image_index + img_num].style.display = 'none';
var next_img
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;
if (image_index >= img_num - 1){
btn = buttons[img_num - 2];
if (next_img >= img_num){
btn = buttons[image_index - del_num];
} else {
btn = buttons[image_index + 1] ;
btn = buttons[next_img];
}
setTimeout(function(btn){btn.click()}, 30, btn);
}
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){

View file

@ -54,7 +54,13 @@ def show_image_info(num, image_path, filenames):
#print(f"select image {num}")
file = filenames[int(num)]
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):
delete_num = int(delete_num)
index = list(filenames).index(name)
i = 0
new_file_list = []
for name in filenames:
if i >= index and i < index + delete_num:
path = os.path.join(dir_name, name)
if os.path.exists(path):
print(f"Delete file {path}")
@ -62,15 +68,12 @@ def delete_image(tabname, dir_name, name, page_index, filenames, image_index):
txt_file = os.path.splitext(path)[0] + ".txt"
if os.path.exists(txt_file):
os.remove(txt_file)
new_file_list = []
for f in filenames:
if f == name:
continue
new_file_list.append(f)
else:
print(f"Not exists file {path}")
new_file_list = filenames
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):
if tabname == "txt2img":
@ -90,10 +93,11 @@ def show_images_history(gr, opts, tabname, run_pnginfo, switch_dict):
with gr.Row():
with gr.Column(scale=2):
history_gallery = gr.Gallery(show_label=False, elem_id=tabname + "_images_history_gallery").style(grid=6)
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.Row():
#pnginfo = gr.Button('PNG info')
pnginfo_send_to_txt2img = gr.Button('Send to txt2img')
pnginfo_send_to_img2img = gr.Button('Send to img2img')
with gr.Row():
@ -127,7 +131,7 @@ def show_images_history(gr, opts, tabname, run_pnginfo, switch_dict):
#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])
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])
#pnginfo.click(fn=run_pnginfo, inputs=[hide_image], outputs=[info1, img_file_info, info2])