logScreen.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import tkinter as tk
  2. from tkinter.ttk import Progressbar
  3. import logHandler
  4. class LogScreen(tk.Frame):
  5. def __init__(self, root):
  6. self.root = root
  7. tk.Frame.__init__(self, root)
  8. self.log_handler = logHandler.get_log_handler()
  9. self.text = tk.Frame(self,relief="sunken",borderwidth=1)
  10. self.text.pack(expand=True,fill=tk.BOTH)
  11. self.y_scroll = tk.Scrollbar(self.text)
  12. self.y_scroll.pack(side="right", fill="y")
  13. self.x_scroll = tk.Scrollbar(self.text, orient='horizontal')
  14. self.x_scroll.pack(side="bottom", fill="x")
  15. self.textfield = tk.Listbox(self.text, yscrollcommand=self.y_scroll.set, xscrollcommand=self.x_scroll.set)
  16. self.textfield.pack(side="left",expand=True, fill=tk.BOTH)
  17. self.y_scroll.config(command=self.textfield.yview)
  18. self.x_scroll.config(command=self.textfield.xview)
  19. self.quit_button = tk.Button(self, text="Close", command=self.close, height=2, width = 10)
  20. self.quit_button.pack(side="right", fill="both")
  21. for element in self.log_handler.get_log_list():
  22. self.textfield.insert(tk.END, element)
  23. self.log_handler.get_new_items()
  24. root.bind('<Escape>', self.close)
  25. def update(self):
  26. if not self.root.winfo_exists():
  27. return
  28. lines = self.log_handler.get_new_items()
  29. if lines:
  30. for element in lines:
  31. self.textfield.insert(tk.END, element)
  32. self.textfield.see("end")
  33. def close(self):
  34. if self.root.winfo_exists():
  35. self.root.destroy()