Bläddra i källkod

improved popup root creation

subDesTagesMitExtraKaese 3 år sedan
förälder
incheckning
9039f9bacc
2 ändrade filer med 23 tillägg och 13 borttagningar
  1. 14 2
      raspberry-pi/gui/Popup.py
  2. 9 11
      raspberry-pi/gui/mainWindow.py

+ 14 - 2
raspberry-pi/gui/Popup.py

@@ -9,7 +9,7 @@ class CalibrationPopUp(tk.Frame):
     self.root = root
     self.calibration_state = calibration_state
     tk.Frame.__init__(self, root)
-    self.killed = False
+    self.pendingClose = False
 
     self.instruction = tk.Label(self,text="Start Calibration", anchor="c",font=("Courier",18))
     self.instruction.pack(side="top", fill="both", expand=True)
@@ -17,14 +17,26 @@ class CalibrationPopUp(tk.Frame):
     button.pack(side="top", fill="both", expand=True)
     self.cs = tk.Label(self,text=self.calibration_state.state_clearname(), anchor="c")
     self.cs.pack(side="top", fill="both", expand=True)
+
+    root.bind('<Escape>', self.close)
   
   def update(self):
+    if not self.root.winfo_exists():
+      return
+
     self.cs["text"] = self.calibration_state.state_clearname()
     if self.calibration_state.get_state() == self.calibration_state.WAITING_POS_1:
       self.instruction["text"] = "Move gondola to far left corner!"
     elif self.calibration_state.get_state() == self.calibration_state.WAITING_POS_2:
       self.instruction["text"] = "Move gondola to far right corner!"
+    elif self.calibration_state.get_state() == self.calibration_state.CALIBRATION_DONE and not self.pendingClose:
+      self.pendingClose = True
+      self.root.after(1500, self.close)
     elif self.calibration_state.get_state() == self.calibration_state.CALIBRATION_DONE:
       self.instruction["text"] = "Calibration Done!"
     else:
-      self.instruction["text"] = "Processing..."
+      self.instruction["text"] = "Processing..."
+
+  def close(self):
+    if self.root.winfo_exists():
+      self.root.destroy()

+ 9 - 11
raspberry-pi/gui/mainWindow.py

@@ -30,6 +30,9 @@ class MainWindow(tk.Frame):
     calibrate_button.pack(side="top", fill="both")
 
   def update(self):
+    if not self.root.winfo_exists():
+      return
+
     ac_positions = []
     ac_raw_vals = (0, 0)
     while self.ac_queue.qsize() > 0:
@@ -44,26 +47,21 @@ class MainWindow(tk.Frame):
       self.ac_dro_y.set("Y: {:3.1f} mm".format(ac_positions[-1][1]))
 
     if self.popup:
-      if self.ac_cal_state.get_state() == self.ac_cal_state.CALIBRATION_DONE and not self.popup.killed:
-        self.popup.killed = True
-        self.root.after(1500,self.kill_popup)
       self.popup.update()
-    self.root.after(30, self.update)
 
-  def kill_popup(self):
-    self.pu_root.destroy()
-    self.popup = None
+    self.root.after(30, self.update)
 
   def calibrate(self):
     self.ac_sensor.start_calibration()
-    if not self.popup:
-      self.pu_root = tk.Tk()
-      self.pu_root.title("Calibration")
+    if not self.popup or not self.pu_root.winfo_exists():
+      self.pu_root = tk.Toplevel(self.root)
+      self.pu_root.wm_transient(self.root)
+      self.pu_root.wm_title("Calibration")
       self.pu_root.geometry("500x200")
+      self.pu_root.grab_set()
       self.popup = CalibrationPopUp(self.pu_root, self.ac_cal_state)
       self.popup.pack(side="top", fill="both", expand=True)
     
-    
 if __name__ == "__main__":
   root = tk.Tk()
   up_queue = queue.Queue()