Parcourir la source

auto update logScreen

subDesTagesMitExtraKaese il y a 3 ans
Parent
commit
16ade7f0ed

+ 0 - 25
raspberry-pi/Log_handler.py

@@ -1,25 +0,0 @@
-import datetime
-
-class LogList():
-    def __init__(self):
-        self.log_list = list()
-
-    def add_item(self,*args):
-        args = [str(i) for i in args]
-        item = " ".join(args)
-        item = str(datetime.datetime.now())+" , "+str(item)
-        self.log_list.append(item)
-        if len(self.log_list) > 100:
-            self.log_list.pop(0)
-
-    def get_log_list(self):
-        return self.log_list
-
-
-_log_handler = None
-
-def get_log_handler():
-    global _log_handler
-    if not _log_handler:
-        _log_handler = LogList()
-    return _log_handler

+ 0 - 49
raspberry-pi/gui/Logscreen.py

@@ -1,49 +0,0 @@
-import tkinter as tk
-from tkinter.ttk import Progressbar
-
-import Log_handler
-
-class LogScreen(tk.Frame):
-    def __init__(self, root):
-        self.root = root
-        tk.Frame.__init__(self, root)
-
-        self.log_handler = Log_handler.get_log_handler()
-
-        self.text = tk.Frame(self,relief="sunken",borderwidth=1)
-        self.text.pack(expand=True,fill=tk.BOTH)
-
-        self.y_scroll = tk.Scrollbar(self.text)
-        self.y_scroll.pack(side="right", fill="y")
-
-        self.x_scroll = tk.Scrollbar(self.text, orient='horizontal')
-        self.x_scroll.pack(side="bottom", fill="x")
-
-        self.textfield = tk.Listbox(self.text, yscrollcommand=self.y_scroll.set, xscrollcommand=self.x_scroll.set)
-        self.textfield.pack(side="left",expand=True, fill=tk.BOTH)
-
-        self.y_scroll.config(command=self.textfield.yview)
-        self.x_scroll.config(command=self.textfield.xview)
-
-        self.quit_button = tk.Button(self, text="Quit", command=self.close, height=2, width = 10)
-        self.quit_button.pack(side="right", fill="both")
-
-        self.refresh_button = tk.Button(self, text="Refresh", command=self.fill_textfield, height=2, width = 10)
-        self.refresh_button.pack(side="right", fill="both")
-
-        self.fill_textfield()
-
-        root.bind('<Escape>', self.close)
-    
-    def update(self):
-        if not self.root.winfo_exists():
-            return
-
-    def close(self):
-        if self.root.winfo_exists():
-            self.root.destroy()
-    
-    def fill_textfield(self):
-        self.textfield.delete(0,"end")
-        for element in self.log_handler.get_log_list():
-            self.textfield.insert(tk.END, element)

+ 48 - 0
raspberry-pi/gui/logScreen.py

@@ -0,0 +1,48 @@
+import tkinter as tk
+from tkinter.ttk import Progressbar
+
+import logHandler
+
+class LogScreen(tk.Frame):
+  def __init__(self, root):
+    self.root = root
+    tk.Frame.__init__(self, root)
+
+    self.log_handler = logHandler.get_log_handler()
+
+    self.text = tk.Frame(self,relief="sunken",borderwidth=1)
+    self.text.pack(expand=True,fill=tk.BOTH)
+
+    self.y_scroll = tk.Scrollbar(self.text)
+    self.y_scroll.pack(side="right", fill="y")
+
+    self.x_scroll = tk.Scrollbar(self.text, orient='horizontal')
+    self.x_scroll.pack(side="bottom", fill="x")
+
+    self.textfield = tk.Listbox(self.text, yscrollcommand=self.y_scroll.set, xscrollcommand=self.x_scroll.set)
+    self.textfield.pack(side="left",expand=True, fill=tk.BOTH)
+
+    self.y_scroll.config(command=self.textfield.yview)
+    self.x_scroll.config(command=self.textfield.xview)
+
+    self.quit_button = tk.Button(self, text="Close", command=self.close, height=2, width = 10)
+    self.quit_button.pack(side="right", fill="both")
+
+    for element in self.log_handler.get_log_list():
+      self.textfield.insert(tk.END, element)
+    self.log_handler.get_new_items()
+
+    root.bind('<Escape>', self.close)
+
+  def update(self):
+    if not self.root.winfo_exists():
+      return
+    lines = self.log_handler.get_new_items()
+    if lines:
+      for element in lines:
+        self.textfield.insert(tk.END, element)
+      self.textfield.see("end")
+
+  def close(self):
+    if self.root.winfo_exists():
+      self.root.destroy()

