diff --git a/MAVProxy/modules/mavproxy_chat/__init__.py b/MAVProxy/modules/mavproxy_chat/__init__.py index 95419a4de1..c03f89e760 100644 --- a/MAVProxy/modules/mavproxy_chat/__init__.py +++ b/MAVProxy/modules/mavproxy_chat/__init__.py @@ -26,7 +26,7 @@ def __init__(self, mpstate): super(chat, self).__init__(mpstate, "chat", "OpenAI chat support") # register module and commands - self.add_command('chat', self.cmd_chat, "chat module", ["show"]) + self.add_command('chat', self.cmd_chat, "chat module", ["hide", "show"]) # keep reference to mpstate self.mpstate = mpstate @@ -42,15 +42,18 @@ def __init__(self, mpstate): # create chat window (should be called from a new thread) def create_chat_window(self): + print("Trying to create chat window") if mp_util.has_wxpython: - # create chat window + # create chat window, and return the chat_window object created self.chat_window = chat_window.chat_window(self.mpstate, self.wait_for_command_ack) + # Call main loop of chat window + self.chat_window.start() else: print("chat: wx support required") # show help on command line options def usage(self): - return "Usage: chat " + return "Usage: chat " # control behaviour of the module def cmd_chat(self, args): @@ -58,6 +61,8 @@ def cmd_chat(self, args): print(self.usage()) elif args[0] == "show": self.show() + elif args[0] == "hide": + self.hide() else: print(self.usage()) @@ -65,6 +70,19 @@ def cmd_chat(self, args): def show(self): self.chat_window.show() + def hide(self): + self.chat_window.hide() + + def close(self): + self.chat_window.close() + + # unload function override for module interface + def unload(self): + # Close the chat window + self.close() + # Call the unload function of super class, to include its functionality + super(chat, self).unload() + # handle mavlink packet def mavlink_packet(self, m): if m.get_type() == 'COMMAND_ACK': diff --git a/MAVProxy/modules/mavproxy_chat/chat_window.py b/MAVProxy/modules/mavproxy_chat/chat_window.py index ef713d1089..037eee1e0b 100644 --- a/MAVProxy/modules/mavproxy_chat/chat_window.py +++ b/MAVProxy/modules/mavproxy_chat/chat_window.py @@ -90,12 +90,13 @@ def __init__(self, mpstate, wait_for_command_ack_fn): # show frame self.frame.Show() + def start(self): # chat window loop (this does not return until the window is closed) self.app.MainLoop() # show the chat window def show(self): - wx.CallAfter(self.frame.Show()) + wx.CallAfter(self.frame.Show) # hide the chat window def hide(self):