Compare commits

..

No commits in common. "80d37924c246b53355407e7905269bd169a124f7" and "3e40b604bc066cdd12a93a6fba10b1a63594aac2" have entirely different histories.

View File

@ -10,6 +10,14 @@ from pathlib import Path
import glob import glob
import platform import platform
import subprocess import subprocess
# Conditionally import tkinter
try:
import tkinter as tk
from tkinter import filedialog
TKINTER_AVAILABLE = True
except ImportError:
TKINTER_AVAILABLE = False
from main import ( from main import (
load_workbook_with_possible_passwords, load_workbook_with_possible_passwords,
copy_excel_file, copy_excel_file,
@ -19,7 +27,7 @@ from main import (
def is_running_locally(): def is_running_locally():
"""Check if the app is running locally or in cloud environment""" """Check if the app is running locally or in cloud environment"""
return os.environ.get('STREAMLIT_SERVER_ADDRESS', '').startswith('localhost') return TKINTER_AVAILABLE
# Configure page # Configure page
st.set_page_config( st.set_page_config(
@ -168,14 +176,21 @@ 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 col1_browse1, col1_browse2 = st.columns([1, 4])
source_dir_files = st.file_uploader("Or select any file from the source directory", with col1_browse1:
key='source_dir_selector', if st.button("Browse", key='source_browse'):
help="Select any file from the directory you want to process") try:
if source_dir_files: import tkinter as tk
dir_path = os.path.dirname(source_dir_files.name) from tkinter import filedialog
st.session_state['source_dir'] = dir_path root = tk.Tk()
st.session_state['source_dir_input'] = dir_path root.withdraw()
path = filedialog.askdirectory(title="Select Source Directory")
if path:
st.session_state['source_dir'] = path
st.session_state['source_dir_input'] = path
root.destroy()
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",
@ -183,14 +198,21 @@ 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 col2_browse1, col2_browse2 = st.columns([1, 4])
dest_dir_files = st.file_uploader("Or select any file from the destination directory", with col2_browse1:
key='dest_dir_selector', if st.button("Browse", key='dest_browse'):
help="Select any file from the directory where you want to save processed files") try:
if dest_dir_files: import tkinter as tk
dir_path = os.path.dirname(dest_dir_files.name) from tkinter import filedialog
st.session_state['dest_dir'] = dir_path root = tk.Tk()
st.session_state['dest_dir_input'] = dir_path root.withdraw()
path = filedialog.askdirectory(title="Select Destination Directory")
if path:
st.session_state['dest_dir'] = path
st.session_state['dest_dir_input'] = path
root.destroy()
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":
@ -215,17 +237,25 @@ 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', ''))
col3_browse1, col3_browse2 = st.columns([1, 4])
# Use direct file uploader for password file with col3_browse1:
password_file_upload = st.file_uploader("Or upload password file", if st.button("Browse", key='password_browse'):
type=["txt"], try:
key='password_file_selector', import tkinter as tk
help="Upload a text file containing passwords") from tkinter import filedialog
if password_file_upload: root = tk.Tk()
content = password_file_upload.getvalue().decode() root.withdraw()
passwords = [line.strip() for line in content.splitlines() if line.strip()] path = filedialog.askopenfilename(
st.info(f"Loaded {len(passwords)} passwords") title="Select Password File",
elif password_path and os.path.exists(password_path): filetypes=[("Text Files", "*.txt")]
)
if path:
st.session_state['password_path'] = path
root.destroy()
except Exception as e:
st.error(f"Error opening file dialog: {str(e)}")
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:
passwords = [line.strip() for line in pf if line.strip()] passwords = [line.strip() for line in pf if line.strip()]
st.info(f"Loaded {len(passwords)} passwords from file") st.info(f"Loaded {len(passwords)} passwords from file")