forked from zietzm/Helmholtz_Test_Bench
Fixed ui_print, #6. Calls now processed in main thread.
This commit is contained in:
@@ -1760,6 +1760,9 @@ class OutputConsole(Frame):
|
||||
def __init__(self, parent):
|
||||
Frame.__init__(self, parent, relief=SUNKEN, bd=1)
|
||||
|
||||
# Queue for messages to print when this class currently has main thread control
|
||||
self.print_queue = Queue()
|
||||
|
||||
# configure Tkinter grid:
|
||||
self.grid_rowconfigure(ALL, weight=1)
|
||||
self.grid_columnconfigure(0, weight=1, minsize=60) # console needs to have a minimum width
|
||||
@@ -1773,3 +1776,23 @@ class OutputConsole(Frame):
|
||||
# link scrollbar to the console
|
||||
scrollbar.config(command=self.console.yview)
|
||||
self.console.config(yscrollcommand=scrollbar.set)
|
||||
|
||||
# Start the main thread for printing queued messages
|
||||
self.print_thread()
|
||||
|
||||
def print_thread(self):
|
||||
""" Continuous thread that checks if messages are present, and prints them if they are. """
|
||||
try:
|
||||
while True:
|
||||
msg = self.print_queue.get(block=False)
|
||||
# print to console
|
||||
self.console.insert(END, "\n" + msg)
|
||||
except Empty:
|
||||
pass
|
||||
self.console.see(END) # scroll console to bottom
|
||||
|
||||
# Print messages every 100 ms in the main Tkinter loop
|
||||
self.after(100, self.print_thread)
|
||||
|
||||
def put(self, message):
|
||||
self.print_queue.put(message)
|
||||
|
||||
Reference in New Issue
Block a user