mainWindow.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. ac_positions = []
  27. ac_raw_vals = (0, 0)
  28. while self.ac_queue.qsize() > 0:
  29. name, data = self.ac_queue.get()
  30. if name == "data":
  31. ac_positions.append(data[0:2])
  32. ac_raw_vals = data[2:4]
  33. if len(ac_positions) > 0:
  34. self.graph.update([ac_positions])
  35. self.ac_dro_x.set("X: {:3.1f} mm".format(ac_positions[-1][0]))
  36. self.ac_dro_y.set("Y: {:3.1f} mm".format(ac_positions[-1][1]))
  37. if self.popup:
  38. if self.ac_cal_state.get_state() == self.ac_cal_state.CALIBRATION_DONE and not self.popup.killed:
  39. self.popup.killed = True
  40. self.root.after(1500,self.kill_popup)
  41. self.popup.update()
  42. self.root.after(30, self.update)
  43. def kill_popup(self):
  44. self.pu_root.destroy()
  45. self.popup = None
  46. def calibrate(self):
  47. self.ac_sensor.start_calibration()
  48. if not self.popup:
  49. self.pu_root = tk.Tk()
  50. self.pu_root.title("Calibration")
  51. self.pu_root.geometry("500x200")
  52. self.popup = CalibrationPopUp(self.pu_root, self.ac_cal_state)
  53. self.popup.pack(side="top", fill="both", expand=True)
  54. if __name__ == "__main__":
  55. root = tk.Tk()
  56. up_queue = queue.Queue()
  57. down_queue = queue.Queue()
  58. root.title("Tracking System")
  59. view = MainWindow(root,up_queue,down_queue,list())
  60. view.pack(side="top", fill="both", expand=True)
  61. view.update()
  62. root.mainloop()