feat: Enhance directory selection with native dialogs for cross-platform support
This commit is contained in:
parent
80d37924c2
commit
47f4287470
@ -168,14 +168,33 @@ with col1:
|
||||
key='source_dir_input',
|
||||
help="Enter the full path to the directory containing files to process")
|
||||
|
||||
# Use a file uploader as directory selector
|
||||
source_dir_files = st.file_uploader("Or select any file from the source directory",
|
||||
key='source_dir_selector',
|
||||
help="Select any file from the directory you want to process")
|
||||
if source_dir_files:
|
||||
dir_path = os.path.dirname(source_dir_files.name)
|
||||
st.session_state['source_dir'] = dir_path
|
||||
st.session_state['source_dir_input'] = dir_path
|
||||
if st.button("Select Source Directory", key='source_browse'):
|
||||
try:
|
||||
import subprocess
|
||||
if platform.system() == "Linux":
|
||||
result = subprocess.run(
|
||||
['zenity', '--file-selection', '--directory'],
|
||||
capture_output=True,
|
||||
text=True
|
||||
)
|
||||
if result.returncode == 0:
|
||||
path = result.stdout.strip()
|
||||
st.session_state['source_dir'] = path
|
||||
st.session_state['source_dir_input'] = path
|
||||
st.experimental_rerun()
|
||||
else: # Windows or MacOS
|
||||
import tkinter as tk
|
||||
from tkinter import filedialog
|
||||
root = tk.Tk()
|
||||
root.withdraw()
|
||||
path = filedialog.askdirectory(title="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)}")
|
||||
|
||||
# Destination Directory
|
||||
dest_dir = st.text_input("Destination Directory Path",
|
||||
@ -183,14 +202,33 @@ with col1:
|
||||
key='dest_dir_input',
|
||||
help="Enter the full path where processed files will be saved")
|
||||
|
||||
# Use a file uploader as directory selector
|
||||
dest_dir_files = st.file_uploader("Or select any file from the destination directory",
|
||||
key='dest_dir_selector',
|
||||
help="Select any file from the directory where you want to save processed files")
|
||||
if dest_dir_files:
|
||||
dir_path = os.path.dirname(dest_dir_files.name)
|
||||
st.session_state['dest_dir'] = dir_path
|
||||
st.session_state['dest_dir_input'] = dir_path
|
||||
if st.button("Select Destination Directory", key='dest_browse'):
|
||||
try:
|
||||
import subprocess
|
||||
if platform.system() == "Linux":
|
||||
result = subprocess.run(
|
||||
['zenity', '--file-selection', '--directory'],
|
||||
capture_output=True,
|
||||
text=True
|
||||
)
|
||||
if result.returncode == 0:
|
||||
path = result.stdout.strip()
|
||||
st.session_state['dest_dir'] = path
|
||||
st.session_state['dest_dir_input'] = path
|
||||
st.experimental_rerun()
|
||||
else: # Windows or MacOS
|
||||
import tkinter as tk
|
||||
from tkinter import filedialog
|
||||
root = tk.Tk()
|
||||
root.withdraw()
|
||||
path = filedialog.askdirectory(title="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)}")
|
||||
|
||||
with col2:
|
||||
if file_type == "Excel":
|
||||
|
||||
Loading…
Reference in New Issue
Block a user