-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUI_test1.py
More file actions
143 lines (110 loc) · 4.37 KB
/
Copy pathGUI_test1.py
File metadata and controls
143 lines (110 loc) · 4.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import tkinter as tk
from tkinter import filedialog, messagebox, scrolledtext
import subprocess
import pathlib
import threading
# === DEFAULT CONFIG ===
DEFAULT_OPTIONS = {
"-u": "200",
"-w": "",
"-U": False,
"-V": True,
"-S": True,
"-p": True,
"-a": "",
"-d": False,
"-r": "100,300",
"-F": "",
"-m": "",
"-f": "arduino",
"-T": "tms5220",
}
PYTHON_WIZARD = pathlib.Path(__file__).parent / "python_wizard.py"
class BatchWizardGUI:
def __init__(self, root):
self.root = root
self.root.title("Batch Wizard GUI")
# === Paths ===
self.input_folder = tk.StringVar(value=".")
self.output_file = tk.StringVar(value="all_outputs.txt")
# === UI ===
self.build_ui()
def build_ui(self):
frame = tk.Frame(self.root)
frame.pack(padx=10, pady=10, fill="both", expand=True)
# Folder selection
tk.Label(frame, text="Input Folder:").grid(row=0, column=0, sticky="w")
tk.Entry(frame, textvariable=self.input_folder, width=40).grid(row=0, column=1)
tk.Button(frame, text="Browse", command=self.browse_folder).grid(row=0, column=2)
# Output file
tk.Label(frame, text="Output File:").grid(row=1, column=0, sticky="w")
tk.Entry(frame, textvariable=self.output_file, width=40).grid(row=1, column=1)
tk.Button(frame, text="Save As", command=self.save_file).grid(row=1, column=2)
# Options
self.option_vars = {}
row = 2
tk.Label(frame, text="Options:").grid(row=row, column=0, sticky="w")
row += 1
for opt, val in DEFAULT_OPTIONS.items():
if isinstance(val, bool):
var = tk.BooleanVar(value=val)
tk.Checkbutton(frame, text=opt, variable=var).grid(row=row, column=0, sticky="w")
else:
var = tk.StringVar(value=val)
tk.Label(frame, text=opt).grid(row=row, column=0, sticky="w")
tk.Entry(frame, textvariable=var, width=20).grid(row=row, column=1, sticky="w")
self.option_vars[opt] = var
row += 1
# Run button
tk.Button(frame, text="Run", command=self.run_thread).grid(row=row, column=0, pady=10)
# Output log
self.log = scrolledtext.ScrolledText(frame, height=15)
self.log.grid(row=row + 1, column=0, columnspan=3, sticky="nsew")
def browse_folder(self):
folder = filedialog.askdirectory()
if folder:
self.input_folder.set(folder)
def save_file(self):
file = filedialog.asksaveasfilename(defaultextension=".txt")
if file:
self.output_file.set(file)
def log_write(self, text):
self.log.insert(tk.END, text + "\n")
self.log.see(tk.END)
def build_command(self, wav_file):
cmd = ["python", str(PYTHON_WIZARD)]
for opt, var in self.option_vars.items():
val = var.get()
if isinstance(var, tk.BooleanVar):
if val:
cmd.append(opt)
else:
if val.strip() != "":
cmd.extend([opt, val])
cmd.append(str(wav_file))
return cmd
def run_thread(self):
threading.Thread(target=self.run_batch).start()
def run_batch(self):
input_path = pathlib.Path(self.input_folder.get())
output_file = self.output_file.get()
wav_files = sorted(input_path.glob("*.wav"))
if not wav_files:
messagebox.showerror("Error", "No WAV files found.")
return
with open(output_file, "w", encoding="utf-8") as out:
for wav in wav_files:
self.log_write(f"Processing {wav.name}...")
cmd = self.build_command(wav)
try:
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
out.write(f"//--- {wav.name} ---//\n")
out.write(result.stdout)
out.write("\n\n")
except subprocess.CalledProcessError as e:
self.log_write(f"Error: {e.stderr}")
self.log_write("Done!")
if __name__ == "__main__":
root = tk.Tk()
app = BatchWizardGUI(root)
root.mainloop()