|
import tkinter as tk
|
|
import tkinter.filedialog as filedialog
|
|
from tkinter import ttk
|
|
import os
|
|
import subprocess
|
|
import json
|
|
|
|
keyword_entries = []
|
|
|
|
def browse_folder():
|
|
folder_path = filedialog.askdirectory(
|
|
initialdir="/",
|
|
title="Select a Folder"
|
|
)
|
|
file_path_var.set(folder_path)
|
|
|
|
|
|
for filename in os.listdir(folder_path):
|
|
if os.path.splitext(filename)[1].lower() in ('.pdf', '.docx'):
|
|
print(filename)
|
|
|
|
def generate_textboxes():
|
|
global keyword_entries
|
|
|
|
category_data = []
|
|
|
|
|
|
for category_frame in category_frames:
|
|
category_name = category_var[category_frame].get()
|
|
num_keywords = int(keyword_vars[category_frame].get())
|
|
category_data.append((category_name, num_keywords))
|
|
|
|
|
|
clear_existing_textboxes()
|
|
|
|
|
|
keyword_entries.clear()
|
|
for i, (category_name, num_keywords) in enumerate(category_data):
|
|
label = tk.Label(root, text=f"{category_name}:")
|
|
label.pack()
|
|
for _ in range(num_keywords):
|
|
entry = tk.Entry(root)
|
|
entry.pack()
|
|
keyword_entries.append(entry)
|
|
|
|
|
|
save_button = tk.Button(root, text="Categorize", command=save_to_backup)
|
|
save_button.pack()
|
|
|
|
|
|
def save_to_backup():
|
|
global keyword_entries
|
|
|
|
category_data = {}
|
|
|
|
|
|
keyword_start_index = 0
|
|
for i, category_frame in enumerate(category_frames):
|
|
category_name = category_var[category_frame].get()
|
|
num_keywords = int(keyword_vars[category_frame].get())
|
|
|
|
keywords = keyword_entries[keyword_start_index:keyword_start_index + num_keywords]
|
|
category_data[category_name] = [entry.get() for entry in keywords]
|
|
|
|
keyword_start_index += num_keywords
|
|
|
|
|
|
subprocess.run(["python3", "augmentA.py", json.dumps(category_data)])
|
|
|
|
|
|
def clear_existing_textboxes():
|
|
for widget in root.winfo_children():
|
|
if isinstance(widget, tk.Label) or isinstance(widget, tk.Entry):
|
|
widget.destroy()
|
|
|
|
|
|
def update_category_dropdowns():
|
|
|
|
for frame in category_frames:
|
|
frame.destroy()
|
|
category_frames.clear()
|
|
|
|
|
|
num_categories = num_categories_var.get()
|
|
for i in range(num_categories):
|
|
frame = tk.Frame(root)
|
|
frame.pack()
|
|
category_frames.append(frame)
|
|
|
|
tk.Label(frame, text="Category Name:").pack()
|
|
category_var[frame] = tk.StringVar(frame)
|
|
tk.Entry(frame, textvariable=category_var[frame]).pack()
|
|
|
|
tk.Label(frame, text="Number of Keywords:").pack()
|
|
keyword_vars[frame] = tk.IntVar(frame)
|
|
keyword_options = [1, 2, 3, 4, 5]
|
|
ttk.Combobox(frame, textvariable=keyword_vars[frame],
|
|
values=keyword_options).pack()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
root = tk.Tk()
|
|
root.title("BuzzMatchTester")
|
|
|
|
|
|
file_frame = tk.Frame(root)
|
|
file_frame.pack()
|
|
|
|
file_path_label = tk.Label(file_frame, text="File Path:")
|
|
file_path_label.pack(side='left')
|
|
|
|
file_path_var = tk.StringVar(root)
|
|
file_path_entry = tk.Entry(file_frame, textvariable=file_path_var)
|
|
file_path_entry.pack(side='left')
|
|
|
|
browse_button = tk.Button(file_frame, text="Browse Folder", command=browse_folder)
|
|
browse_button.pack(side='left')
|
|
|
|
|
|
num_categories_label = tk.Label(root, text="Number of Categories:")
|
|
num_categories_label.pack()
|
|
|
|
num_categories_options = [0,1, 2, 3, 4, 5]
|
|
num_categories_var = tk.IntVar(root)
|
|
num_categories_var.set(num_categories_options[0])
|
|
num_categories_dropdown = ttk.Combobox(root, textvariable=num_categories_var,
|
|
values=num_categories_options)
|
|
num_categories_dropdown.pack()
|
|
|
|
category_frames = []
|
|
category_var = {}
|
|
keyword_vars = {}
|
|
|
|
update_category_dropdowns()
|
|
|
|
|
|
|
|
generate_button = tk.Button(root, text="Generate Textboxes", command=generate_textboxes)
|
|
generate_button.pack()
|
|
|
|
num_categories_dropdown.bind("<<ComboboxSelected>>", lambda _: update_category_dropdowns())
|
|
|
|
root.mainloop()
|
|
|