Browse Source

added calibration popup

w.mueller 4 years ago
parent
commit
fa19b06873
3 changed files with 43 additions and 16 deletions
  1. 33 0
      raspberry-pi/gui/Popup.py
  2. 9 16
      raspberry-pi/gui/mainWindow.py
  3. 1 0
      raspberry-pi/main.py

+ 33 - 0
raspberry-pi/gui/Popup.py

@@ -0,0 +1,33 @@
+import tkinter as tk
+import tkinter.messagebox
+import time
+import queue
+
+
+class CalibrationPopUp(tk.Frame):
+  def __init__(self, root, up_queue, down_queue,calibration_state):
+    self.root = root
+    self.calibration_state = calibration_state
+    self.down_queue = down_queue
+    self.up_queue = up_queue
+    tk.Frame.__init__(self, root)
+
+    self.csString = tk.StringVar()
+    self.instruction_string = tk.StringVar()
+    self.instruction_string.set("start Calibration!")
+    self.csString.set(self.calibration_state.state_clearname())
+    cs = tk.Label(self,textvariable=self.csString, anchor="c")
+    cs.pack(side="top", fill="both", expand=True)
+    dummy = tk.Label(self,text="dummy im a dummy", anchor="c")
+    dummy.pack(side="top", fill="both", expand=True)
+    instruction = tk.Label(self,textvariable=self.instruction_string, anchor="c")
+    instruction.pack(side="top", fill="both", expand=True)
+    button = tk.Button(self,text="OK", command=self.calibration_state.next_state_gui, anchor="c")
+    button.pack(side="top", fill="both", expand=True)
+  
+  def update(self):
+    self.csString.set(self.calibration_state.state_clearname())
+    if self.calibration_state.get_state() == self.calibration_state.WAITING_POS_1:
+        self.instruction_string.set("Move gondola to far left corner!")
+    if self.calibration_state.get_state() == self.calibration_state.WAITING_POS_2:
+        self.instruction_string.set("Move gondole to far right corner!")

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

@@ -1,13 +1,14 @@
 import tkinter as tk
-import tkinter.messagebox
 import time
 import queue
 
+import gui.Popup as Popup
 import gui.graph as Graph
 
 class MainWindow(tk.Frame):
   def __init__(self, root, up_queue, down_queue,calibration_state):
     self.root = root
+    self.popup = None
     self.calibration_state = calibration_state
     self.down_queue = down_queue
     self.up_queue = up_queue
@@ -24,27 +25,19 @@ class MainWindow(tk.Frame):
     calibrate_button = tk.Button(self.controls,text="calibrate",command=self.calibrate)
     calibrate_button.pack(side="top")
 
-    self.csString = tk.StringVar()
-    cs = tk.Label(self.controls, textvariable=self.csString, anchor="c")
-    cs.pack(side="top", fill="both", expand=True)
-
   def update(self):
     self.graph.update()
-    self.csString.set(self.calibration_state.state_clearname())
+    if self.popup:
+      self.popup.update()
     self.root.after(30, self.update)
 
   def calibrate(self):
-    self.calibration_state.reset_state()
-    tkinter.messagebox.showinfo(title="Calibrate", message="Move gondola to far left corner!")
-    self.calibration_state.next_state()
     self.down_queue.put("calibrate")
-    while self.calibration_state.return_state() != 3:
-      time.sleep(1)
-    tkinter.messagebox.showinfo(title="Calibrate", message="Move gondola to far rigth corner!")
-    self.calibration_state.next_state()
-    while self.calibration_state.return_state() != 7:
-      time.sleep(1)
-    tkinter.messagebox.showinfo(title="Calibrate",message="Calibration Done!") #display new calibration values?
+    pu_root = tk.Tk()
+    pu_root.title("Calibration")
+    self.popup = Popup.CalibrationPopUp(pu_root,self.up_queue,self.down_queue,self.calibration_state)
+    self.popup.pack(side="top", fill="both", expand=True)
+    
     
 if __name__ == "__main__":
   root = tk.Tk()

+ 1 - 0
raspberry-pi/main.py

@@ -43,6 +43,7 @@ class CalibrationStateMashine():
       print(self.state_clearname())
 
   def next_state_gui(self):
+    print("next_state_gui",self.state)
     if self.state == self.WAITING_POS_1 or self.state == self.WAITING_POS_2:
       self.next_state()