Page_1.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import tkinter as tk
  2. import tk_tools
  3. import numpy as np
  4. from datetime import datetime
  5. from .Plot import Plot
  6. from .globals import *
  7. class Page_1(tk.Frame):
  8. plotLen = 100
  9. def __init__(self, parent, controller):
  10. tk.Frame.__init__(self, parent)
  11. self.t = 0
  12. self.controller = controller
  13. # graph
  14. self.serialPlot = Plot(xaxis=(0, self.plotLen * .3), yaxis=(0, 5),
  15. ytitle="Windgeschwindigkeit m/s",
  16. xtitle="vergangene Zeit in s",
  17. title="Geschwindigkeitsverlauf",
  18. line_colors=["#2222ff", "#22ff22", "#ff2222"])
  19. canvas = self.serialPlot.create_canvas(self)
  20. canvas.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
  21. # right menu
  22. left = tk.Frame(self, borderwidth=2, relief="solid")
  23. container = tk.Frame(left, borderwidth=2, relief="solid")
  24. label1 = tk.Label(container, text="I could be a canvas, but I'm a label right now")
  25. self.label4 = tk.Label(self,font=("Arial","30"),fg="red")
  26. self.label4.pack()
  27. self.label4.config(text=str(self.t))
  28. SendButton = tk.Button(left, text='Quit', command=quit)
  29. label2 = tk.Label(left, text="I could be a button")
  30. label3 = tk.Label(left, text="So could I")
  31. left.pack(side="left", expand=True, fill="both")
  32. container.pack(expand=True, fill="both", padx=7, pady=5)
  33. SendButton.pack()
  34. label1.pack()
  35. label2.pack()
  36. label3.pack()
  37. controller.pid.SetPoint = 0.4 # m/s
  38. def update(self, visible):
  39. if visible:
  40. timestamps = (np.datetime64(datetime.now()) - self.controller.getLastValues(self.plotLen, "datetime")) / np.timedelta64(1,'s')
  41. self.serialPlot.plot_data(
  42. xs=[timestamps, timestamps],
  43. ys=[self.controller.getLastValues(self.plotLen, "adc_0"), np.linspace(0, 5, self.plotLen)]
  44. )
  45. self.label4.config(text="{:5.3f} V".format(self.controller.getLastValue("adc_0")))