Open folder, #62, fix migrate, #63

pull/71/head
AlUlkesh 2023-03-05 15:25:33 +01:00
parent aa4e180388
commit 3d95a7d263
2 changed files with 67 additions and 20 deletions

View File

@ -7,15 +7,14 @@ import random
import re
import shutil
import stat
import subprocess as sp
import sys
import tempfile
import time
import modules.extras
import modules.images
import modules.ui
from modules import paths
from modules import script_callbacks
from modules import shared, scripts, images
from modules import paths, shared, script_callbacks, scripts, images
from modules.shared import opts, cmd_opts
from modules.ui_common import plaintext_to_html
from modules.ui_components import ToolButton
@ -58,6 +57,7 @@ refresh_symbol = '\U0001f504' # 🔄
up_symbol = '\U000025b2' # ▲
down_symbol = '\U000025bc' # ▼
caution_symbol = '\U000026a0' # ⚠
folder_symbol = '\U0001f4c2' # 📂
current_depth = 0
init = True
copy_move = ["Move", "Copy"]
@ -491,6 +491,19 @@ def natural_keys(text):
'''
return [ atof(c) for c in re.split(r'[+-]?([0-9]+(?:[.][0-9]*)?|[.][0-9]+)', text) ]
def open_folder(path):
if os.path.exists(path):
# Code from ui_common.py
if not shared.cmd_opts.hide_ui_dir_config:
if platform.system() == "Windows":
os.startfile(path)
elif platform.system() == "Darwin":
sp.Popen(["open", path])
elif "microsoft-standard-WSL2" in platform.uname().release:
sp.Popen(["wsl-open", path])
else:
sp.Popen(["xdg-open", path])
def exif_search(needle, haystack, use_regex, case_sensitive):
found = False
if use_regex:
@ -838,10 +851,16 @@ def create_tab(tab: ImageBrowserTab, current_gr_tab: gr.Tab):
aes_filter_min = gr.Textbox(value="", label="minimum aesthetic_score")
aes_filter_max = gr.Textbox(value="", label="maximum aesthetic_score")
with gr.Row():
with gr.Column():
img_file_info = gr.Textbox(label="Generate Info", interactive=False, lines=6)
img_file_name = gr.Textbox(value="", label="File Name", interactive=False)
img_file_time= gr.HTML()
img_file_info = gr.Textbox(label="Generate Info", interactive=False, lines=6)
with gr.Row():
img_file_name = gr.Textbox(value="", label="File Name", interactive=False)
with gr.Row():
img_file_time= gr.HTML()
with gr.Row():
open_folder_button = gr.Button(folder_symbol)
gr.HTML("&nbsp")
gr.HTML("&nbsp")
gr.HTML("&nbsp")
with gr.Row(elem_id=f"{tab.base_tag}_image_browser_button_panel", visible=False) as button_panel:
if tab.name != favorite_tab_name:
favorites_btn = gr.Button(f'{copy_move[opts.image_browser_copy_image]} to favorites', elem_id=f"{tab.base_tag}_image_browser_favorites_btn")
@ -1020,7 +1039,13 @@ def create_tab(tab: ImageBrowserTab, current_gr_tab: gr.Tab):
inputs=[],
outputs=[path_recorder, to_dir_saved]
)
open_folder_button.click(
fn=lambda: open_folder(dir_name),
inputs=[],
outputs=[]
)
def run_pnginfo(image, image_path, image_file_name):
if image is None:
return '', '', ''

View File

@ -243,12 +243,23 @@ def migrate_path_recorder_dirs(cursor):
if path != real_path:
update_from = path
update_to = real_path
cursor.execute('''
UPDATE path_recorder
SET path = ?,
path_display = ? || SUBSTR(path_display, LENGTH(?) + 1)
WHERE path = ?
''', (update_to, update_to, update_from, update_from))
try:
cursor.execute('''
UPDATE path_recorder
SET path = ?,
path_display = ? || SUBSTR(path_display, LENGTH(?) + 1)
WHERE path = ?
''', (update_to, update_to, update_from, update_from))
except sqlite3.IntegrityError as e:
# these are double keys, because the same file can be in the db with different path notations
(e_msg,) = e.args
if e_msg.startswith("UNIQUE constraint"):
cursor.execute('''
DELETE FROM path_recorder
WHERE path = ?
''', (update_from,))
else:
raise
return
@ -309,12 +320,23 @@ def migrate_ranking_dirs(cursor, db_version):
name = file
update_from = filepath
update_to = os.path.join(real_path, file)
cursor.execute('''
UPDATE ranking
SET file = ?,
name = ?
WHERE file = ?
''', (update_to, name, update_from))
try:
cursor.execute('''
UPDATE ranking
SET file = ?,
name = ?
WHERE file = ?
''', (update_to, name, update_from))
except sqlite3.IntegrityError as e:
# these are double keys, because the same file can be in the db with different path notations
(e_msg,) = e.args
if e_msg.startswith("UNIQUE constraint"):
cursor.execute('''
DELETE FROM ranking
WHERE file = ?
''', (update_from,))
else:
raise
return