checkboxes for output and showing output files
This commit is contained in:
93
main.py
93
main.py
@@ -6,6 +6,7 @@ import subprocess
|
||||
import os
|
||||
from datetime import datetime
|
||||
import shutil
|
||||
import platform
|
||||
try:
|
||||
from openpyxl import load_workbook
|
||||
XLSX_AVAILABLE = True
|
||||
@@ -114,6 +115,27 @@ def write_xlsx(pairs, output_filename, template_path='template.xlsx'):
|
||||
# Save to new filename (never overwrite template)
|
||||
wb.save(output_filename)
|
||||
|
||||
def show_files_in_explorer(files):
|
||||
"""Open file explorer and highlight the generated files"""
|
||||
if not files:
|
||||
return
|
||||
|
||||
# Get the directory of the first file
|
||||
directory = os.path.dirname(os.path.abspath(files[0]))
|
||||
|
||||
system = platform.system()
|
||||
|
||||
if system == 'Windows':
|
||||
# On Windows, use explorer with /select to highlight the file
|
||||
# If multiple files, just select the first one
|
||||
subprocess.run(['explorer', '/select,', os.path.abspath(files[0])])
|
||||
elif system == 'Darwin': # macOS
|
||||
# On Mac, use 'open' with -R to reveal in Finder
|
||||
subprocess.run(['open', '-R', os.path.abspath(files[0])])
|
||||
else: # Linux and others
|
||||
# On Linux, just open the directory
|
||||
subprocess.run(['xdg-open', directory])
|
||||
|
||||
def run_update_script():
|
||||
try:
|
||||
# Run update.sh script
|
||||
@@ -139,38 +161,74 @@ def process_files():
|
||||
messagebox.showerror("Error", "Please select an input file.")
|
||||
return
|
||||
|
||||
generate_csv = csv_var.get()
|
||||
generate_xlsx = xlsx_var.get()
|
||||
|
||||
if not generate_csv and not generate_xlsx:
|
||||
messagebox.showerror("Error", "Please select at least one output format (CSV or XLSX).")
|
||||
return
|
||||
|
||||
# Auto-generate output filenames
|
||||
base = os.path.splitext(input_file)[0]
|
||||
output_file1 = f"{base}.sequential.csv"
|
||||
output_file2 = f"{base}.joined.csv"
|
||||
output_xlsx = f"{base}.xlsx"
|
||||
|
||||
generated_files = []
|
||||
error_messages = []
|
||||
|
||||
try:
|
||||
with open(input_file, 'r') as f:
|
||||
log_text = f.read()
|
||||
pairs = parse_logs(log_text)
|
||||
write_csv1(pairs, output_file1)
|
||||
write_csv2(pairs, output_file2)
|
||||
|
||||
# Try to write XLSX file
|
||||
xlsx_msg = ""
|
||||
try:
|
||||
write_xlsx(pairs, output_xlsx)
|
||||
xlsx_msg = f"\n{output_xlsx}"
|
||||
except ImportError as e:
|
||||
xlsx_msg = f"\n\nXLSX export skipped: {str(e)}"
|
||||
except Exception as e:
|
||||
xlsx_msg = f"\n\nXLSX export failed: {str(e)}"
|
||||
# Generate CSV files if checked
|
||||
if generate_csv:
|
||||
try:
|
||||
write_csv1(pairs, output_file1)
|
||||
generated_files.append(output_file1)
|
||||
write_csv2(pairs, output_file2)
|
||||
generated_files.append(output_file2)
|
||||
except Exception as e:
|
||||
error_messages.append(f"CSV export failed: {str(e)}")
|
||||
|
||||
messagebox.showinfo("Success", f"Files generated:\n{output_file1}\n{output_file2}{xlsx_msg}")
|
||||
# Generate XLSX file if checked
|
||||
if generate_xlsx:
|
||||
try:
|
||||
write_xlsx(pairs, output_xlsx)
|
||||
generated_files.append(output_xlsx)
|
||||
except ImportError as e:
|
||||
error_messages.append(f"XLSX export skipped: {str(e)}")
|
||||
except Exception as e:
|
||||
error_messages.append(f"XLSX export failed: {str(e)}")
|
||||
|
||||
# Build success message
|
||||
if generated_files:
|
||||
files_list = "\n".join(generated_files)
|
||||
error_info = ""
|
||||
if error_messages:
|
||||
error_info = "\n\nWarnings:\n" + "\n".join(error_messages)
|
||||
|
||||
# Custom dialog with "Show the files" button
|
||||
response = messagebox.askquestion("Success",
|
||||
f"Files generated:\n{files_list}{error_info}\n\nShow the files?",
|
||||
icon='info')
|
||||
|
||||
if response == 'yes':
|
||||
show_files_in_explorer(generated_files)
|
||||
else:
|
||||
messagebox.showerror("Error", "No files were generated.\n\n" + "\n".join(error_messages))
|
||||
|
||||
except Exception as e:
|
||||
messagebox.showerror("Error", f"An error occurred: {str(e)}")
|
||||
|
||||
root = tk.Tk()
|
||||
root.title("Log to CSV Converter")
|
||||
root.geometry("500x160")
|
||||
root.geometry("500x200")
|
||||
|
||||
input_file_var = tk.StringVar()
|
||||
csv_var = tk.BooleanVar(value=False) # CSV unchecked by default
|
||||
xlsx_var = tk.BooleanVar(value=True) # XLSX checked by default
|
||||
|
||||
# Input file selection
|
||||
input_frame = tk.Frame(root)
|
||||
@@ -179,8 +237,15 @@ tk.Label(input_frame, text="Select Input Log File:").pack(side='left')
|
||||
tk.Entry(input_frame, textvariable=input_file_var, width=40).pack(side='left', padx=5)
|
||||
tk.Button(input_frame, text="Browse Input", bg="#2196F3", command=select_input_file).pack(side='left')
|
||||
|
||||
# Output format checkboxes
|
||||
format_frame = tk.Frame(root)
|
||||
format_frame.pack(pady=5, padx=10, fill='x')
|
||||
tk.Label(format_frame, text="Output Formats:").pack(side='left')
|
||||
tk.Checkbutton(format_frame, text="CSV", variable=csv_var).pack(side='left', padx=10)
|
||||
tk.Checkbutton(format_frame, text="XLSX", variable=xlsx_var).pack(side='left', padx=10)
|
||||
|
||||
# Convert button
|
||||
tk.Button(root, text="CONVERT TO CSV", command=process_files, font=("Arial", 14), relief="raised", bg="#4CAF50", fg="white").pack(pady=10, padx=10, fill='x')
|
||||
tk.Button(root, text="CONVERT", command=process_files, font=("Arial", 14), relief="raised", bg="#4CAF50", fg="white").pack(pady=10, padx=10, fill='x')
|
||||
|
||||
# Update script button
|
||||
tk.Button(root, text="Update this Application", command=run_update_script, font=("Arial", 12), relief="raised").pack(pady=5, padx=10, fill='x')
|
||||
|
||||
Reference in New Issue
Block a user