feat: Add dialog-based directory selection for terminal environments
This commit is contained in:
parent
800ae3b262
commit
f0a002eff1
@ -17,6 +17,25 @@ from main import (
|
||||
setup_logging
|
||||
)
|
||||
|
||||
def select_directory_with_dialog(title="Select Directory"):
|
||||
"""Use dialog command to select directory in terminal environment"""
|
||||
try:
|
||||
result = subprocess.run(
|
||||
['dialog', '--title', title, '--dselect', os.getcwd(), 0, 0],
|
||||
env={'DIALOGRC': '/etc/dialogrc'},
|
||||
capture_output=True,
|
||||
text=True
|
||||
)
|
||||
if result.returncode == 0:
|
||||
return result.stderr.strip() # dialog outputs to stderr
|
||||
return None
|
||||
except FileNotFoundError:
|
||||
st.error("Please install 'dialog' package: sudo apt-get install dialog")
|
||||
return None
|
||||
except Exception as e:
|
||||
st.error(f"Error using dialog: {str(e)}")
|
||||
return None
|
||||
|
||||
def is_running_locally():
|
||||
"""Check if the app is running locally or in cloud environment"""
|
||||
return os.environ.get('STREAMLIT_SERVER_ADDRESS', '').startswith('localhost')
|
||||
@ -170,17 +189,11 @@ with col1:
|
||||
|
||||
if st.button("Browse Source Directory", key='source_browse'):
|
||||
try:
|
||||
import tkinter as tk
|
||||
from tkinter import filedialog
|
||||
root = tk.Tk()
|
||||
root.withdraw()
|
||||
root.wm_attributes('-topmost', 1)
|
||||
path = filedialog.askdirectory(title="Select Source Directory")
|
||||
path = select_directory_with_dialog("Select Source Directory")
|
||||
if path:
|
||||
st.session_state['source_dir'] = path
|
||||
st.session_state['source_dir_input'] = path
|
||||
st.experimental_rerun()
|
||||
root.destroy()
|
||||
except Exception as e:
|
||||
st.error(f"Error selecting directory: {str(e)}")
|
||||
|
||||
@ -192,17 +205,11 @@ with col1:
|
||||
|
||||
if st.button("Browse Destination Directory", key='dest_browse'):
|
||||
try:
|
||||
import tkinter as tk
|
||||
from tkinter import filedialog
|
||||
root = tk.Tk()
|
||||
root.withdraw()
|
||||
root.wm_attributes('-topmost', 1)
|
||||
path = filedialog.askdirectory(title="Select Destination Directory")
|
||||
path = select_directory_with_dialog("Select Destination Directory")
|
||||
if path:
|
||||
st.session_state['dest_dir'] = path
|
||||
st.session_state['dest_dir_input'] = path
|
||||
st.experimental_rerun()
|
||||
root.destroy()
|
||||
except Exception as e:
|
||||
st.error(f"Error selecting directory: {str(e)}")
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user