Skip to content

Commit 15c03c1

Browse files
authored
Merge pull request yfszzx#75 from EllangoK/main
Allows for configurable hiding of ui components
2 parents 8b748ed + 473cfca commit 15c03c1

File tree

2 files changed

+91
-57
lines changed

2 files changed

+91
-57
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ and restart your stable-diffusion-webui, then you can see the new tab "Image Bro
1717
Please be aware that when scanning a directory for the first time, the png-cache will be built. This can take several minutes, depending on the amount of images.
1818

1919
## Recent updates
20+
- Hidable UI components
2021
- Send to openOutpaint
2122
- Regex search
2223
- Maximum aesthetic_score filter
@@ -49,4 +50,4 @@ Please be aware that when scanning a directory for the first time, the png-cache
4950

5051
## Credit
5152

52-
Credit goes to the original maintainer of this extension: https://github.com/yfszzx and to major contributor https://github.com/Klace
53+
Credit goes to the original maintainer of this extension: https://github.com/yfszzx and to major contributors https://github.com/Klace and https://github.com/EllangoK

scripts/image_browser.py

+89-56
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from modules import paths, shared, script_callbacks, scripts, images
1818
from modules.shared import opts, cmd_opts
1919
from modules.ui_common import plaintext_to_html
20-
from modules.ui_components import ToolButton
20+
from modules.ui_components import ToolButton, DropdownMulti
2121
from scripts.wib import wib_db
2222
from PIL import Image
2323
from PIL.ExifTags import TAGS
@@ -45,6 +45,8 @@
4545
except AttributeError:
4646
tabs_list.append("Maintenance") # mandatory tab
4747

48+
components_list = ["Sort by", "Filename keyword search", "EXIF keyword search", "Ranking Filter", "Aesthestic Score", "Generation Info", "File Name", "File Time", "Open Folder", "Send to buttons", "Copy to directory", "Gallery Controls Bar", "Ranking Bar", "Delete Bar", "Additional Generation Info"]
49+
4850
num_of_imgs_per_page = 0
4951
loads_files_num = 0
5052
image_ext_list = [".png", ".jpg", ".jpeg", ".bmp", ".gif", ".webp"]
@@ -837,14 +839,14 @@ def create_tab(tab: ImageBrowserTab, current_gr_tab: gr.Tab):
837839
with gr.Column():
838840
with gr.Row():
839841
with gr.Column(scale=2):
840-
with gr.Row():
842+
with gr.Row() as gallery_controls_panel:
841843
first_page = gr.Button('First Page')
842844
prev_page = gr.Button('Prev Page', elem_id=f"{tab.base_tag}_image_browser_prev_page")
843845
page_index = gr.Number(value=1, label="Page Index")
844846
refresh_index_button = ToolButton(value=refresh_symbol)
845847
next_page = gr.Button('Next Page', elem_id=f"{tab.base_tag}_image_browser_next_page")
846848
end_page = gr.Button('End Page')
847-
with gr.Row():
849+
with gr.Row() as ranking_panel:
848850
ranking = gr.Radio(value="None", choices=["1", "2", "3", "4", "5", "None"], label="ranking", elem_id=f"{tab.base_tag}_image_browser_ranking", interactive=True, visible=False)
849851
with gr.Row():
850852
image_gallery = gr.Gallery(show_label=False, elem_id=f"{tab.base_tag}_image_browser_gallery").style(grid=opts.image_browser_page_columns)
@@ -855,34 +857,34 @@ def create_tab(tab: ImageBrowserTab, current_gr_tab: gr.Tab):
855857
with gr.Column(scale=3):
856858
delete = gr.Button('Delete', elem_id=f"{tab.base_tag}_image_browser_del_img_btn")
857859
with gr.Row() as info_add_panel:
858-
with gr.Accordion("Additional Generate Info", open=False):
860+
with gr.Accordion("Additional Generation Info", open=False):
859861
img_file_info_add = gr.HTML()
860862

