17
17
from modules import paths , shared , script_callbacks , scripts , images
18
18
from modules .shared import opts , cmd_opts
19
19
from modules .ui_common import plaintext_to_html
20
- from modules .ui_components import ToolButton
20
+ from modules .ui_components import ToolButton , DropdownMulti
21
21
from scripts .wib import wib_db
22
22
from PIL import Image
23
23
from PIL .ExifTags import TAGS
45
45
except AttributeError :
46
46
tabs_list .append ("Maintenance" ) # mandatory tab
47
47
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
+
48
50
num_of_imgs_per_page = 0
49
51
loads_files_num = 0
50
52
image_ext_list = [".png" , ".jpg" , ".jpeg" , ".bmp" , ".gif" , ".webp" ]
@@ -837,14 +839,14 @@ def create_tab(tab: ImageBrowserTab, current_gr_tab: gr.Tab):
837
839
with gr .Column ():
838
840
with gr .Row ():
839
841
with gr .Column (scale = 2 ):
840
- with gr .Row ():
842
+ with gr .Row () as gallery_controls_panel :
841
843
first_page = gr .Button ('First Page' )
842
844
prev_page = gr .Button ('Prev Page' , elem_id = f"{ tab .base_tag } _image_browser_prev_page" )
843
845
page_index = gr .Number (value = 1 , label = "Page Index" )
844
846
refresh_index_button = ToolButton (value = refresh_symbol )
845
847
next_page = gr .Button ('Next Page' , elem_id = f"{ tab .base_tag } _image_browser_next_page" )
846
848
end_page = gr .Button ('End Page' )
847
- with gr .Row ():
849
+ with gr .Row () as ranking_panel :
848
850
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 )
849
851
with gr .Row ():
850
852
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):
855
857
with gr .Column (scale = 3 ):
856
858
delete = gr .Button ('Delete' , elem_id = f"{ tab .base_tag } _image_browser_del_img_btn" )
857
859
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 ):
859
861
img_file_info_add = gr .HTML ()
860
862
861
863
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" )
864
866
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 :
868
870
with gr .Row ():
869
- exif_keyword = gr .Textbox (value = "" , label = "exif keyword" )
871
+ exif_keyword_search = gr .Textbox (value = "" , label = "EXIF keyword search " )
870
872
negative_prompt_search = gr .Radio (value = "No" , choices = ["No" , "Yes" , "Only" ], label = "Search negative prompt" , interactive = True )
871
873
with gr .Row ():
872
874
case_sensitive = gr .Checkbox (value = False , label = "case sensitive" )
873
875
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 :
882
884
img_file_name = gr .Textbox (value = "" , label = "File Name" , interactive = False )
883
- with gr .Row ():
885
+ with gr .Row () as filetime_panel :
884
886
img_file_time = gr .HTML ()
885
- with gr .Row ():
887
+ with gr .Row () as open_folder_panel :
886
888
open_folder_button = gr .Button (folder_symbol , visible = standard_ui or others_dir )
887
889
gr .HTML (" " )
888
890
gr .HTML (" " )
@@ -964,6 +966,34 @@ def create_tab(tab: ImageBrowserTab, current_gr_tab: gr.Tab):
964
966
with gr .Column (scale = 10 ):
965
967
gr .HTML (visible = False )
966
968
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
+
967
997
change_dir_outputs = [warning_box , main_panel , img_path_browser , path_recorder , load_switch , img_path , img_path_depth ]
968
998
img_path .submit (change_dir , inputs = [img_path , path_recorder , load_switch , img_path_browser , img_path_depth , img_path ], outputs = change_dir_outputs )
969
999
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):
986
1016
prev_page .click (lambda p , s : (p - 1 , - s ), inputs = [page_index , turn_page_switch ], outputs = [page_index , turn_page_switch ])
987
1017
end_page .click (lambda s : (- 1 , - s ), inputs = [turn_page_switch ], outputs = [page_index , turn_page_switch ])
988
1018
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 ])
991
1021
aes_filter_min .submit (lambda s :(1 , - s ), inputs = [turn_page_switch ], outputs = [page_index , turn_page_switch ])
992
1022
aes_filter_max .submit (lambda s :(1 , - s ), inputs = [turn_page_switch ], outputs = [page_index , turn_page_switch ])
993
1023
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):
999
1029
1000
1030
turn_page_switch .change (
1001
1031
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 ],
1003
1033
outputs = [filenames , page_index , image_gallery , img_file_name , img_file_time , img_file_info , visible_img_num , warning_box , delete_state , hidden ]
1004
1034
)
1005
1035
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 )
1007
1038
1008
1039
sort_order .click (
1009
1040
fn = sort_order_flip ,
@@ -1047,7 +1078,7 @@ def create_tab(tab: ImageBrowserTab, current_gr_tab: gr.Tab):
1047
1078
1048
1079
# other functions
1049
1080
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 )
1051
1082
img_file_name .change (fn = lambda : "" , inputs = None , outputs = [collected_warning ])
1052
1083
img_file_name .change (get_ranking , inputs = img_file_name , outputs = ranking )
1053
1084
@@ -1140,59 +1171,61 @@ def on_ui_tabs():
1140
1171
gr .Textbox ("," .join ( [tab .base_tag for tab in tabs_list ] ), elem_id = "image_browser_tab_base_tags_list" , visible = False )
1141
1172
return (image_browser , "Image Browser" , "image_browser" ),
1142
1173
1143
- def move_setting (options , section , added ):
1174
+ def move_setting (cur_setting_name , old_setting_name , option_info , section , added ):
1144
1175
try :
1145
- old_value = shared .opts .__getattr__ (options [ 3 ] )
1176
+ old_value = shared .opts .__getattr__ (old_setting_name )
1146
1177
except AttributeError :
1147
1178
old_value = None
1148
1179
try :
1149
- new_value = shared .opts .__getattr__ (options [ 0 ] )
1180
+ new_value = shared .opts .__getattr__ (cur_setting_name )
1150
1181
except AttributeError :
1151
1182
new_value = None
1152
1183
if old_value is not None and new_value is None :
1153
1184
# 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 )
1156
1187
added = added + 1
1157
1188
# Remove old option
1158
- shared .opts .data .pop (options [ 3 ] , None )
1189
+ shared .opts .data .pop (old_setting_name , None )
1159
1190
1160
1191
return added
1161
1192
1162
1193
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]
1165
1195
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
+ ]
1184
1217
1185
1218
section = ('image-browser' , "Image Browser" )
1186
1219
# Move historic setting names to current names
1187
1220
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 )
1191
1224
if added > 0 :
1192
1225
shared .opts .save (shared .config_filename )
1193
1226
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 ))
1196
1229
1197
1230
script_callbacks .on_ui_settings (on_ui_settings )
1198
1231
script_callbacks .on_ui_tabs (on_ui_tabs )
0 commit comments