-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTask_7.py
50 lines (39 loc) · 1.87 KB
/
Task_7.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
import tkinter as tk
from tkinter import ttk, messagebox, filedialog
from SignalToolkit import convolve
from SignalProcessor import SignalProcessor
class Task_7:
def __init__(self, main_window, title):
self.main_window = main_window
self.app = None # Initialize app as None
self.signal_processor = SignalProcessor()
self.file_path = ["", ""]
self.title = title
def open_window(self):
if self.app is not None:
return
self.app = tk.Toplevel(self.main_window)
self.app.title(self.title)
self.app.geometry("300x300+200+200")
frame = tk.Frame(self.app, width=50)
# Create a Load File button for the first signal
loadfile1 = tk.Button(frame, text="Load First Signal", width=30, command=lambda: self.load_file(0))
loadfile1.pack(padx=1, pady=5)
# Create a Load File button for the first signal
loadfile2 = tk.Button(frame, text="Load Second Signal", width=30, command=lambda: self.load_file(1))
loadfile2.pack(padx=1, pady=5)
# Create a button to execute the convolve function
convolveButton = tk.Button(frame, text="Convolve", width=30, command=self.convolve_function)
convolveButton.pack(padx=1, pady=5)
frame.pack()
def load_file(self, file_index):
root = tk.Tk()
root.withdraw() # to hide the main window
self.file_path[file_index] = filedialog.askopenfilename(parent=root, title="Choose file")
def convolve_function(self):
signal1 = self.signal_processor.read_signal_from_file(self.file_path[0])
signal2 = self.signal_processor.read_signal_from_file(self.file_path[1])
indices, samples = convolve(signal1, signal2)
result = [[a, b] for a, b in zip(indices, samples)]
self.signal_processor.set_signal(result)
self.signal_processor.display_signal()