|
#sudo apt update |
|
#sudo apt install python3-tk |
|
|
|
import os |
|
import json |
|
import tempfile |
|
import tkinter as tk |
|
from tkinter import filedialog, messagebox, scrolledtext |
|
|
|
# Paths |
|
SAVE_FILE = os.path.join(tempfile.gettempdir(), "selected_files.json") |
|
OUTPUT_FILE = "output.txt" |
|
|
|
def load_file_list(): |
|
if os.path.exists(SAVE_FILE): |
|
with open(SAVE_FILE, "r", encoding="utf-8") as f: |
|
return json.load(f) |
|
return [] |
|
|
|
def save_file_list(file_list): |
|
with open(SAVE_FILE, "w", encoding="utf-8") as f: |
|
json.dump(file_list, f, indent=2) |
|
|
|
def select_files(): |
|
files = filedialog.askopenfilenames(title="Select files") |
|
if files: |
|
file_list.clear() |
|
file_list.extend(files) |
|
update_display() |
|
save_file_list(file_list) |
|
|
|
def update_display(): |
|
display_text.delete(1.0, tk.END) |
|
for f in file_list: |
|
display_text.insert(tk.END, f + "\n") |
|
|
|
def export_to_text(): |
|
if not file_list: |
|
messagebox.showwarning("No files", "Please select files first.") |
|
return |
|
|
|
with open(OUTPUT_FILE, "w", encoding="utf-8") as out: |
|
for file_path in file_list: |
|
filename = os.path.basename(file_path) |
|
try: |
|
with open(file_path, "r", encoding="utf-8") as f: |
|
content = f.read() |
|
except Exception as e: |
|
content = f"β οΈ Error reading file: {e}" |
|
|
|
out.write(f"File {filename}:\n") |
|
out.write("```\n") |
|
out.write(content) |
|
out.write("\n```\n\n") |
|
|
|
messagebox.showinfo("Done", f"Content saved to {OUTPUT_FILE}") |
|
|
|
def clear_file_list(): |
|
file_list.clear() |
|
update_display() |
|
save_file_list(file_list) |
|
|
|
# GUI |
|
root = tk.Tk() |
|
root.title("CodeConcat β Prepare Your Code for GPT") |
|
|
|
file_list = load_file_list() |
|
|
|
tk.Button(root, text="Select Files", command=select_files).pack(pady=5) |
|
tk.Button(root, text="Export to output.txt", command=export_to_text).pack(pady=5) |
|
tk.Button(root, text="Clear List", command=clear_file_list).pack(pady=5) |
|
|
|
display_text = scrolledtext.ScrolledText(root, width=80, height=20) |
|
display_text.pack(padx=10, pady=10) |
|
update_display() |
|
|
|
root.mainloop() |