refactor: Replace Linux-specific directory selection with cross-platform tkinter dialog

This commit is contained in:
Bobby Abellana (aider) 2025-02-11 11:23:52 -08:00
parent 47f4287470
commit 800ae3b262

View File

@ -168,31 +168,19 @@ with col1:
key='source_dir_input',
help="Enter the full path to the directory containing files to process")
if st.button("Select Source Directory", key='source_browse'):
if st.button("Browse Source Directory", key='source_browse'):
try:
import subprocess
if platform.system() == "Linux":
result = subprocess.run(
['zenity', '--file-selection', '--directory'],
capture_output=True,
text=True
)
if result.returncode == 0:
path = result.stdout.strip()
st.session_state['source_dir'] = path
st.session_state['source_dir_input'] = path
st.experimental_rerun()
else: # Windows or MacOS
import tkinter as tk
from tkinter import filedialog
root = tk.Tk()
root.withdraw()
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()
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)}")
@ -202,31 +190,19 @@ with col1:
key='dest_dir_input',
help="Enter the full path where processed files will be saved")
if st.button("Select Destination Directory", key='dest_browse'):
if st.button("Browse Destination Directory", key='dest_browse'):
try:
import subprocess
if platform.system() == "Linux":
result = subprocess.run(
['zenity', '--file-selection', '--directory'],
capture_output=True,
text=True
)
if result.returncode == 0:
path = result.stdout.strip()
st.session_state['dest_dir'] = path
st.session_state['dest_dir_input'] = path
st.experimental_rerun()
else: # Windows or MacOS
import tkinter as tk
from tkinter import filedialog
root = tk.Tk()
root.withdraw()
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()
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)}")