From 70e3af157e639216af4c8eda809ff191d6c5a5c8 Mon Sep 17 00:00:00 2001 From: "Bobby Abellana (aider)" Date: Tue, 11 Feb 2025 11:48:06 -0800 Subject: [PATCH] feat: Add tkinter-based directory browse buttons for source and destination paths --- requirements.txt | 1 + src/streamlit_app.py | 62 +++++++++++++++++++++----------------------- 2 files changed, 31 insertions(+), 32 deletions(-) diff --git a/requirements.txt b/requirements.txt index 849405d..fd40596 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,4 @@ msoffcrypto-tool>=5.0.0 tqdm>=4.65.0 streamlit>=1.24.0 python-docx>=0.8.11 +tkinter diff --git a/src/streamlit_app.py b/src/streamlit_app.py index 938a352..830acd2 100644 --- a/src/streamlit_app.py +++ b/src/streamlit_app.py @@ -171,29 +171,28 @@ with col1: col_src1, col_src2 = st.columns([1, 4]) with col_src1: - if st.button("How to Browse", key='source_browse'): - st.info(""" - To find your folder path in Windows: - 1. Open File Explorer - 2. Navigate to your desired folder - 3. Click in the address bar (or press Alt+D) - 4. Copy the full path (Ctrl+C) - 5. Paste it here (Ctrl+V) - - Example paths: - C:\\Users\\YourName\\Documents - D:\\Work\\Files - """) + if st.button("Browse", 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") + 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)}") # Add a check and display for source directory status if source_dir: - # Convert Windows path to Linux path if needed - source_dir = source_dir.replace('\\', '/') if os.path.exists(source_dir): st.success(f"āœ… Source directory exists: {source_dir}") else: st.error(f"āŒ Source directory not found: {source_dir}") - st.info("Make sure the path is accessible to the Linux server") # Destination Directory dest_dir = st.text_input("Destination Directory Path", @@ -203,24 +202,24 @@ with col1: col_dest1, col_dest2 = st.columns([1, 4]) with col_dest1: - if st.button("How to Browse", key='dest_browse'): - st.info(""" - To find your folder path in Windows: - 1. Open File Explorer - 2. Navigate to your desired folder - 3. Click in the address bar (or press Alt+D) - 4. Copy the full path (Ctrl+C) - 5. Paste it here (Ctrl+V) - - Example paths: - C:\\Users\\YourName\\Documents - D:\\Work\\Files - """) + if st.button("Browse", 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") + 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)}") # Add a check and display for destination directory status if dest_dir: - # Convert Windows path to Linux path if needed - dest_dir = dest_dir.replace('\\', '/') dest_parent = os.path.dirname(dest_dir) if os.path.exists(dest_parent): if os.path.exists(dest_dir): @@ -229,7 +228,6 @@ with col1: st.info(f"iļø Destination directory will be created: {dest_dir}") else: st.error(f"āŒ Parent directory not found: {dest_parent}") - st.info("Make sure the path is accessible to the Linux server") with col2: if file_type == "Excel":