-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGUI.py
70 lines (57 loc) · 2.64 KB
/
GUI.py
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
import tkinter as tk
from tkinter import filedialog, messagebox
from Deconvolution import SignalProcess
class AudioProcessorGUI:
def __init__(self, master):
self.master = master
master.title("Deconvolution Tool")
master.geometry("600x400")
# Create an instance of the SignalProcess class
self.processor = SignalProcess()
# Initialize file paths
self.reference_path = None
self.recorded_path = None
btnRef = tk.Button(master, text="Load Reference File", width=10, height=2, command=self.loadRef)
btnRef.place(x= 100, y=100)
btnRec = tk.Button(master, text="Load Recorded File", width=10, height=2, command=self.loadRec)
btnRec.place(x= 380, y= 100)
self.btn_process = tk.Button(master, text="Start Deconvolution", width=20, height=4, command=self.signalFiles)
self.btn_process.place(x= 200, y= 250)
self.btn_process["state"] = "disabled"
def loadRef(self):
self.reference_path = filedialog.askopenfilename(title="Select Reference Wave File")
if self.reference_path:
print(f"Loaded reference file: {self.reference_path}")
self.check_files_loaded()
else:
print("File selection cancelled.")
def loadRec(self):
self.recorded_path = filedialog.askopenfilename(title="Select Recorded Wave File")
if self.recorded_path:
print(f"Loaded Recorded file: {self.recorded_path}")
self.check_files_loaded()
else:
print("File selection cancelled.")
def signalFiles(self):
if self.reference_path and self.recorded_path:
# File saveas dialog
output_path = filedialog.asksaveasfilename(defaultextension=".wav", title="Save Impulse Response as Wave File")
if output_path:
self.processor.signalProcess(self.reference_path, self.recorded_path, output_path) # Call processing method
self.processor.plotFig() # Call plotting method
messagebox.showinfo("Processing Complete", "Processing is complete. Check the output files.")
else:
messagebox.showerror("File Error", "File saving was cancelled.")
else:
messagebox.showerror("File Error", "Please ensure both files are loaded before processing.")
def check_files_loaded(self):
if self.reference_path and self.recorded_path:
self.btn_process["state"] = "normal"
else:
self.btn_process["state"] = "disabled"
def main():
root = tk.Tk()
app = AudioProcessorGUI(root)
root.mainloop()
if __name__ == "__main__":
main()