mainWindow.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import tkinter as tk
  2. import time
  3. import queue
  4. from gui.popup import CalibrationPopUp
  5. from gui.graph import Graph
  6. class MainWindow(tk.Frame):
  7. def __init__(self, root, ac_sensor, ac_queue, ac_cal_state):
  8. self.root = root
  9. self.popup = None
  10. self.ac_cal_state = ac_cal_state
  11. self.ac_sensor = ac_sensor
  12. self.ac_queue = ac_queue
  13. tk.Frame.__init__(self, root)
  14. self.graph = Graph(self)
  15. self.graph.pack(fill=tk.BOTH, side=tk.LEFT, expand=True)
  16. self.controls = tk.Frame(self)
  17. self.controls.pack(fill=tk.BOTH, side=tk.RIGHT)
  18. self.ac_dro_x = tk.StringVar()
  19. self.ac_dro_y = tk.StringVar()
  20. tk.Label(self.controls, text="Acustic Sensor", anchor="c").pack(side="top", fill="both", expand=False)
  21. tk.Label(self.controls, textvariable=self.ac_dro_x, anchor="nw").pack(side="top", fill="both", expand=False)
  22. tk.Label(self.controls, textvariable=self.ac_dro_y, anchor="nw").pack(side="top", fill="both", expand=False)
  23. calibrate_button = tk.Button(self.controls,text="calibrate",command=self.calibrate)
  24. calibrate_button.pack(side="top", fill="both")
  25. def update(self):
  26. if not self.root.winfo_exists():
  27. return
  28. ac_positions = []
  29. ac_raw_vals = (0, 0)
  30. while self.ac_queue.qsize() > 0:
  31. name, data = self.ac_queue.get()
  32. if name == "data":
  33. ac_positions.append(data[0:2])
  34. ac_raw_vals = data[2:4]
  35. if len(ac_positions) > 0:
  36. self.graph.update([ac_positions])
  37. self.ac_dro_x.set("X: {:3.1f} mm".format(ac_positions[-1][0]))
  38. self.ac_dro_y.set("Y: {:3.1f} mm".format(ac_positions[-1][1]))
  39. if self.popup:
  40. self.popup.update()
  41. self.root.after(30, self.update)
  42. def calibrate(self):
  43. self.ac_sensor.start_calibration()
  44. if not self.popup or not self.pu_root.winfo_exists():
  45. self.pu_root = tk.Toplevel(self.root)
  46. self.pu_root.wm_transient(self.root)
  47. self.pu_root.wm_title("Calibration")
  48. self.pu_root.geometry("500x200")
  49. self.pu_root.grab_set()
  50. self.popup = CalibrationPopUp(self.pu_root, self.ac_cal_state)
  51. self.popup.pack(side="top", fill="both", expand=True)
  52. if __name__ == "__main__":
  53. root = tk.Tk()
  54. up_queue = queue.Queue()
  55. down_queue = queue.Queue()
  56. root.title("Tracking System")
  57. view = MainWindow(root,up_queue,down_queue,list())
  58. view.pack(side="top", fill="both", expand=True)
  59. view.update()
  60. root.mainloop()