popup.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import tkinter as tk
  2. from tkinter.ttk import Progressbar
  3. class CalibrationPopUp(tk.Frame):
  4. def __init__(self, root, calibration_state):
  5. self.root = root
  6. self.calibration_state = calibration_state
  7. tk.Frame.__init__(self, root)
  8. self.pendingClose = False
  9. self.instruction = tk.Label(self,text="Start Calibration", anchor="c",font=("Helvatica", 18, 'bold'))
  10. self.instruction.pack(side="top", fill="both", expand=True)
  11. button = tk.Button(self,text="OK", command=self.calibration_state.next_state_gui, anchor="c",height=1,width=5)
  12. button.pack(side="top", fill="both", expand=True)
  13. self.cs = Progressbar(self, orient='horizontal', mode='determinate')
  14. self.cs.pack(side="top", fill="both", expand=True)
  15. root.bind('<Escape>', self.close)
  16. def update(self):
  17. if not self.root.winfo_exists():
  18. return
  19. self.cs['value'] = self.calibration_state.progress
  20. if self.calibration_state.get_state() == self.calibration_state.WAITING_POS_1:
  21. self.instruction["text"] = "Move gondola to far left corner!"
  22. elif self.calibration_state.get_state() == self.calibration_state.WAITING_POS_2:
  23. self.instruction["text"] = "Move gondola to far right corner!"
  24. elif self.calibration_state.get_state() == self.calibration_state.CALIBRATION_DONE and not self.pendingClose:
  25. self.pendingClose = True
  26. self.root.after(1500, self.close)
  27. elif self.calibration_state.get_state() == self.calibration_state.CALIBRATION_DONE:
  28. self.instruction["text"] = "Calibration Done!"
  29. else:
  30. self.instruction["text"] = "Processing..."
  31. def close(self):
  32. if self.root.winfo_exists():
  33. self.root.destroy()