861863
with gr.Column(scale=1):
862-
with gr.Row(scale=0.5):
863-
sort_by = gr.Dropdown(value="date", choices=["path name", "date", "aesthetic_score", "random", "cfg scale", "steps", "seed", "sampler", "size", "model", "model hash", "ranking"], label="sort by")
864+
with gr.Row(scale=0.5) as sort_panel:
865+
sort_by = gr.Dropdown(value="date", choices=["path name", "date", "aesthetic_score", "random", "cfg scale", "steps", "seed", "sampler", "size", "model", "model hash", "ranking"], label="Sort by")
864866
sort_order = ToolButton(value=down_symbol)
865-
with gr.Row():
866-
keyword = gr.Textbox(value="", label="filename keyword")
867-
with gr.Box():
867+
with gr.Row() as filename_search_panel:
868+
filename_keyword_search = gr.Textbox(value="", label="Filename keyword search")
869+
with gr.Box() as exif_search_panel:
868870
with gr.Row():
869-
exif_keyword = gr.Textbox(value="", label="exif keyword")
871+
exif_keyword_search = gr.Textbox(value="", label="EXIF keyword search")
870872
negative_prompt_search = gr.Radio(value="No", choices=["No", "Yes", "Only"], label="Search negative prompt", interactive=True)
871873
with gr.Row():
872874
case_sensitive = gr.Checkbox(value=False, label="case sensitive")
873875
use_regex = gr.Checkbox(value=False, label=r"regex - e.g. ^(?!.*Hires).*$")
874-
with gr.Column():
875-
ranking_filter = gr.Radio(value="All", choices=["All", "1", "2", "3", "4", "5", "None"], label="ranking filter", interactive=True)
876-
with gr.Row():
877-
aes_filter_min = gr.Textbox(value="", label="minimum aesthetic_score")
878-
aes_filter_max = gr.Textbox(value="", label="maximum aesthetic_score")
879-
with gr.Row():
880-
img_file_info = gr.Textbox(label="Generate Info", interactive=False, lines=6)
881-
with gr.Row():
876+
with gr.Column() as ranking_filter_panel:
877+
ranking_filter = gr.Radio(value="All", choices=["All", "1", "2", "3", "4", "5", "None"], label="Ranking filter", interactive=True)
878+
with gr.Row() as aesthetic_score_filter_panel:
879+
aes_filter_min = gr.Textbox(value="", label="Minimum aesthetic_score")
880+
aes_filter_max = gr.Textbox(value="", label="Maximum aesthetic_score")
881+
with gr.Row() as generation_info_panel:
882+
img_file_info = gr.Textbox(label="Generation Info", interactive=False, lines=6)
883+
with gr.Row() as filename_panel:
882884
img_file_name = gr.Textbox(value="", label="File Name", interactive=False)
883-
with gr.Row():
885+
with gr.Row() as filetime_panel:
884886
img_file_time= gr.HTML()
885-
with gr.Row():
887+
with gr.Row() as open_folder_panel:
886888
open_folder_button = gr.Button(folder_symbol, visible=standard_ui or others_dir)
887889
gr.HTML("&nbsp")
888890
gr.HTML("&nbsp")
@@ -964,6 +966,34 @@ def create_tab(tab: ImageBrowserTab, current_gr_tab: gr.Tab):
964966
with gr.Column(scale=10):
965967
gr.HTML(visible=False)
966968

