appWindow.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. # The code for changing pages was derived from: http://stackoverflow.com/questions/7546050/switch-between-two-frames-in-tkinter
  2. # License: http://creativecommons.org/licenses/by-sa/3.0/
  3. from database import Table
  4. from analogPressure.sdpArray import SdpArray
  5. from analogPressure.mcp3008 import MCP3008
  6. from digitalPressure.sdp610Array import Spd610Array
  7. from wirelessLoadCell.loadCells import LoadCells
  8. from ui import *
  9. import tkinter as tk
  10. import tk_tools
  11. from time import *
  12. class Main(tk.Tk, Table):
  13. def __init__(self, *args, **kwargs):
  14. tk.Tk.__init__(self, *args, **kwargs)
  15. tk.Tk.wm_title(self, "Windkanal-Tool")
  16. self.adc = MCP3008(0,0)
  17. self.pressureSensors = Spd610Array()
  18. self.forceSensors = LoadCells()
  19. self.forceSensors.start()
  20. self.motorController = None
  21. Table.__init__(self,
  22. ["time", "windspeed", "motor_pwm"] +
  23. [f"pressure_{i}" for i in range(8)] +
  24. [f"adc_{i}" for i in range(1)] +
  25. [f"force_X_1", f"force_Y_1", f"force_Z_1"] +
  26. [f"force_X_2", f"force_Y_2", f"force_Z_2"] +
  27. [f"force_X_3", f"force_Y_3", f"force_Z_3"])
  28. self.saveAsCsv("test.csv")
  29. container = tk.Frame(self)
  30. container.pack(side="top", fill="both", expand = True)
  31. container.grid_rowconfigure(0, weight=1)
  32. container.grid_columnconfigure(0, weight=1)
  33. menubar = tk.Menu(container)
  34. filemenu = tk.Menu(menubar, tearoff=0)
  35. filemenu.add_command(label="Save settings", command = lambda: self.popupmsg("Not supported just yet!"))
  36. filemenu.add_separator()
  37. filemenu.add_command(label="Exit", command=quit)
  38. menubar.add_cascade(label="File", menu=filemenu)
  39. tk.Tk.config(self, menu=menubar)
  40. label = tk.Label(self, text="Bedienelemente", font=LARGE_FONT)
  41. label.pack(pady=10,padx=10)
  42. # top menu
  43. top = tk.Frame(self, borderwidth=2, relief="solid")
  44. button1 = tk.Button(top, text="Bedienelemente", command=lambda: self.show_frame(Page_1))
  45. button1.pack(side=tk.LEFT)
  46. button2 = tk.Button(top, text="Kräfte", command=lambda: self.show_frame(Page_2))
  47. button2.pack(side=tk.LEFT)
  48. button3 = tk.Button(top, text="Druck", command=lambda: self.show_frame(Page_3))
  49. button3.pack(side=tk.LEFT)
  50. button4 = tk.Button(top,text="Einstellungen",command=lambda: self.show_frame(Page_4))
  51. button4.pack(side=tk.LEFT)
  52. button5 = tk.Button(top, text="QUIT", fg="red",command=quit)
  53. button5.pack(side=tk.LEFT)
  54. top.pack(side="top", expand=True, fill="both")
  55. self.frames = {}
  56. for F in (Page_1, Page_2, Page_3, Page_4):
  57. frame = F(container, self)
  58. self.frames[F] = frame
  59. frame.grid(row=0, column=0, sticky="nsew")
  60. self.show_frame(Page_1)
  61. self.interval()
  62. def show_frame(self, cont):
  63. frame = self.frames[cont]
  64. frame.tkraise()
  65. def popupmsg(self, msg=""):
  66. popup = tk.Toplevel(self.master)
  67. popup.wm_title("Error!")
  68. label = tk.Label(popup, text=msg, font=LARGE_FONT)
  69. label.pack(side="top", fill="x", pady=10)
  70. b1 = tk.Button(popup, text="Okay", command=popup.destroy)
  71. b1.pack()
  72. def interval(self):
  73. adcValues = self.adc.read()
  74. self.addRow(
  75. [time.time(), 0, 0] +
  76. self.pressureSensors.getValues() +
  77. [self.adc.getVoltage(0)] +
  78. self.forceSensors.getForces(0) +
  79. self.forceSensors.getForces(1) +
  80. self.forceSensors.getForces(2)
  81. )
  82. for frame in self.frames:
  83. frame.update()
  84. self.after(300,self.interval)