diff --git a/README.md b/README.md index c4849f3..a75c408 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ and restart your stable-diffusion-webui, then you can see the new tab "Image Bro 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. ## Recent updates +- "All"-tab showing all the images from all tabs combined - Image Reward scoring - Size tooltip for thumbnails - Optimized images in the thumbnail interface diff --git a/scripts/image_browser.py b/scripts/image_browser.py index 8249d2a..78f1541 100644 --- a/scripts/image_browser.py +++ b/scripts/image_browser.py @@ -85,23 +85,25 @@ js_dummy_return = None log_file = os.path.join(scripts.basedir(), "image_browser.log") image_reward_model = None -def check_image_browser_active_tabs(): - # Check if Maintenance tab has been added to settings in addition to as a mandatory tab. If so, remove. - if hasattr(opts, "image_browser_active_tabs"): - active_tabs_no_maint = re.sub(r",\s*Maintenance", "", opts.image_browser_active_tabs) - if len(active_tabs_no_maint) != len(opts.image_browser_active_tabs): - shared.opts.__setattr__("image_browser_active_tabs", active_tabs_no_maint) - shared.opts.save(shared.config_filename) +db_version = wib_db.check() favorite_tab_name = "Favorites" -default_tab_options = ["txt2img", "img2img", "txt2img-grids", "img2img-grids", "Extras", favorite_tab_name, "Others"] +default_tab_options = ["txt2img", "img2img", "txt2img-grids", "img2img-grids", "Extras", favorite_tab_name, "Others", "All", "Maintenance"] + +def check_image_browser_active_tabs(): + last_default_tab = wib_db.get_last_default_tab() + if last_default_tab[0] == "Others": + # New tabs don't exist yet in image_browser_active_tabs, add them + conn, cursor = wib_db.transaction_begin() + wib_db.update_db_data(cursor, "last_default_tab", "Maintenance") + wib_db.transaction_end(conn, cursor) + if hasattr(opts, "image_browser_active_tabs"): + active_and_new_tabs = f"{opts.image_browser_active_tabs}, All, Maintenance" + shared.opts.__setattr__("image_browser_active_tabs", active_and_new_tabs) + shared.opts.save(shared.config_filename) + check_image_browser_active_tabs() -tabs_list = [tab.strip() for tab in chain.from_iterable(csv.reader(StringIO(opts.image_browser_active_tabs))) if tab] if hasattr(opts, "image_browser_active_tabs") else default_tab_options -try: - if opts.image_browser_enable_maint: - tabs_list.append("Maintenance") # mandatory tab -except AttributeError: - tabs_list.append("Maintenance") # mandatory tab +tabs_list = [tab.strip() for tab in chain.from_iterable(csv.reader(StringIO(opts.image_browser_active_tabs))) if tab] if hasattr(opts, "image_browser_active_tabs") and opts.image_browser_active_tabs != "" else default_tab_options path_maps = { "txt2img": opts.outdir_samples or opts.outdir_txt2img_samples, @@ -230,6 +232,7 @@ def restart_debug(parameter): logger.debug(f.read()) logger.debug(os.path.realpath(__file__)) logger.debug([str(tab) for tab in tabs_list]) + logger.debug(f"db_version: {db_version}") maint_last_msg = "Debug restarted" return parameter, maint_last_msg @@ -445,7 +448,7 @@ def traverse_all_files(curr_path, image_list, tab_base_tag_box, img_path_depth) if os.path.splitext(fname)[1] in image_ext_list: image_list.append(f_info) elif stat.S_ISDIR(fstat.st_mode): - if (opts.image_browser_with_subdirs and tab_base_tag_box != "image_browser_tab_others") or (tab_base_tag_box == "image_browser_tab_others" and img_path_depth != 0 and (current_depth < img_path_depth or img_path_depth < 0)): + if (opts.image_browser_with_subdirs and tab_base_tag_box != "image_browser_tab_others") or (tab_base_tag_box == "image_browser_tab_all") or (tab_base_tag_box == "image_browser_tab_others" and img_path_depth != 0 and (current_depth < img_path_depth or img_path_depth < 0)): current_depth = current_depth + 1 image_list = traverse_all_files(fname, image_list, tab_base_tag_box, img_path_depth) current_depth = current_depth - 1 @@ -734,7 +737,17 @@ def get_all_images(dir_name, sort_by, sort_order, keyword, tab_base_tag_box, img global current_depth logger.debug("get_all_images") current_depth = 0 - fileinfos = traverse_all_files(dir_name, [], tab_base_tag_box, img_path_depth) + fileinfos = [] + if tab_base_tag_box == "image_browser_tab_all": + for path in path_maps.values(): + list1 = fileinfos + list2 = traverse_all_files(path, [], tab_base_tag_box, img_path_depth) + tmp = dict(list1) + tmp.update(dict(list2)) + fileinfos = list(tmp.items()) + else: + fileinfos = traverse_all_files(dir_name, [], tab_base_tag_box, img_path_depth) + keyword = keyword.strip(" ") if opts.image_browser_scan_exif: @@ -1097,8 +1110,6 @@ def create_tab(tab: ImageBrowserTab, current_gr_tab: gr.Tab): path_recorder_unformatted = [] if init: - db_version = wib_db.check() - logger.debug(f"db_version: {db_version}") exif_cache = wib_db.load_exif_data(exif_cache) aes_cache = wib_db.load_exif_data_by_key(aes_cache, "aesthetic_score", "Score") image_reward_cache = wib_db.load_exif_data_by_key(image_reward_cache, "ImageRewardScore", "ImageRewardScore") @@ -1692,7 +1703,6 @@ def on_ui_settings(): ("image_browser_scan_exif", "images_scan_exif", True, "Scan Exif-/.txt-data (initially slower, but required for many features to work)"), ("image_browser_mod_shift", None, False, "Change CTRL keybindings to SHIFT"), ("image_browser_mod_ctrl_shift", None, False, "or to CTRL+SHIFT"), - ("image_browser_enable_maint", None, True, "Enable Maintenance tab"), ("image_browser_ranking_pnginfo", None, False, "Save ranking in image's pnginfo"), ("image_browser_page_columns", "images_history_page_columns", 6, "Number of columns on the page"), ("image_browser_page_rows", "images_history_page_rows", 6, "Number of rows on the page"), diff --git a/scripts/wib/wib_db.py b/scripts/wib/wib_db.py index 4ff9ed1..0609e41 100644 --- a/scripts/wib/wib_db.py +++ b/scripts/wib/wib_db.py @@ -5,7 +5,7 @@ import sqlite3 from modules import scripts from PIL import Image -version = 6 +version = 7 path_recorder_file = os.path.join(scripts.basedir(), "path_recorder.txt") aes_cache_file = os.path.join(scripts.basedir(), "aes_scores.json") @@ -302,6 +302,18 @@ def get_version(): return db_version +def get_last_default_tab(): + with sqlite3.connect(db_file, timeout=timeout) as conn: + cursor = conn.cursor() + cursor.execute(''' + SELECT value + FROM db_data + WHERE key = 'last_default_tab' + ''',) + last_default_tab = cursor.fetchone() + + return last_default_tab + def migrate_path_recorder_dirs(cursor): cursor.execute(''' SELECT path, path_display @@ -434,6 +446,8 @@ def check(): migrate_filehash(cursor, db_version[0]) if db_version[0] <= "5": migrate_work_files(cursor) + if db_version[0] <= "6": + update_db_data(cursor, "last_default_tab", "Others") update_db_data(cursor, "version", version) print(f"Image Browser: Database upgraded from version {db_version[0]} to version {version}") transaction_end(conn, cursor) diff --git a/style.css b/style.css index 0037c04..7f6d00c 100644 --- a/style.css +++ b/style.css @@ -14,6 +14,21 @@ div[id^="image_browser_tab"][id$="image_browser_gallery"].hide_loading > .svelte object-fit: scale-down !important; } +/* hack to fix the alignment of the page index, refresh, and delete buttons*/ +div[id$='control_image_browser_page_index'] { + margin-top: -20px !important; + margin-left: 10px !important; + display: grid; + justify-content: end; +} +button[id$='_control_image_browser_refresh_index']{ + align-self: start !important; + height: 2em !important; +} +button[id$='_image_browser_del_img_btn'] { + margin-top: 22px !important; +} + /* Workaround until gradio version is updated to a version that fixes it see https://github.com/gradio-app/gradio/issues/1590 */