feat: Add tkinter directory browsing with error handling in Streamlit app
This commit is contained in:
parent
c4e107b40e
commit
336541fcae
@ -4,8 +4,9 @@ import logging
|
||||
import warnings
|
||||
import shutil
|
||||
from io import BytesIO
|
||||
from io import BytesIO
|
||||
import tempfile
|
||||
import tkinter as tk
|
||||
from tkinter import filedialog
|
||||
import zipfile
|
||||
from pathlib import Path
|
||||
import glob
|
||||
@ -161,29 +162,43 @@ with col1:
|
||||
else: # Select Directory
|
||||
# Source Directory
|
||||
source_dir = st.text_input("Source Directory Path",
|
||||
value=st.session_state.get('source_dir', ''),
|
||||
key='source_dir_input',
|
||||
help="Enter the full path to the directory containing files to process")
|
||||
source_browse = st.button("Browse Source Directory")
|
||||
if source_browse:
|
||||
path = get_directory_path("Select Source Directory")
|
||||
if path:
|
||||
st.session_state['source_dir'] = path
|
||||
st.session_state['source_dir_input'] = path
|
||||
st.experimental_rerun()
|
||||
value=st.session_state.get('source_dir', ''),
|
||||
key='source_dir_input',
|
||||
help="Enter the full path to the directory containing files to process")
|
||||
|
||||
if st.button("Browse Source Directory", key='source_browse'):
|
||||
try:
|
||||
root = tk.Tk()
|
||||
root.withdraw()
|
||||
root.wm_attributes('-topmost', 1)
|
||||
path = filedialog.askdirectory(title="Select Source Directory")
|
||||
root.destroy()
|
||||
if path:
|
||||
st.session_state['source_dir'] = path
|
||||
st.session_state['source_dir_input'] = path
|
||||
st.experimental_rerun()
|
||||
except Exception as e:
|
||||
st.error(f"Error opening directory dialog: {str(e)}")
|
||||
|
||||
# Destination Directory
|
||||
dest_dir = st.text_input("Destination Directory Path",
|
||||
value=st.session_state.get('dest_dir', ''),
|
||||
key='dest_dir_input',
|
||||
help="Enter the full path where processed files will be saved")
|
||||
dest_browse = st.button("Browse Destination Directory")
|
||||
if dest_browse:
|
||||
path = get_directory_path("Select Destination Directory")
|
||||
if path:
|
||||
st.session_state['dest_dir'] = path
|
||||
st.session_state['dest_dir_input'] = path
|
||||
st.experimental_rerun()
|
||||
value=st.session_state.get('dest_dir', ''),
|
||||
key='dest_dir_input',
|
||||
help="Enter the full path where processed files will be saved")
|
||||
|
||||
if st.button("Browse Destination Directory", key='dest_browse'):
|
||||
try:
|
||||
root = tk.Tk()
|
||||
root.withdraw()
|
||||
root.wm_attributes('-topmost', 1)
|
||||
path = filedialog.askdirectory(title="Select Destination Directory")
|
||||
root.destroy()
|
||||
if path:
|
||||
st.session_state['dest_dir'] = path
|
||||
st.session_state['dest_dir_input'] = path
|
||||
st.experimental_rerun()
|
||||
except Exception as e:
|
||||
st.error(f"Error opening directory dialog: {str(e)}")
|
||||
|
||||
with col2:
|
||||
if file_type == "Excel":
|
||||
|
||||
Loading…
Reference in New Issue
Block a user