Skip to content

Commit

Permalink
Some cleaning to pass tests
Browse files Browse the repository at this point in the history
  • Loading branch information
edouardbruelhart committed Apr 12, 2024
1 parent adadd4a commit 7935a8f
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 101 deletions.
51 changes: 42 additions & 9 deletions ms_sample_list_creator/csv_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
from datetime import datetime
from tkinter import filedialog


class csvBatch(tk.Frame):
def __init__(self, csv_batch_window, root):
def __init__(self, csv_batch_window: tk.Toplevel, root: tk.Tk):
"""
Initializes an instance of the class.
Args:
root(tk.Tk): The parent widget or window where this frame will be placed.
csv_path(str): CSV path and name.
csv_batch_window(tk.Toplevel): The parent widget where this frame will be placed.
root(tk.Tk): The root window to perform actions on it.
Returns:
None
Expand Down Expand Up @@ -43,27 +44,59 @@ def __init__(self, csv_batch_window, root):
self.timestamp = datetime.now().strftime("%Y%m%d%H%M")
self.csv_path = f"{self.output_folder}/{datetime.now().strftime('%Y%m%d')}_{self.operator}_dbgi_{self.file}.csv"

warning_label = tk.Label(self.csv_batch_window, text="Warning, this mode is exclusively made to submit sample lists that have already been made using this tool.")
warning_label = tk.Label(
self.csv_batch_window,
text="Warning, this mode is exclusively made to submit sample lists that have already been made using this tool.",
)
warning_label.pack()

label = tk.Label(self.csv_batch_window, text="Search for your CSV:", pady=10)
label.pack()

import_button = tk.Button(self.csv_batch_window, text="Import your CSV", width=17, command=self.import_csv, pady=10)
import_button = tk.Button(
self.csv_batch_window, text="Import your CSV", width=17, command=self.import_csv, pady=10
)
import_button.pack()

button_submit = tk.Button(self.csv_batch_window, text="Submit", width=17, command=self.show_values, pady=10)
button_submit = tk.Button(self.csv_batch_window, text="Submit", width=17, command=self.submit_result, pady=10)
button_submit.pack()

button_back = tk.Button(self.csv_batch_window, text="Go back to home", width=17, command=self.on_exit, pady=10)
button_back.pack()

def on_exit(self):
def on_exit(self) -> None:
"""
Defines behaviour when user quits this window (by x button or specified button).
Args:
None
Returns:
None
"""
self.csv_batch_window.destroy()
self.root.deiconify()

def import_csv(self):
def import_csv(self) -> None:
"""
Asks the path to input CSV.
Args:
None
Returns:
None
"""
os.environ["FILE_PATH"] = filedialog.askopenfilename(filetypes=[("CSV Files", "*.csv")])

def show_values(self):
def submit_result(self) -> None:
"""
performs modifications on the CSV, submit them to directus and writes the output csv.
Args:
None
Returns:
None
"""
print("correctly written")
10 changes: 6 additions & 4 deletions ms_sample_list_creator/home_page.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import os
import tkinter as tk
from tkinter import filedialog
from typing import Any

import requests


class HomeWindow(tk.Frame):
def __init__(self, parent, *args, **kwargs):
def __init__(self, parent: tk.Tk, *args: Any, **kwargs: Any):
"""
Initializes an instance of the class.
Expand Down Expand Up @@ -250,12 +251,12 @@ def output_folder(self) -> None:
folder = parts[-1]
self.output_path_button.config(text=folder)

def show_values(self, clicked_button) -> None:
def show_values(self, clicked_button: str) -> None:
"""
Stores all the parameters to the environment when user confirms his choice.
Args:
None
clicked_button(str): A string ("new" or "csv"), that defines which window will be launched after home page.
Returns:
None
Expand Down Expand Up @@ -370,7 +371,7 @@ def testConnection(self) -> None:
# If user didn't enter all necessary values, shows this message
self.label.config(text="Please provide all asked values", foreground="red")

def manage_choice(self) -> None:
def manage_choice(self) -> str:
"""
Returns to main script which option did the user choose.
Expand All @@ -389,3 +390,4 @@ def manage_choice(self) -> None:
else:
# If user didn't enter all necessary values, shows this message
self.label.config(text="Unknow error, please try again with other parameters", foreground="red")
return "error"
Empty file removed ms_sample_list_creator/log.txt
Empty file.
51 changes: 41 additions & 10 deletions ms_sample_list_creator/ms_sample_list_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,53 @@
# other non-built-in packages (here requests) inside wine. Then run: wine pyinstaller --onefile main.py

