refactor: Simplify tkinter file/directory browsing in Streamlit app
This commit is contained in:
parent
cc3a7d1175
commit
367353d451
@ -176,18 +176,17 @@ 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():
|
col1_browse1, col1_browse2 = st.columns([1, 4])
|
||||||
if st.button("Browse Source Directory", key='source_browse'):
|
with col1_browse1:
|
||||||
|
if st.button("Browse", key='source_browse'):
|
||||||
try:
|
try:
|
||||||
root = tk.Tk()
|
root = tk.Tk()
|
||||||
root.withdraw()
|
root.withdraw()
|
||||||
root.wm_attributes('-topmost', 1)
|
|
||||||
path = filedialog.askdirectory(title="Select Source Directory")
|
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()
|
root.destroy()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
st.error(f"Error opening directory dialog: {str(e)}")
|
st.error(f"Error opening directory dialog: {str(e)}")
|
||||||
|
|
||||||
@ -197,18 +196,17 @@ 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():
|
col2_browse1, col2_browse2 = st.columns([1, 4])
|
||||||
if st.button("Browse Destination Directory", key='dest_browse'):
|
with col2_browse1:
|
||||||
|
if st.button("Browse", key='dest_browse'):
|
||||||
try:
|
try:
|
||||||
root = tk.Tk()
|
root = tk.Tk()
|
||||||
root.withdraw()
|
root.withdraw()
|
||||||
root.wm_attributes('-topmost', 1)
|
|
||||||
path = filedialog.askdirectory(title="Select Destination Directory")
|
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()
|
root.destroy()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
st.error(f"Error opening directory dialog: {str(e)}")
|
st.error(f"Error opening directory dialog: {str(e)}")
|
||||||
|
|
||||||
@ -235,18 +233,19 @@ 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', ''))
|
||||||
if is_running_locally():
|
col3_browse1, col3_browse2 = st.columns([1, 4])
|
||||||
if st.button("Browse Password File"):
|
with col3_browse1:
|
||||||
|
if st.button("Browse", key='password_browse'):
|
||||||
try:
|
try:
|
||||||
root = tk.Tk()
|
root = tk.Tk()
|
||||||
root.withdraw()
|
root.withdraw()
|
||||||
root.wm_attributes('-topmost', 1)
|
path = filedialog.askopenfilename(
|
||||||
path = filedialog.askopenfilename(title="Select Password File",
|
title="Select Password File",
|
||||||
filetypes=[("Text Files", "*.txt")])
|
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()
|
root.destroy()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
st.error(f"Error opening file dialog: {str(e)}")
|
st.error(f"Error opening file dialog: {str(e)}")
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user