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 a2c1405
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 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
21 changes: 10 additions & 11 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,16 @@ 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()
# chat window loop (this does not return until the window is closed)
self.app.MainLoop()

# 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
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 a2c1405

Please sign in to comment.