Page_3.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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_3(tk.Frame):
  8. plotLen = 100
  9. def __init__(self, parent, controller):
  10. tk.Frame.__init__(self, parent)
  11. self.controller = controller
  12. # graph
  13. self.pressurePlot = Plot(xaxis=(0, self.plotLen * .3), yaxis=(-120, 120),
  14. ytitle="Druck in Pa",
  15. xtitle="vergangene Zeit in s",
  16. title="Druckverlauf",
  17. line_colors=GRAPH_COLORS)
  18. canvas = self.pressurePlot.create_canvas(self)
  19. canvas.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
  20. # legend
  21. container = tk.Frame(self, relief="solid")
  22. container.pack(side="bottom", fill="both", padx=20, pady=20)
  23. for i in range(8):
  24. tk.Label(container, text="Sensor {}".format(i)).grid(row=i, column=1)
  25. tk.Frame(container, height = 3,width = 50,bg = GRAPH_COLORS[i]).grid(row=i, column=0)
  26. # right menu
  27. rightFrame = tk.LabelFrame(self, text="Druck")
  28. rightFrame.pack(side="left", fill="both", padx=5, pady=5)
  29. gridFrame = tk.Frame(rightFrame, relief="solid")
  30. gridFrame.pack(side="top", fill="both", padx=20, pady=20)
  31. self.readOuts = {}
  32. for sensor in range(8):
  33. name = "pressure_{}".format(sensor)
  34. label = tk.Label(gridFrame, text=name)
  35. label.grid(row=sensor, column=0)
  36. self.readOuts[name] = tk.StringVar()
  37. entry = tk.Entry(gridFrame, textvariable=self.readOuts[name], width=10)
  38. entry.grid(row=sensor, column=1)
  39. def update(self, visible):
  40. if visible:
  41. self.pressurePlot.setTimeScale(self.plotLen, self.controller.intervalDelay)
  42. timestamps = (np.datetime64(datetime.now()) - self.controller.getLastValues(self.plotLen, "datetime")) / np.timedelta64(1,'s')
  43. self.pressurePlot.plot_data(
  44. xs=[timestamps] * 8,
  45. ys=[self.controller.getLastValues(self.plotLen, "pressure_{}".format(i)) for i in range(8)]
  46. )
  47. for name in self.readOuts:
  48. val = self.controller.getLastValue(name)
  49. if np.isnan(val):
  50. self.readOuts[name].set("")
  51. else:
  52. self.readOuts[name].set("{:1.3f} Pa".format(val))