mainWindow.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. if self.calibration_state.get_state() == self.calibration_state.CALIBRATION_DONE and not self.popup.killed:
  37. self.popup.killed = True
  38. self.root.after(1500,self.kill_popup)
  39. self.popup.update()
  40. self.root.after(30, self.update)
  41. def kill_popup(self):
  42. self.pu_root.destroy()
  43. self.popup = None
  44. def calibrate(self):
  45. self.down_queue.put("calibrate")
  46. if not self.popup:
  47. self.pu_root = tk.Tk()
  48. self.pu_root.title("Calibration")
  49. self.pu_root.geometry("500x200")
  50. self.popup = Popup.CalibrationPopUp(self.pu_root,self.up_queue,self.down_queue,self.calibration_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()