popup.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. # display captured value count as progress
  20. self.cs['value'] = self.calibration_state.progress
  21. # read state from state machine
  22. if self.calibration_state.get_state() == self.calibration_state.WAITING_POS_1:
  23. self.instruction["text"] = "Move gondola to far left corner!"
  24. elif self.calibration_state.get_state() == self.calibration_state.WAITING_POS_2:
  25. self.instruction["text"] = "Move gondola to far right corner!"
  26. elif self.calibration_state.get_state() == self.calibration_state.CALIBRATION_DONE:
  27. self.instruction["text"] = "Calibration Done!"
  28. if not self.pendingClose:
  29. self.pendingClose = True
  30. self.root.after(1500, self.close)
  31. else:
  32. self.instruction["text"] = "Processing..."
  33. def close(self):
  34. if self.root.winfo_exists():
  35. self.root.destroy()