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',
|
key='source_dir_input',
|
||||||
help="Enter the full path to the directory containing files to process")
|
help="Enter the full path to the directory containing files to process")
|
||||||
|
|
||||||
# Use a file uploader as directory selector
|
if st.button("Select Source Directory", key='source_browse'):
|
||||||
source_dir_files = st.file_uploader("Or select any file from the source directory",
|
try:
|
||||||
key='source_dir_selector',
|
import subprocess
|
||||||
help="Select any file from the directory you want to process")
|
if platform.system() == "Linux":
|
||||||
if source_dir_files:
|
result = subprocess.run(
|
||||||
dir_path = os.path.dirname(source_dir_files.name)
|
['zenity', '--file-selection', '--directory'],
|
||||||
st.session_state['source_dir'] = dir_path
|
capture_output=True,
|
||||||
st.session_state['source_dir_input'] = dir_path
|
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
|
# Destination Directory
|
||||||
dest_dir = st.text_input("Destination Directory Path",
|
dest_dir = st.text_input("Destination Directory Path",
|
||||||
@ -183,14 +202,33 @@ with col1:
|
|||||||
key='dest_dir_input',
|
key='dest_dir_input',
|
||||||
help="Enter the full path where processed files will be saved")
|
help="Enter the full path where processed files will be saved")
|
||||||
|
|
||||||
# Use a file uploader as directory selector
|
if st.button("Select Destination Directory", key='dest_browse'):
|
||||||
dest_dir_files = st.file_uploader("Or select any file from the destination directory",
|
try:
|
||||||
key='dest_dir_selector',
|
import subprocess
|
||||||
help="Select any file from the directory where you want to save processed files")
|
if platform.system() == "Linux":
|
||||||
if dest_dir_files:
|
result = subprocess.run(
|
||||||
dir_path = os.path.dirname(dest_dir_files.name)
|
['zenity', '--file-selection', '--directory'],
|
||||||
st.session_state['dest_dir'] = dir_path
|
capture_output=True,
|
||||||
st.session_state['dest_dir_input'] = dir_path
|
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:
|
with col2:
|
||||||
if file_type == "Excel":
|
if file_type == "Excel":
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user