mainWindow.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import tkinter as tk
  2. import time
  3. import queue
  4. import gui.Popup as Popup
  5. import gui.graph as Graph
  6. class MainWindow(tk.Frame):
  7. def __init__(self, root, up_queue, down_queue,calibration_state):
  8. self.root = root
  9. self.popup = None
  10. self.calibration_state = calibration_state
  11. self.down_queue = down_queue
  12. self.up_queue = up_queue
  13. tk.Frame.__init__(self, root)
  14. self.graph = 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_data = []
  27. while self.up_queue.qsize() > 0:
  28. name, data = self.up_queue.get()
  29. if name == "ac_data":
  30. ac_data.append(data)
  31. if len(ac_data) > 0:
  32. self.graph.update([ac_data])
  33. self.ac_dro_x.set("X: {:3.1f} mm".format(ac_data[-1][0]))
  34. self.ac_dro_y.set("Y: {:3.1f} mm".format(ac_data[-1][1]))
  35. if self.popup:
  36. self.popup.update()
  37. self.root.after(30, self.update)
  38. def calibrate(self):
  39. self.down_queue.put("calibrate")
  40. pu_root = tk.Tk()
  41. pu_root.title("Calibration")
  42. self.popup = Popup.CalibrationPopUp(pu_root,self.up_queue,self.down_queue,self.calibration_state)
  43. self.popup.pack(side="top", fill="both", expand=True)
  44. if __name__ == "__main__":
  45. root = tk.Tk()
  46. up_queue = queue.Queue()
  47. down_queue = queue.Queue()
  48. root.title("Tracking System")
  49. view = MainWindow(root,up_queue,down_queue,list())
  50. view.pack(side="top", fill="both", expand=True)
  51. view.update()
  52. root.mainloop()