969+
# Hide components based on opts.image_browser_hidden_components
970+
hidden_component_map = {
971+
"Sort by": sort_panel,
972+
"Filename keyword search": filename_search_panel,
973+
"EXIF keyword search": exif_search_panel,
974+
"Ranking Filter": ranking_filter_panel,
975+
"Aesthestic Score": aesthetic_score_filter_panel,
976+
"Generation Info": generation_info_panel,
977+
"File Name": filename_panel,
978+
"File Time": filetime_panel,
979+
"Open Folder": open_folder_panel,
980+
"Send to buttons": button_panel,
981+
"Copy to directory": to_dir_panel,
982+
"Gallery Controls Bar": gallery_controls_panel,
983+
"Ranking Bar": ranking_panel,
984+
"Delete Bar": delete_panel,
985+
"Additional Generation Info": info_add_panel
986+
}
987+
988+
if set(hidden_component_map.keys()) != set(components_list):
989+
logger.warning(f"Invalid items present in either hidden_component_map or components_list. Make sure when adding new components they are added to both.")
990+
991+
override_hidden = set()
992+
if hasattr(opts, "image_browser_hidden_components"):
993+
for item in opts.image_browser_hidden_components:
994+
hidden_component_map[item].visible = False
995+
override_hidden.add(hidden_component_map[item])
996+
967997
change_dir_outputs = [warning_box, main_panel, img_path_browser, path_recorder, load_switch, img_path, img_path_depth]
968998
img_path.submit(change_dir, inputs=[img_path, path_recorder, load_switch, img_path_browser, img_path_depth, img_path], outputs=change_dir_outputs)
969999
img_path_browser.change(change_dir, inputs=[img_path_browser, path_recorder, load_switch, img_path_browser, img_path_depth, img_path], outputs=change_dir_outputs)
@@ -986,8 +1016,8 @@ def create_tab(tab: ImageBrowserTab, current_gr_tab: gr.Tab):
9861016
prev_page.click(lambda p, s: (p - 1, -s), inputs=[page_index, turn_page_switch], outputs=[page_index, turn_page_switch])
9871017
end_page.click(lambda s: (-1, -s), inputs=[turn_page_switch], outputs=[page_index, turn_page_switch])
9881018
load_switch.change(lambda s:(1, -s), inputs=[turn_page_switch], outputs=[page_index, turn_page_switch])
989-
keyword.submit(lambda s:(1, -s), inputs=[turn_page_switch], outputs=[page_index, turn_page_switch])
990-
exif_keyword.submit(lambda s:(1, -s), inputs=[turn_page_switch], outputs=[page_index, turn_page_switch])
1019+
filename_keyword_search.submit(lambda s:(1, -s), inputs=[turn_page_switch], outputs=[page_index, turn_page_switch])
1020+
exif_keyword_search.submit(lambda s:(1, -s), inputs=[turn_page_switch], outputs=[page_index, turn_page_switch])
9911021
aes_filter_min.submit(lambda s:(1, -s), inputs=[turn_page_switch], outputs=[page_index, turn_page_switch])
9921022
aes_filter_max.submit(lambda s:(1, -s), inputs=[turn_page_switch], outputs=[page_index, turn_page_switch])
9931023
sort_by.change(lambda s:(1, -s), inputs=[turn_page_switch], outputs=[page_index, turn_page_switch])
@@ -999,11 +1029,12 @@ def create_tab(tab: ImageBrowserTab, current_gr_tab: gr.Tab):
9991029

10001030
turn_page_switch.change(
10011031
fn=get_image_page,
1002-
inputs=[img_path, page_index, filenames, keyword, sort_by, sort_order, tab_base_tag_box, img_path_depth, ranking_filter, aes_filter_min, aes_filter_max, exif_keyword, negative_prompt_search, use_regex, case_sensitive, delete_state],
1032+
inputs=[img_path, page_index, filenames, filename_keyword_search, sort_by, sort_order, tab_base_tag_box, img_path_depth, ranking_filter, aes_filter_min, aes_filter_max, exif_keyword_search, negative_prompt_search, use_regex, case_sensitive, delete_state],
10031033
outputs=[filenames, page_index, image_gallery, img_file_name, img_file_time, img_file_info, visible_img_num, warning_box, delete_state, hidden]
10041034
)
10051035
turn_page_switch.change(fn=None, inputs=[tab_base_tag_box], outputs=None, _js="image_browser_turnpage")
1006-
turn_page_switch.change(fn=lambda:(gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)), inputs=None, outputs=[delete_panel, button_panel, ranking, to_dir_panel, info_add_panel])
1036+
hide_on_thumbnail_view = [delete_panel, button_panel, ranking, to_dir_panel, info_add_panel]
1037+
turn_page_switch.change(fn=lambda:(gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)), inputs=None, outputs=hide_on_thumbnail_view)
10071038

