4
4
import ttkbootstrap as ttk
5
5
from ttkbootstrap .constants import *
6
6
from tkinter import filedialog , messagebox
7
+ import csv
7
8
import shutil
8
9
9
10
# Helper function to get the correct path to resources
@@ -60,26 +61,31 @@ def __init__(self, root):
60
61
61
62
def select_file (self ):
62
63
self .file_path = filedialog .askopenfilename (filetypes = [("Excel Files" , "*.xlsx" )])
63
- if self .file_path :
64
- messagebox .showinfo ("File Selected" , f"Selected File: { os .path .basename (self .file_path )} " )
65
-
64
+
66
65
def generate_manifest (self ):
67
66
project_name = self .project_name_entry .get ()
68
67
project_date = self .project_date_entry .get ()
69
68
n_plates = self .n_plates_entry .get ()
70
-
69
+
71
70
# Validate inputs
72
71
if not project_name or not project_date or not n_plates or not self .file_path :
73
72
messagebox .showerror ("Error" , "All fields and the Excel file must be provided!" )
74
73
return
75
-
74
+
76
75
try :
77
76
n_plates = int (n_plates )
78
77
project_date = pd .to_datetime (project_date ).strftime ('%Y-%m-%d' )
79
78
except ValueError :
80
79
messagebox .showerror ("Error" , "Invalid date or number of plates format." )
81
80
return
82
-
81
+
82
+ # Ask for output destination
83
+ output_file = filedialog .asksaveasfilename (defaultextension = ".csv" , filetypes = [("CSV files" , "*.csv" )],
84
+ initialfile = f"{ project_name } _SampleSheet_{ project_date } .csv" )
85
+ if not output_file :
86
+ messagebox .showerror ("Error" , "Output destination must be specified!" )
87
+ return
88
+
83
89
# Process the header file
84
90
try :
85
91
header_lines = self .process_header_file (project_name , project_date )
@@ -90,9 +96,8 @@ def generate_manifest(self):
90
96
# Run the manifest generation logic
91
97
try :
92
98
data_section = self .generate_manifest_logic (project_name , n_plates )
93
- file_name = f"{ project_name } _SampleSheet_{ project_date } .csv"
94
- self .write_manifest (header_lines , data_section , file_name )
95
- messagebox .showinfo ("Success" , f"Manifest generated successfully: { file_name } " )
99
+ self .write_manifest (header_lines , data_section , output_file )
100
+ messagebox .showinfo ("Success" , f"Manifest generated successfully: { output_file } " )
96
101
except Exception as e :
97
102
messagebox .showerror ("Error" , f"An error occurred: { str (e )} " )
98
103
0 commit comments