From 02c4b757b6e4e0894c5a988b49cb8f50c0d99cc1 Mon Sep 17 00:00:00 2001 From: Michoko Date: Wed, 28 Sep 2022 10:31:53 +0200 Subject: [PATCH] Add output folder icons Handling of the --hide-ui-dir-config flag and added multi-platform code for opening a folder --- modules/ui.py | 20 ++++++++++++++++---- style.css | 4 ++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/modules/ui.py b/modules/ui.py index 4c93fca9..2dbcd50c 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -9,6 +9,8 @@ import random import sys import time import traceback +import platform +import subprocess as sp import numpy as np import torch @@ -461,7 +463,8 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo, run_modelmerger): send_to_img2img = gr.Button('Send to img2img') send_to_inpaint = gr.Button('Send to inpaint') send_to_extras = gr.Button('Send to extras') - open_txt2img_folder = gr.Button(folder_symbol, elem_id="open_folder") + button_id = "open_folder_hidden" if shared.cmd_opts.hide_ui_dir_config else 'open_folder' + open_txt2img_folder = gr.Button(folder_symbol, elem_id=button_id) with gr.Group(): html_info = gr.HTML() @@ -638,7 +641,8 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo, run_modelmerger): img2img_send_to_img2img = gr.Button('Send to img2img') img2img_send_to_inpaint = gr.Button('Send to inpaint') img2img_send_to_extras = gr.Button('Send to extras') - open_img2img_folder = gr.Button(folder_symbol, elem_id="open_folder") + button_id = "open_folder_hidden" if shared.cmd_opts.hide_ui_dir_config else 'open_folder' + open_img2img_folder = gr.Button(folder_symbol, elem_id=button_id) with gr.Group(): html_info = gr.HTML() @@ -811,7 +815,8 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo, run_modelmerger): html_info = gr.HTML() extras_send_to_img2img = gr.Button('Send to img2img') extras_send_to_inpaint = gr.Button('Send to inpaint') - open_extras_folder = gr.Button('Open output directory') + button_id = "open_folder_hidden" if shared.cmd_opts.hide_ui_dir_config else '' + open_extras_folder = gr.Button('Open output directory', elem_id=button_id) submit.click( fn=run_extras, @@ -911,7 +916,14 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo, run_modelmerger): component_dict = {} def open_folder(f): - os.startfile(os.path.normpath(f)) + if not shared.cmd_opts.hide_ui_dir_config: + path = os.path.normpath(f) + if platform.system() == "Windows": + os.startfile(path) + elif platform.system() == "Darwin": + sp.Popen(["open", path]) + else: + sp.Popen(["xdg-open", path]) def run_settings(*args): changed = 0 diff --git a/style.css b/style.css index a98c46ec..1b53f05f 100644 --- a/style.css +++ b/style.css @@ -56,6 +56,10 @@ padding-right: 0.25em; } +#open_folder_hidden{ + display: none; +} + #seed_row, #subseed_row{ gap: 0.5rem; }