Skip to content

Commit

Permalink
chat: another attempt to fix windows crashing
Browse files Browse the repository at this point in the history
  • Loading branch information
rmackay9 committed Dec 13, 2023
1 parent feccdb7 commit 5ee49df
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
8 changes: 7 additions & 1 deletion MAVProxy/modules/mavproxy_chat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from MAVProxy.modules.lib import mp_module
from MAVProxy.modules.lib import mp_util
from MAVProxy.modules.mavproxy_chat import chat_window
from threading import Thread

class chat(mp_module.MPModule):
def __init__(self, mpstate):
Expand All @@ -25,7 +26,12 @@ def __init__(self, mpstate):
# keep reference to mpstate
self.mpstate = mpstate

# add menu to map and console
# run chat window in a separate thread
self.thread = Thread(target=self.create_chat_window)
self.thread.start()

# create chat window (should be called from a new thread)
def create_chat_window(self):
if mp_util.has_wxpython:
# create chat window
self.chat_window = chat_window.chat_window(self.mpstate)
Expand Down
23 changes: 9 additions & 14 deletions MAVProxy/modules/mavproxy_chat/chat_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ def __init__(self, mpstate):
# lock to prevent multiple threads sending text to the assistant at the same time
self.send_lock = Lock()

# create chat_openai object
self.chat_openai = chat_openai.chat_openai(self.mpstate)

# create chat_voice_to_text object
self.chat_voice_to_text = chat_voice_to_text.chat_voice_to_text()

# create chat window
self.app = wx.App()
self.frame = wx.Frame(None, title="Chat", size=(650, 200))

Expand Down Expand Up @@ -66,24 +73,12 @@ def __init__(self, mpstate):
# show frame
self.frame.Show()

# create chat_openai object
self.chat_openai = chat_openai.chat_openai(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
# chat window loop (this does not return until the window is closed)
self.app.MainLoop()

# show the chat window
def show(self):
self.frame.Show()
wx.CallAfter(self.frame.Show())

# hide the chat window
def hide(self):
Expand Down

0 comments on commit 5ee49df

Please sign in to comment.