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 warnings
|
||||||
import shutil
|
import shutil
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from io import BytesIO
|
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import tkinter as tk
|
||||||
|
from tkinter import filedialog
|
||||||
import zipfile
|
import zipfile
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import glob
|
import glob
|
||||||
@ -164,26 +165,40 @@ with col1:
|
|||||||
value=st.session_state.get('source_dir', ''),
|
value=st.session_state.get('source_dir', ''),
|
||||||
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")
|
||||||
source_browse = st.button("Browse Source Directory")
|
|
||||||
if source_browse:
|
if st.button("Browse Source Directory", key='source_browse'):
|
||||||
path = get_directory_path("Select Source Directory")
|
try:
|
||||||
|
root = tk.Tk()
|
||||||
|
root.withdraw()
|
||||||
|
root.wm_attributes('-topmost', 1)
|
||||||
|
path = filedialog.askdirectory(title="Select Source Directory")
|
||||||
|
root.destroy()
|
||||||
if path:
|
if path:
|
||||||
st.session_state['source_dir'] = path
|
st.session_state['source_dir'] = path
|
||||||
st.session_state['source_dir_input'] = path
|
st.session_state['source_dir_input'] = path
|
||||||
st.experimental_rerun()
|
st.experimental_rerun()
|
||||||
|
except Exception as e:
|
||||||
|
st.error(f"Error opening directory dialog: {str(e)}")
|
||||||
|
|
||||||
# Destination Directory
|
# Destination Directory
|
||||||
dest_dir = st.text_input("Destination Directory Path",
|
dest_dir = st.text_input("Destination Directory Path",
|
||||||
value=st.session_state.get('dest_dir', ''),
|
value=st.session_state.get('dest_dir', ''),
|
||||||
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")
|
||||||
dest_browse = st.button("Browse Destination Directory")
|
|
||||||
if dest_browse:
|
if st.button("Browse Destination Directory", key='dest_browse'):
|
||||||
path = get_directory_path("Select Destination Directory")
|
try:
|
||||||
|
root = tk.Tk()
|
||||||
|
root.withdraw()
|
||||||
|
root.wm_attributes('-topmost', 1)
|
||||||
|
path = filedialog.askdirectory(title="Select Destination Directory")
|
||||||
|
root.destroy()
|
||||||
if path:
|
if path:
|
||||||
st.session_state['dest_dir'] = path
|
st.session_state['dest_dir'] = path
|
||||||
st.session_state['dest_dir_input'] = path
|
st.session_state['dest_dir_input'] = path
|
||||||
st.experimental_rerun()
|
st.experimental_rerun()
|
||||||
|
except Exception as e:
|
||||||
|
st.error(f"Error opening directory dialog: {str(e)}")
|
||||||
|
|
||||||
with col2:
|
with col2:
|
||||||
if file_type == "Excel":
|
if file_type == "Excel":
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user