+ 5 - 5
raspberry-pi/gui/mainWindow.py

@@ -6,8 +6,8 @@ import numpy as np
 
 from gui.popup import CalibrationPopUp
 from gui.graph import Graph
-from gui.Logscreen import LogScreen
-import Log_handler
+from gui.logScreen import LogScreen
+import logHandler
 
 
 class MainWindow(tk.Frame):
@@ -18,7 +18,7 @@ class MainWindow(tk.Frame):
     self.ac_cal_state = ac_cal_state
     self.ac_sensor = ac_sensor
     self.ac_queue = ac_queue
-    self.log_handler = Log_handler.get_log_handler()
+    self.log_handler = logHandler.get_log_handler()
     self.log_handler.add_item("start Main Window")
 
     tk.Frame.__init__(self, root)
@@ -127,9 +127,9 @@ class MainWindow(tk.Frame):
     self.log_root.wm_transient(self.root)
     self.log_root.wm_title("Logs")
     #center
-    x = (self.log_root.winfo_screenwidth()  - 1000) / 2
+    x = (self.log_root.winfo_screenwidth()  - 780) / 2
     y = (self.log_root.winfo_screenheight() - 400) / 2
-    self.log_root.geometry(f'1000x400+{int(x)}+{int(y)}')
+    self.log_root.geometry(f'780x400+{int(x)}+{int(y)}')
     # deactivate mainWindow
     self.log_root.grab_set()
     self.log_window = LogScreen(self.log_root)

+ 31 - 0
raspberry-pi/logHandler.py

@@ -0,0 +1,31 @@
+import datetime
+
+class LogList():
+  def __init__(self):
+    self.log_list = list()
+    self.read_index = 0
+
+  def add_item(self,*args):
+    args = [str(i) for i in args]
+    item = " ".join(args)
+    item = str(datetime.datetime.now())+"   "+str(item)
+    self.log_list.append(item)
+    if len(self.log_list) > 100:
+      self.log_list.pop(0)
+
+  def get_log_list(self):
+    return self.log_list
+
+  def get_new_items(self):
+    items = self.log_list[self.read_index:]
+    self.read_index = len(self.log_list)
+    return items
+
+
+_log_handler = None
+
+def get_log_handler():
+  global _log_handler
+  if not _log_handler:
+    _log_handler = LogList()
+  return _log_handler

+ 2 - 2
raspberry-pi/main.py

@@ -6,13 +6,13 @@ import queue
 import configparser
 import tkinter as tk
 import traceback
-import Log_handler
+import logHandler
 
 conf = configparser.ConfigParser()
 conf.read('config.ini')
 
 def main():
-  log_handler = Log_handler.get_log_handler()
+  log_handler = logHandler.get_log_handler()
   ac_queue = queue.Queue()
   ac_calibration_state = CalibrationStateMashine(log_handler)
   ac_sensor = AcusticSensor(conf, ac_queue, ac_calibration_state)

+ 2 - 2
raspberry-pi/sensors/acusticSensor.py

@@ -6,7 +6,7 @@ import random
 import traceback
 
 from sensors.connection import globalArduinoSlave
-import Log_handler
+import logHandler
 
 conn = globalArduinoSlave()
 
@@ -26,7 +26,7 @@ class AcusticSensor:
     self.overhead_left          = float(conf["ac_sensor"]["overhead_left"])
     self.overhead_right         = float(conf["ac_sensor"]["overhead_right"])
 
-    self.log_handler = Log_handler.get_log_handler()
+    self.log_handler = logHandler.get_log_handler()
     self.log_handler.add_item("start ac_sensor")
 
     # temporary calibration variables

+ 2 - 2
raspberry-pi/sensors/connection.py

@@ -3,14 +3,14 @@ import time
 
 import serial
 import serial.tools.list_ports
-import Log_handler
+import logHandler
 
 
 class SerialConnection:
   def __init__(self):
     self._ser = None
     self.port = None
-    self.log_handler = Log_handler.get_log_handler()
+    self.log_handler = logHandler.get_log_handler()
   
   # try connecting to an available port
   def open(self, port = None, baudrate = 1000000):