init
This commit is contained in:
91
filter_dev/app.py
Normal file
91
filter_dev/app.py
Normal file
@@ -0,0 +1,91 @@
|
||||
import tkinter as tk
|
||||
from tkinter import ttk
|
||||
import matplotlib.pyplot as plt
|
||||
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
|
||||
|
||||
from .filter import *
|
||||
from .gui.device import Device
|
||||
|
||||
class FilterDevApp:
|
||||
def __init__(self, root):
|
||||
self.filter = None
|
||||
|
||||
self.root = root
|
||||
self.root.title("JannTers Filter Evaluation Tool")
|
||||
|
||||
# Create a frame for the plot and sliders
|
||||
self.frame = tk.Frame(self.root)
|
||||
self.frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
|
||||
|
||||
# Create a figure for plotting
|
||||
self.fig, self.ax = plt.subplots()
|
||||
self.canvas = FigureCanvasTkAgg(self.fig, master=self.frame)
|
||||
self.canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=True)
|
||||
|
||||
# Create a frame for sliders
|
||||
self.toolbar = tk.Frame(self.root)
|
||||
self.toolbar.pack(side=tk.RIGHT, fill=tk.Y)
|
||||
|
||||
# Device Settings
|
||||
self.device_label = ttk.Label(self.toolbar, text="Device Name:")
|
||||
self.device_label.pack(pady=10)
|
||||
self.device_name = ttk.Entry(self.toolbar)
|
||||
self.device_name.insert(0, "Smaage") # Set default value
|
||||
self.device_name.pack(pady=10)
|
||||
|
||||
self.device = Device(self.device_name)
|
||||
|
||||
self.connect_button = ttk.Button(self.toolbar, text="Connect Device", command=self.device.connect)
|
||||
self.connect_button.pack(pady=10)
|
||||
|
||||
# Filter Settings
|
||||
self.filter_type_label = ttk.Label(self.toolbar, text="Filter:")
|
||||
self.filter_type_label.pack(pady=10)
|
||||
self.filter_type_combobox = ttk.Combobox(self.toolbar, values=["MovAvg"])
|
||||
self.filter_type_combobox.set("MovAvg") # Set default value
|
||||
self.filter_type_combobox.pack(pady=10)
|
||||
self.change_filter = ttk.Button(self.toolbar, text="Change Filter", command=self.update_filter)
|
||||
self.change_filter.pack(pady=10)
|
||||
|
||||
# Objects
|
||||
self.filter = MovAvg(self.device, self.toolbar, self.update_plot)
|
||||
|
||||
# Initial plot
|
||||
self.update_plot()
|
||||
|
||||
def update_plot(self, *args):
|
||||
if self.filter is None:
|
||||
return
|
||||
|
||||
# Clear the current plot
|
||||
self.ax.clear()
|
||||
|
||||
# Get current values from sliders
|
||||
df = self.filter()
|
||||
|
||||
# Generate data
|
||||
x = df['timestamps']
|
||||
y1 = df['weights']
|
||||
y2 = df['filtered']
|
||||
|
||||
# Plot the data
|
||||
self.ax.plot(x, y1)
|
||||
self.ax.plot(x, y2)
|
||||
self.ax.set_xlabel("Time in ms")
|
||||
self.ax.set_ylabel("Weight")
|
||||
self.ax.grid()
|
||||
|
||||
# Draw the updated plot
|
||||
self.canvas.draw()
|
||||
|
||||
def update_filter(self):
|
||||
option = self.filter_type_combobox.get()
|
||||
if option == 'MovAvg' and not isinstance(self.filter, MovAvg):
|
||||
self.filter = MovAvg(self.device, self.toolbar, self.update_plot)
|
||||
|
||||
self.update_plot()
|
||||
|
||||
if __name__ == "__main__":
|
||||
root = tk.Tk()
|
||||
app = FilterDevApp(root)
|
||||
root.mainloop()
|
||||
Reference in New Issue
Block a user