add csv with tab

This commit is contained in:
VALLONGOL 2025-06-24 08:51:07 +02:00
parent b8eb3ce9ad
commit 133cbbeb0b
2 changed files with 28 additions and 8 deletions

View File

@ -144,9 +144,18 @@ class AppController:
if not profile: raise ValueError(f"CSV profile '{self.view.out_csv_profile_var.get()}' not found.")
self.active_export_profiles["csv"] = profile
path = (output_dir / basename).with_suffix(".csv")
# Determine the delimiter based on the GUI checkbox
use_tab_delimiter = self.view.out_csv_use_tab_var.get()
delimiter = "\t" if use_tab_delimiter else ","
log.info(f"Preparing CSV file with '{delimiter}' as delimiter.")
fh = open(path, "w", encoding="utf-8", newline="")
self.output_file_handles["csv"] = fh
self.csv_writers["csv"] = csv.writer(fh)
# Create the CSV writer with the chosen delimiter
csv_writer = csv.writer(fh, delimiter=delimiter)
self.csv_writers["csv"] = csv_writer
self.csv_writers["csv"].writerow([f.column_name for f in profile.fields])
if self.view.out_output_json_var.get():

View File

@ -67,6 +67,7 @@ class MainWindow(tk.Frame):
self.out_output_dir_var = tk.StringVar()
self.out_basename_var = tk.StringVar()
self.out_output_csv_var = tk.BooleanVar(value=True)
self.out_csv_use_tab_var = tk.BooleanVar(value=False) # New variable for tab separator
self.out_output_json_var = tk.BooleanVar(value=False)
self.out_csv_profile_var = tk.StringVar()
self.out_json_profile_var = tk.StringVar()
@ -148,15 +149,25 @@ class MainWindow(tk.Frame):
formats_frame = ttk.LabelFrame(parent, text="Output Formats & Profiles")
formats_frame.grid(row=2, column=0, columnspan=3, sticky="ew", padx=5, pady=5)
formats_frame.columnconfigure(1, weight=1)
formats_frame.columnconfigure(2, weight=1) # Add weight to third column
# CSV Options
csv_options_frame = ttk.Frame(formats_frame)
csv_options_frame.grid(row=0, column=0, columnspan=3, sticky="ew")
ttk.Checkbutton(formats_frame, text="Generate .csv file", variable=self.out_output_csv_var).grid(row=0, column=0, sticky="w", padx=5, pady=2)
self.out_csv_profile_combobox = ttk.Combobox(formats_frame, textvariable=self.out_csv_profile_var, state="readonly", width=20)
self.out_csv_profile_combobox.grid(row=0, column=1, sticky="w", padx=5)
ttk.Checkbutton(formats_frame, text="Generate .json file", variable=self.out_output_json_var).grid(row=1, column=0, sticky="w", padx=5, pady=2)
self.out_json_profile_combobox = ttk.Combobox(formats_frame, textvariable=self.out_json_profile_var, state="readonly", width=20)
self.out_json_profile_combobox.grid(row=1, column=1, sticky="w", padx=5)
ttk.Checkbutton(csv_options_frame, text="Generate .csv file", variable=self.out_output_csv_var).pack(side=tk.LEFT, padx=(5,10))
self.out_csv_profile_combobox = ttk.Combobox(csv_options_frame, textvariable=self.out_csv_profile_var, state="readonly", width=20)
self.out_csv_profile_combobox.pack(side=tk.LEFT, padx=5)
ttk.Checkbutton(csv_options_frame, text="Use Tab Separator", variable=self.out_csv_use_tab_var).pack(side=tk.LEFT, padx=(10,5))
# JSON Options
json_options_frame = ttk.Frame(formats_frame)
json_options_frame.grid(row=1, column=0, columnspan=3, sticky="ew")
ttk.Checkbutton(json_options_frame, text="Generate .json file", variable=self.out_output_json_var).pack(side=tk.LEFT, padx=(5,10))
self.out_json_profile_combobox = ttk.Combobox(json_options_frame, textvariable=self.out_json_profile_var, state="readonly", width=20)
self.out_json_profile_combobox.pack(side=tk.LEFT, padx=5)
action_frame = ttk.Frame(parent)
action_frame.grid(row=3, column=0, columnspan=3, pady=(10, 0))
self.out_process_button = ttk.Button(action_frame, text="Process .out File", command=self.controller.start_out_processing)