12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- import tkinter as tk
- import tk_tools
- import numpy as np
- from datetime import datetime
- from .Plot import Plot
- from .globals import *
- class Page_1(tk.Frame):
- plotLen = 100
- def __init__(self, parent, controller):
- tk.Frame.__init__(self, parent)
- self.t = 0
- self.controller = controller
- # graph
- self.serialPlot = Plot(xaxis=(0, self.plotLen * .3), yaxis=(0, 5),
- ytitle="Windgeschwindigkeit m/s",
- xtitle="vergangene Zeit in s",
- title="Geschwindigkeitsverlauf",
- line_colors=["#2222ff", "#22ff22", "#ff2222"])
- canvas = self.serialPlot.create_canvas(self)
- canvas.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
- # right menu
- left = tk.Frame(self, borderwidth=2, relief="solid")
- container = tk.Frame(left, borderwidth=2, relief="solid")
- label1 = tk.Label(container, text="I could be a canvas, but I'm a label right now")
- self.label4 = tk.Label(self,font=("Arial","30"),fg="red")
- self.label4.pack()
- self.label4.config(text=str(self.t))
- SendButton = tk.Button(left, text='Quit', command=quit)
- label2 = tk.Label(left, text="I could be a button")
- label3 = tk.Label(left, text="So could I")
- left.pack(side="left", expand=True, fill="both")
- container.pack(expand=True, fill="both", padx=7, pady=5)
- SendButton.pack()
- label1.pack()
- label2.pack()
- label3.pack()
- controller.pid.SetPoint = 0.4 # m/s
- def update(self, visible):
- if visible:
- timestamps = (np.datetime64(datetime.now()) - self.controller.getLastValues(self.plotLen, "datetime")) / np.timedelta64(1,'s')
- self.serialPlot.plot_data(
- xs=[timestamps, timestamps],
- ys=[self.controller.getLastValues(self.plotLen, "adc_0"), np.linspace(0, 5, self.plotLen)]
- )
- self.label4.config(text="{:5.3f} V".format(self.controller.getLastValue("adc_0")))
|