popup.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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):
  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.instruction = tk.Label(self,text="Start Calibration", anchor="c",font=("SourceSansPro-Semibold", 18))
  12. self.instruction.pack(side="top", fill="both", expand=True)
  13. button = tk.Button(self,text="OK", command=self.calibration_state.next_state_gui, anchor="c",height=1,width=5)
  14. button.pack(side="top", fill="both", expand=True)
  15. self.cs = Progressbar(self, orient='horizontal', mode='determinate')
  16. self.cs.pack(side="top", fill="both", expand=True)
  17. root.bind('<Escape>', self.close)
  18. def update(self):
  19. if not self.root.winfo_exists():
  20. return
  21. # display captured value count as progress
  22. self.cs['value'] = self.calibration_state.progress
  23. # read state from state machine
  24. if self.calibration_state.get_state() == self.calibration_state.WAITING_POS_1:
  25. self.instruction["text"] = "Move gondola to left at calibration_y_offset!"
  26. elif self.calibration_state.get_state() == self.calibration_state.WAITING_POS_2:
  27. self.instruction["text"] = "Move gondola to right at calibration_y_offset!"
  28. elif self.calibration_state.get_state() == self.calibration_state.CALIBRATION_DONE:
  29. self.instruction["text"] = "Calibration Done!"
  30. if not self.pendingClose:
  31. self.pendingClose = True
  32. self.root.after(1500, self.close)
  33. else:
  34. self.instruction["text"] = "Processing..."
  35. def close(self):
  36. if self.root.winfo_exists():
  37. self.root.destroy()