Browse Source

fixed quit function

subDesTagesMitExtraKaese 4 years ago
parent
commit
900127736f

+ 14 - 14
software/appWindow.py

@@ -45,17 +45,11 @@ class Main(tk.Tk, Table):
 
 
     print('initializing GUI...')
-    container = tk.Frame(self)
-    container.pack(side="top", fill="both", expand = True)
-    container.grid_rowconfigure(0, weight=1)
-    container.grid_columnconfigure(0, weight=1)
-
-
-    menubar = tk.Menu(container)
+    menubar = tk.Menu(self)
     filemenu = tk.Menu(menubar, tearoff=0)
     filemenu.add_command(label="Save settings", command = lambda: self.popupmsg("Not supported just yet!"))
     filemenu.add_separator()
-    filemenu.add_command(label="Exit", command=quit)
+    filemenu.add_command(label="Exit", command=self.stop)
     menubar.add_cascade(label="File", menu=filemenu)
 
     tk.Tk.config(self, menu=menubar)
@@ -76,9 +70,14 @@ class Main(tk.Tk, Table):
     button4 = tk.Button(top,text="Einstellungen",command=lambda: self.show_frame(Page_4))
     button4.pack(side=tk.LEFT)
 
-    button5 = tk.Button(top, text="QUIT", fg="red",command=quit)
+    button5 = tk.Button(top, text="QUIT", fg="red",command=self.stop)
     button5.pack(side=tk.LEFT)
-    top.pack(side="top", expand=True, fill="both")
+    top.pack(side="top", fill="both")
+
+    container = tk.Frame(self)
+    container.pack(side="top", fill="both", expand = True)
+    container.grid_rowconfigure(0, weight=1)
+    container.grid_columnconfigure(0, weight=1)
 
     self.frames = {}
 
@@ -92,10 +91,10 @@ class Main(tk.Tk, Table):
 
     self.show_frame(Page_1)
 
-    self.after(5000,self.interval)
-
     print('program ready!')
 
+    self.interval()
+
   def show_frame(self, cont):
     self.currentFrame = self.frames[cont]
     self.currentFrame.tkraise()
@@ -136,5 +135,6 @@ class Main(tk.Tk, Table):
 
     print("draw:    {:8.3f} ms".format((time.time() - start)*1000))
     
-
-          
+  def stop(self):
+    self.forceSensors.stop()
+    self.quit()

+ 1 - 0
software/database.py

@@ -10,6 +10,7 @@ class Table:
     self.rows = self.ys = np.ndarray(shape=(self.nRows, self.nCols), dtype=float)
     self.rows.fill(float('NaN'))
     self.timestamps = np.ndarray(shape=(self.nRows), dtype='datetime64[ns]')
+    self.timestamps.fill(datetime.now())
     self.rowIndex = 0
 
   def rowIdToOffset(self, id):

+ 2 - 1
software/main.py

@@ -9,8 +9,9 @@ try:
   app = Main()
   app.geometry("1280x720")
   app.mainloop()
+  print('program closed!')
 except KeyboardInterrupt as e:
+  app.stop()
   pass
-running = False
 
 sys.exit()

+ 3 - 3
software/ui/Page_1.py

@@ -31,12 +31,12 @@ class Page_1(tk.Frame):
     self.label4.pack()
     self.label4.config(text=str(self.t))
 
-    SendButton = tk.Button(left, text='Quit', command=quit)
+    SendButton = tk.Button(left, text='Quit', command=self.controller.stop)
     label2 = tk.Label(left, text="I could be a button")
     label3 = tk.Label(left, text="So could I")
 
-    left.pack(side="left", expand=True, fill="both")
-    container.pack(expand=True, fill="both", padx=7, pady=5)
+    left.pack(side="left", fill="both")
+    container.pack(fill="both", padx=7, pady=5)
     SendButton.pack()
 
     label1.pack()

+ 1 - 3
software/ui/globals.py

@@ -1,5 +1,3 @@
 
 
-LARGE_FONT= ("Verdana", 12)
-
-running = True
+LARGE_FONT= ("Verdana", 12)

+ 13 - 6
software/wirelessLoadCell/loadCells.py

@@ -1,13 +1,13 @@
 if __name__ == "__main__":
   from GSV4BT import GSV4BT
-  running = True
 else:
   from .GSV4BT import GSV4BT
-  from ui.globals import *
+  
 
 import time
 import bluetooth
 import threading
+import ctypes
 
 class LoadCells():
   def __init__(self):
@@ -20,7 +20,9 @@ class LoadCells():
   def connect(self):
     success = True
     for cell in self.cells:
-      if cell.isConnected():
+      if not self.running:
+        return
+      elif cell.isConnected():
         if cell.requiresSetup:
           cell.setNormalMode()
           cell.stopTransmission()
@@ -40,13 +42,18 @@ class LoadCells():
     return success
 
   def reconnectThread(self):
-    while running:
-      self.connect()
+    while self.running:
       time.sleep(1)
+      self.connect()
 
   def start(self):
+    self.running = True
     self.thread = threading.Thread(target=self.reconnectThread)
     self.thread.start()
+  
+  def stop(self):
+    if self.running:
+      self.running = False
 
   def getForces(self, id):
     cell = self.cells[id]
@@ -77,4 +84,4 @@ if __name__ == "__main__":
 
 
   except KeyboardInterrupt as e:
-    running = False
+    cells.stop()