Popup.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import tkinter as tk
  2. from tkinter.ttk import Progressbar
  3. import tkinter.messagebox
  4. import time
  5. import queue
  6. class CalibrationPopUp(tk.Frame):
  7. def __init__(self, root, calibration_state):
  8. self.root = root
  9. self.calibration_state = calibration_state
  10. tk.Frame.__init__(self, root)
  11. self.pendingClose = False
  12. self.instruction = tk.Label(self,text="Start Calibration", anchor="c",font=("Helvatica", 18, 'bold'))
  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. self.cs['value'] = self.calibration_state.progress
  23. if self.calibration_state.get_state() == self.calibration_state.WAITING_POS_1:
  24. self.instruction["text"] = "Move gondola to far left corner!"
  25. elif self.calibration_state.get_state() == self.calibration_state.WAITING_POS_2:
  26. self.instruction["text"] = "Move gondola to far right corner!"
  27. elif self.calibration_state.get_state() == self.calibration_state.CALIBRATION_DONE and not self.pendingClose:
  28. self.pendingClose = True
  29. self.root.after(1500, self.close)
  30. elif self.calibration_state.get_state() == self.calibration_state.CALIBRATION_DONE:
  31. self.instruction["text"] = "Calibration Done!"
  32. else:
  33. self.instruction["text"] = "Processing..."
  34. def close(self):
  35. if self.root.winfo_exists():
  36. self.root.destroy()