import tkinter as tk
from home_page import HomeWindow
from new_batch import newBatch
from csv_batch import csvBatch

def submit_results(clicked_button:str):
from csv_batch import csvBatch # type: ignore[import-not-found]
from home_page import HomeWindow # type: ignore[import-not-found]
from new_batch import newBatch # type: ignore[import-not-found]


def submit_results(clicked_button: str) -> None:
"""
Permits to detect the button the user clicked.
Args:
clicked_button (str): string parameter to define which button is clicked.
Returns:
None
"""
home_page.show_values(clicked_button)
handle_user_choice()


# Function to handle the user choice
def handle_user_choice():
def handle_user_choice() -> None:
"""
Collect user choice and transmits it to de function that shows the correct window.
Args:
None
Returns:
None
"""
# Call the manage_choice method to get the user choice
user_choice = home_page.manage_choice()
# Show the corresponding window based on the user's choice
show_selected_window(user_choice)

def show_selected_window(choice):

def show_selected_window(choice: str) -> None:
"""
Accepts user choice and launches the correct window.
Args:
choice (str): Retrieves the user choice.
Returns:
None
"""
if choice == "new":
# Create a new Toplevel window for the new batch
new_batch_window = tk.Toplevel(root)
Expand All @@ -38,6 +69,7 @@ def show_selected_window(choice):
# Handle the case of an unknown choice
print("Unknown error, please try again with other parameters.")


# Create an instance of the main window
root = tk.Tk()
root.title("Home")
Expand All @@ -52,14 +84,13 @@ def show_selected_window(choice):
frame_submit = tk.Frame(root)
frame_submit.pack(pady=(50, 0))

button_new_batch = tk.Button(
frame_submit, text="New sample list", width=20, command=lambda: submit_results("new"))
button_new_batch = tk.Button(frame_submit, text="New sample list", width=20, command=lambda: submit_results("new"))
button_new_batch.pack(side="left")

button_submit_csv = tk.Button(
frame_submit, text="Sample list from CSV", width=20, command=lambda: submit_results("csv"))
frame_submit, text="Sample list from CSV", width=20, command=lambda: submit_results("csv")
)
button_submit_csv.pack(side="right")

# Start the tkinter event loop
root.mainloop()

23 changes: 17 additions & 6 deletions ms_sample_list_creator/new_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@


class newBatch:
def __init__(self, new_batch_window, root):
def __init__(self, new_batch_window: tk.Toplevel, root: tk.Tk):
"""
Initializes an instance of the class.
Args:
root(tk.Tk): The parent widget or window where this frame will be placed.
csv_path(str): CSV path and name.
new_batch_window(tk.Toplevel): The parent widget where this frame will be placed.
root(tk.Tk): The root window to perform actions on it.
Returns:
None
Expand Down Expand Up @@ -85,7 +85,9 @@ def __init__(self, new_batch_window, root):
self.label.grid(row=2, column=0, columnspan=2, pady=10)

# Submit button
submit_button = ttk.Button(self.new_batch_window, text="Generate sample list", width=20, command=self.submit_table)
submit_button = ttk.Button(
self.new_batch_window, text="Generate sample list", width=20, command=self.submit_table
)

# Back button
button_back = tk.Button(self.new_batch_window, text="Back to Home", width=20, command=self.on_exit)
Expand All @@ -100,7 +102,16 @@ def __init__(self, new_batch_window, root):
self.new_batch_window.mainloop()
self.root.withdraw()

def on_exit(self):
def on_exit(self) -> None:
"""
Defines behaviour when user quits this window (by x button or specified button).
Args:
None
Returns:
None
"""
self.new_batch_window.destroy()
self.root.deiconify()

Expand Down Expand Up @@ -380,4 +391,4 @@ def store_prefix(self) -> None:
os.environ["PREFIX"] = self.prefix.get()

# Close the AskBoxPrefixWindow
self.master.destroy()
self.master.destroy()
25 changes: 0 additions & 25 deletions ms_sample_list_creator/pieces.py

This file was deleted.

47 changes: 0 additions & 47 deletions ms_sample_list_creator/prefix_window.py

This file was deleted.

0 comments on commit 7935a8f

Please sign in to comment.