Page_2.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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_2(tk.Frame):
  8. plotLen = 100
  9. def __init__(self, parent, controller):
  10. tk.Frame.__init__(self, parent)
  11. self.controller = controller
  12. # graphs
  13. self.forcePlot = Plot(xaxis=(-2, 2), yaxis=(-2, 2),
  14. ytitle="y-Kraft in mV",
  15. xtitle="x-Kraft in mV",
  16. title="XY-Graph",
  17. line_colors=GRAPH_COLORS)
  18. canvas = self.forcePlot.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. tk.Label(container, text="Sensor 1").grid(row=0, column=1)
  24. tk.Frame(container, height = 3,width = 50,bg = GRAPH_COLORS[0]).grid(row=0, column=0)
  25. tk.Label(container, text="Sensor 2").grid(row=1, column=1)
  26. tk.Frame(container, height = 3,width = 50,bg = GRAPH_COLORS[1]).grid(row=1, column=0)
  27. tk.Label(container, text="Sensor 3").grid(row=2, column=1)
  28. tk.Frame(container, height = 3,width = 50,bg = GRAPH_COLORS[2]).grid(row=2, column=0)
  29. # right menu
  30. rightFrame = tk.LabelFrame(self, text="Kräfte")
  31. rightFrame.pack(side="left", fill="both", padx=5, pady=5)
  32. tareButton = tk.Button(rightFrame, text='Kräfte tarieren', command=self.controller.forceSensors.tare, justify=tk.LEFT, anchor="w")
  33. tareButton.pack(side="top", fill="both", padx=5, pady=5)
  34. gridFrame = tk.Frame(rightFrame, relief="solid")
  35. gridFrame.pack(side="top", fill="both", padx=20, pady=20)
  36. self.readOuts = {}
  37. for sensor in range(4):
  38. for axis in range(3):
  39. name = "force_{}_{}".format(chr(ord('X') + axis), 'sum' if sensor==0 else sensor)
  40. label = tk.Label(gridFrame, text=name)
  41. label.grid(row=sensor*2, column=axis)
  42. self.readOuts[name] = tk.StringVar()
  43. entry = tk.Entry(gridFrame, textvariable=self.readOuts[name], width=10)
  44. entry.grid(row=sensor*2+1, column=axis)
  45. def update(self, visible):
  46. if visible:
  47. self.forcePlot.plot_data(
  48. xs=[self.controller.getLastValues(self.plotLen, "force_X_{}".format(i+1)) for i in range(3)] +
  49. [np.sin(np.linspace(0, 6.282, self.plotLen))],
  50. ys=[self.controller.getLastValues(self.plotLen, "force_Y_{}".format(i+1)) for i in range(3)] +
  51. [np.cos(np.linspace(0, 6.282, self.plotLen))]
  52. )
  53. for name in self.readOuts:
  54. val = self.controller.getLastValue(name)
  55. if np.isnan(val):
  56. self.readOuts[name].set("")
  57. else:
  58. self.readOuts[name].set("{:1.3f} mV".format(val))