From fc28a635ab52df0d1fc0f90c4204b89b0bed2a55 Mon Sep 17 00:00:00 2001 From: Randy Mackay Date: Tue, 12 Dec 2023 21:01:47 +0900 Subject: [PATCH] chat: run GUI in a separate process --- MAVProxy/modules/mavproxy_chat/chat_window.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/MAVProxy/modules/mavproxy_chat/chat_window.py b/MAVProxy/modules/mavproxy_chat/chat_window.py index f447dd4dc0..8ccc4a9847 100644 --- a/MAVProxy/modules/mavproxy_chat/chat_window.py +++ b/MAVProxy/modules/mavproxy_chat/chat_window.py @@ -5,6 +5,7 @@ Chat window for input and output of AI chat ''' +from MAVProxy.modules.lib import multiproc from MAVProxy.modules.lib.wx_loader import wx from MAVProxy.modules.mavproxy_chat import chat_openai, chat_voice_to_text from threading import Thread, Lock @@ -17,6 +18,11 @@ def __init__(self, mpstate): # lock to prevent multiple threads sending text to the assistant at the same time self.send_lock = Lock() + self.child = multiproc.Process(target=self.child_task) + self.child.start() + + def child_task(self): + '''child process - this holds all the GUI elements''' self.app = wx.App() self.frame = wx.Frame(None, title="Chat", size=(650, 200)) @@ -72,13 +78,7 @@ def __init__(self, mpstate): # create chat_voice_to_text object self.chat_voice_to_text = chat_voice_to_text.chat_voice_to_text() - # run chat window in a separate thread - self.thread = Thread(target=self.idle_task) - self.thread.start() - - # update function rapidly called by mavproxy - def idle_task(self): - # update chat window + # run the GUI event loop self.app.MainLoop() # show the chat window