10081039
sort_order.click(
10091040
fn=sort_order_flip,
@@ -1047,7 +1078,7 @@ def create_tab(tab: ImageBrowserTab, current_gr_tab: gr.Tab):
10471078

10481079
# other functions
10491080
set_index.click(show_image_info, _js="image_browser_get_current_img", inputs=[tab_base_tag_box, image_index, page_index, filenames, turn_page_switch], outputs=[img_file_name, img_file_time, image_index, hidden, turn_page_switch, img_file_info_add])
1050-
set_index.click(fn=lambda:(gr.update(visible=True), gr.update(visible=True), gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)), inputs=None, outputs=[delete_panel, button_panel, ranking, to_dir_panel, info_add_panel])
1081+
set_index.click(fn=lambda:(gr.update(visible=delete_panel not in override_hidden), gr.update(visible=button_panel not in override_hidden), gr.update(visible=ranking_panel not in override_hidden), gr.update(visible=to_dir_panel not in override_hidden), gr.update(visible=info_add_panel not in override_hidden)), inputs=None, outputs=hide_on_thumbnail_view)
10511082
img_file_name.change(fn=lambda : "", inputs=None, outputs=[collected_warning])
10521083
img_file_name.change(get_ranking, inputs=img_file_name, outputs=ranking)
10531084

@@ -1140,59 +1171,61 @@ def on_ui_tabs():
11401171
gr.Textbox(",".join( [tab.base_tag for tab in tabs_list] ), elem_id="image_browser_tab_base_tags_list", visible=False)
11411172
return (image_browser , "Image Browser", "image_browser"),
11421173

1143-
def move_setting(options, section, added):
1174+
def move_setting(cur_setting_name, old_setting_name, option_info, section, added):
11441175
try:
1145-
old_value = shared.opts.__getattr__(options[3])
1176+
old_value = shared.opts.__getattr__(old_setting_name)
11461177
except AttributeError:
11471178
old_value = None
11481179
try:
1149-
new_value = shared.opts.__getattr__(options[0])
1180+
new_value = shared.opts.__getattr__(cur_setting_name)
11501181
except AttributeError:
11511182
new_value = None
11521183
if old_value is not None and new_value is None:
11531184
# Add new option
1154-
shared.opts.add_option(options[0], shared.OptionInfo(options[1], options[2], section=section))
1155-
shared.opts.__setattr__(options[0], old_value)
1185+
shared.opts.add_option(cur_setting_name, shared.OptionInfo(*option_info, section=section))
1186+
shared.opts.__setattr__(cur_setting_name, old_value)
11561187
added = added + 1
11571188
# Remove old option
1158-
shared.opts.data.pop(options[3], None)
1189+
shared.opts.data.pop(old_setting_name, None)
11591190

11601191
return added
11611192

