Skip to content

Commit

Permalink
fixed bug in file/folder pickers
Browse files Browse the repository at this point in the history
  • Loading branch information
rnmitchell committed Jul 1, 2024
1 parent 5e483cb commit fa935dd
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 4 deletions.
32 changes: 28 additions & 4 deletions lusSTR/cli/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# Importing Necessary Packages #
#################################################################

import json
import importlib.resources
import streamlit as st
from streamlit_option_menu import option_menu
Expand Down Expand Up @@ -51,14 +52,36 @@ def generate_config_file(config_data, working_directory, workflow_type):
# ------------ Function for folder selection ------------------ #

def folder_picker_dialog():
folder_path = filedialog.askdirectory(master=root)
return folder_path
script_path = importlib.resources.files("lusSTR") / "scripts" / "folder_selector.py"
result = subprocess.run(["python", script_path], capture_output=True, text=True)
if result.returncode == 0:
folder_data = json.loads(result.stdout)
folder_path = folder_data.get("folder_path")
if folder_path:
st.success(f"Selected Folder: {folder_path}")
return folder_path

else:
st.error("No folder selected")
else:
st.error("Error selecting folder")

# ------- Function for individual file selection -------------- #

def file_picker_dialog():
file_path = filedialog.askopenfilename(master=root)
return file_path
script_path = importlib.resources.files("lusSTR") / "scripts" / "file_selector.py"
result = subprocess.run(["python", script_path], capture_output=True, text=True)
if result.returncode == 0:
file_data = json.loads(result.stdout)
file_path = file_data.get("file_path")
if file_path:
st.success(f"Selected File: {file_path}")
return file_path

else:
st.error("No folder selected")
else:
st.error("Error selecting folder")

# ---- Function to validate prefix for output folder ---------- #

Expand Down Expand Up @@ -103,6 +126,7 @@ def main():
elif selected == "Contact":
show_contact_page()


#####################################################################
# lusSTR Home Page #
#####################################################################
Expand Down
29 changes: 29 additions & 0 deletions lusSTR/scripts/file_selector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2024, DHS.
#
# This file is part of lusSTR (http://github.com/bioforensics/lusSTR) and is licensed under
# the BSD license: see LICENSE.txt.
#
# This software was prepared for the Department of Homeland Security (DHS) by the Battelle National
# Biodefense Institute, LLC (BNBI) as part of contract HSHQDC-15-C-00064 to manage and operate the
# National Biodefense Analysis and Countermeasures Center (NBACC), a Federally Funded Research and
# Development Center.
# -------------------------------------------------------------------------------------------------

import tkinter as tk
from tkinter import filedialog
import sys
import json


def select_file():
root = tk.Tk()
root.withdraw() # Hide the main window
file_path = filedialog.askopenfilename() # Open the dialog to select a folder
if file_path:
print(json.dumps({"file_path": file_path}))
root.destroy()


if __name__ == "__main__":
select_file()
29 changes: 29 additions & 0 deletions lusSTR/scripts/folder_selector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2024, DHS.
#
# This file is part of lusSTR (http://github.com/bioforensics/lusSTR) and is licensed under
# the BSD license: see LICENSE.txt.
#
# This software was prepared for the Department of Homeland Security (DHS) by the Battelle National
# Biodefense Institute, LLC (BNBI) as part of contract HSHQDC-15-C-00064 to manage and operate the
# National Biodefense Analysis and Countermeasures Center (NBACC), a Federally Funded Research and
# Development Center.
# -------------------------------------------------------------------------------------------------

import tkinter as tk
from tkinter import filedialog
import sys
import json


def select_folder():
root = tk.Tk()
root.withdraw() # Hide the main window
folder_path = filedialog.askdirectory() # Open the dialog to select a folder
if folder_path:
print(json.dumps({"folder_path": folder_path}))
root.destroy()


if __name__ == "__main__":
select_folder()

0 comments on commit fa935dd

Please sign in to comment.