popup.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import tkinter as tk
  2. from tkinter.ttk import Progressbar
  3. import pyglet
  4. class CalibrationPopUp(tk.Frame):
  5. def __init__(self, root, calibration_state, conf):
  6. self.root = root
  7. self.font = pyglet.font.add_file("gui/SourceSansPro-Semibold.otf")
  8. self.calibration_state = calibration_state
  9. tk.Frame.__init__(self, root)
  10. self.pendingClose = False
  11. self.conf = conf
  12. self.instruction = tk.Label(self,text="Start Calibration", anchor="c",font=("SourceSansPro-Semibold", 18))
  13. self.instruction.pack(side="top", fill="both", expand=True)
  14. button = tk.Button(self,text="OK", command=self.calibration_state.next_state_gui, anchor="c",height=1,width=5)
  15. button.pack(side="top", fill="both", expand=True)
  16. self.cs = Progressbar(self, orient='horizontal', mode='determinate')
  17. self.cs.pack(side="top", fill="both", expand=True)
  18. root.bind('<Escape>', self.close)
  19. def update(self):
  20. if not self.root.winfo_exists():
  21. return
  22. # display captured value count as progress
  23. self.cs['value'] = self.calibration_state.progress
  24. # read state from state machine
  25. if self.calibration_state.get_state() == self.calibration_state.WAITING_POS_1:
  26. text = "Move gondola to [" + self.conf["ac_sensor"]["calibration_x_offset"] + " , " + self.conf["ac_sensor"]["calibration_y_offset_1"] + "]!"
  27. self.instruction["text"] = text
  28. elif self.calibration_state.get_state() == self.calibration_state.WAITING_POS_2:
  29. text = "Move gondola to [" + self.conf["ac_sensor"]["calibration_x_offset"] + " , " + self.conf["ac_sensor"]["calibration_y_offset_2"] + "]!"
  30. self.instruction["text"] = text
  31. elif self.calibration_state.get_state() == self.calibration_state.CALIBRATION_DONE:
  32. self.instruction["text"] = "Calibration Done!"
  33. if not self.pendingClose:
  34. self.pendingClose = True
  35. self.root.after(1500, self.close)
  36. else:
  37. self.instruction["text"] = "Processing..."
  38. def close(self):
  39. if self.root.winfo_exists():
  40. self.root.destroy()