feat: Add environment-aware directory and file browsing support

This commit is contained in:
Bobby Abellana (aider) 2025-02-11 11:12:12 -08:00
parent 336541fcae
commit c224424e04

View File

@ -19,6 +19,14 @@ from main import (
setup_logging setup_logging
) )
def is_running_locally():
"""Check if the app is running locally or in cloud environment"""
try:
import tkinter
return True
except ImportError:
return False
# Configure page # Configure page
st.set_page_config( st.set_page_config(
page_title="Office Protection Remover", page_title="Office Protection Remover",
@ -166,6 +174,7 @@ 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")
if is_running_locally():
if st.button("Browse Source Directory", key='source_browse'): if st.button("Browse Source Directory", key='source_browse'):
try: try:
root = tk.Tk() root = tk.Tk()
@ -186,6 +195,7 @@ 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")
if is_running_locally():
if st.button("Browse Destination Directory", key='dest_browse'): if st.button("Browse Destination Directory", key='dest_browse'):
try: try:
root = tk.Tk() root = tk.Tk()
@ -223,12 +233,20 @@ with col2:
password_path = st.text_input("Password File Path", password_path = st.text_input("Password File Path",
help="Enter the full path to the text file containing passwords", help="Enter the full path to the text file containing passwords",
value=st.session_state.get('password_path', '')) value=st.session_state.get('password_path', ''))
password_browse = st.button("Browse Password File") if is_running_locally():
if password_browse: if st.button("Browse Password File"):
path = get_file_path("Select Password File", [("Text Files", "*.txt")]) try:
root = tk.Tk()
root.withdraw()
root.wm_attributes('-topmost', 1)
path = filedialog.askopenfilename(title="Select Password File",
filetypes=[("Text Files", "*.txt")])
root.destroy()
if path: if path:
st.session_state['password_path'] = path st.session_state['password_path'] = path
st.experimental_rerun() st.experimental_rerun()
except Exception as e:
st.error(f"Error opening file dialog: {str(e)}")
if password_path and os.path.exists(password_path): if password_path and os.path.exists(password_path):
with open(password_path, 'r', encoding='utf-8') as pf: with open(password_path, 'r', encoding='utf-8') as pf: