123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- import tkinter as tk
- import time
- import queue
- from gui.popup import CalibrationPopUp
- from gui.graph import Graph
- class MainWindow(tk.Frame):
- def __init__(self, root, ac_sensor, ac_queue, ac_cal_state):
- self.root = root
- self.popup = None
- self.ac_cal_state = ac_cal_state
- self.ac_sensor = ac_sensor
- self.ac_queue = ac_queue
- tk.Frame.__init__(self, root)
- self.graph = Graph(self)
- self.graph.pack(fill=tk.BOTH, side=tk.LEFT, expand=True)
- self.controls = tk.Frame(self)
- self.controls.pack(fill=tk.BOTH, side=tk.RIGHT)
- self.ac_dro_x = tk.StringVar()
- self.ac_dro_y = tk.StringVar()
- tk.Label(self.controls, text="Acustic Sensor", anchor="c").pack(side="top", fill="both", expand=False)
- tk.Label(self.controls, textvariable=self.ac_dro_x, anchor="nw").pack(side="top", fill="both", expand=False)
- tk.Label(self.controls, textvariable=self.ac_dro_y, anchor="nw").pack(side="top", fill="both", expand=False)
- calibrate_button = tk.Button(self.controls,text="calibrate",command=self.calibrate)
- calibrate_button.pack(side="top", fill="both")
- def update(self):
- ac_positions = []
- ac_raw_vals = (0, 0)
- while self.ac_queue.qsize() > 0:
- name, data = self.ac_queue.get()
- if name == "data":
- ac_positions.append(data[0:2])
- ac_raw_vals = data[2:4]
- if len(ac_positions) > 0:
- self.graph.update([ac_positions])
- self.ac_dro_x.set("X: {:3.1f} mm".format(ac_positions[-1][0]))
- self.ac_dro_y.set("Y: {:3.1f} mm".format(ac_positions[-1][1]))
- if self.popup:
- if self.ac_cal_state.get_state() == self.ac_cal_state.CALIBRATION_DONE and not self.popup.killed:
- self.popup.killed = True
- self.root.after(1500,self.kill_popup)
- self.popup.update()
- self.root.after(30, self.update)
- def kill_popup(self):
- self.pu_root.destroy()
- self.popup = None
- def calibrate(self):
- self.ac_sensor.start_calibration()
- if not self.popup:
- self.pu_root = tk.Tk()
- self.pu_root.title("Calibration")
- self.pu_root.geometry("500x200")
- self.popup = CalibrationPopUp(self.pu_root, self.ac_cal_state)
- self.popup.pack(side="top", fill="both", expand=True)
-
-
- if __name__ == "__main__":
- root = tk.Tk()
- up_queue = queue.Queue()
- down_queue = queue.Queue()
- root.title("Tracking System")
- view = MainWindow(root,up_queue,down_queue,list())
- view.pack(side="top", fill="both", expand=True)
- view.update()
- root.mainloop()
|