11621193
def on_ui_settings():
1163-
image_browser_options = []
1164-
# [current setting_name], [default], [label], [old setting_name]
1194+
# [current setting_name], [old setting_name], [default], [label], [component], [component_args]
11651195
active_tabs_description = f"List of active tabs (separated by commas). Available options are {', '.join(default_tab_options)}. Custom folders are also supported by specifying their path."
1166-
image_browser_options.append(("image_browser_active_tabs", ", ".join(default_tab_options), active_tabs_description, None))
1167-
image_browser_options.append(("image_browser_with_subdirs", True, "Include images in sub directories", "images_history_with_subdirs"))
1168-
image_browser_options.append(("image_browser_preload", False, "Preload images at startup", "images_history_preload"))
1169-
image_browser_options.append(("image_browser_copy_image", False, "Move buttons copy instead of move", "images_copy_image"))
1170-
image_browser_options.append(("image_browser_delete_message", True, "Print image deletion messages to the console", "images_delete_message"))
1171-
image_browser_options.append(("image_browser_txt_files", True, "Move/Copy/Delete matching .txt files", "images_txt_files"))
1172-
image_browser_options.append(("image_browser_logger_warning", False, "Print warning logs to the console", "images_logger_warning"))
1173-
image_browser_options.append(("image_browser_logger_debug", False, "Print debug logs to the console", "images_logger_debug"))
1174-
image_browser_options.append(("image_browser_delete_recycle", False, "Use recycle bin when deleting images", "images_delete_recycle"))
1175-
image_browser_options.append(("image_browser_scan_exif", True, "Scan Exif-/.txt-data (slower, but required for exif-keyword-search)", "images_scan_exif"))
1176-
image_browser_options.append(("image_browser_mod_shift", False, "Change CTRL keybindings to SHIFT", None))
1177-
image_browser_options.append(("image_browser_mod_ctrl_shift", False, "or to CTRL+SHIFT", None))
1178-
image_browser_options.append(("image_browser_enable_maint", True, "Enable Maintenance tab", None))
1179-
image_browser_options.append(("image_browser_ranking_pnginfo", False, "Save ranking in image's pnginfo", None))
1180-
1181-
image_browser_options.append(("image_browser_page_columns", 6, "Number of columns on the page", "images_history_page_columns"))
1182-
image_browser_options.append(("image_browser_page_rows", 6, "Number of rows on the page", "images_history_page_rows"))
1183-
image_browser_options.append(("image_browser_pages_perload", 20, "Minimum number of pages per load", "images_history_pages_perload"))
1196+
1197+
image_browser_options = [
1198+
("image_browser_active_tabs", None, ", ".join(default_tab_options), active_tabs_description),
1199+
("image_browser_hidden_components", None, [], "Select components to hide", DropdownMulti, lambda: {"choices": components_list}),
1200+
("image_browser_with_subdirs", "images_history_with_subdirs", True, "Include images in sub directories"),
1201+
("image_browser_preload", "images_history_preload", False, "Preload images at startup"),
1202+
("image_browser_copy_image", "images_copy_image", False, "Move buttons copy instead of move"),
1203+
("image_browser_delete_message", "images_delete_message", True, "Print image deletion messages to the console"),
1204+
("image_browser_txt_files", "images_txt_files", True, "Move/Copy/Delete matching .txt files"),
1205+
("image_browser_logger_warning", "images_logger_warning", False, "Print warning logs to the console"),
1206+
("image_browser_logger_debug", "images_logger_debug", False, "Print debug logs to the console"),
1207+
("image_browser_delete_recycle", "images_delete_recycle", False, "Use recycle bin when deleting images"),
1208+
("image_browser_scan_exif", "images_scan_exif", True, "Scan Exif-/.txt-data (slower, but required for exif-keyword-search)"),
1209+
("image_browser_mod_shift", None, False, "Change CTRL keybindings to SHIFT"),
1210+
("image_browser_mod_ctrl_shift", None, False, "or to CTRL+SHIFT"),
1211+
("image_browser_enable_maint", None, True, "Enable Maintenance tab"),
1212+
("image_browser_ranking_pnginfo", None, False, "Save ranking in image's pnginfo"),
1213+
("image_browser_page_columns", "images_history_page_columns", 6, "Number of columns on the page"),
1214+
("image_browser_page_rows", "images_history_page_rows", 6, "Number of rows on the page"),
1215+
("image_browser_pages_perload", "images_history_pages_perload", 20, "Minimum number of pages per load"),
1216+
]
11841217

11851218
section = ('image-browser', "Image Browser")
11861219
# Move historic setting names to current names
11871220
added = 0
1188-
for i in range(len(image_browser_options)):
1189-
if image_browser_options[i][3] is not None:
1190-
added = move_setting(image_browser_options[i], section, added)
1221+
for cur_setting_name, old_setting_name, *option_info in image_browser_options:
1222+
if old_setting_name is not None:
1223+
added = move_setting(cur_setting_name, old_setting_name, option_info, section, added)
11911224
if added > 0:
11921225
shared.opts.save(shared.config_filename)
11931226

1194-
for i in range(len(image_browser_options)):
1195-
shared.opts.add_option(image_browser_options[i][0], shared.OptionInfo(image_browser_options[i][1], image_browser_options[i][2], section=section))
1227+
for cur_setting_name, _, *option_info in image_browser_options:
1228+
shared.opts.add_option(cur_setting_name, shared.OptionInfo(*option_info, section=section))
11961229

11971230
script_callbacks.on_ui_settings(on_ui_settings)
11981231
script_callbacks.on_ui_tabs(on_ui_tabs)

0 commit comments

Comments
 (0)