Skip to content

Commit 6a105f0

Browse files
SriramS-77rmackay9
authored andcommitted
Fixed issue of 'chat show' error, added 'chat hide' and fixed working of 'module unload chat'
1 parent c4f7ff2 commit 6a105f0

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

MAVProxy/modules/mavproxy_chat/__init__.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def __init__(self, mpstate):
2626
super(chat, self).__init__(mpstate, "chat", "OpenAI chat support")
2727

2828
# register module and commands
29-
self.add_command('chat', self.cmd_chat, "chat module", ["show"])
29+
self.add_command('chat', self.cmd_chat, "chat module", ["hide", "show"])
3030

3131
# keep reference to mpstate
3232
self.mpstate = mpstate
@@ -42,29 +42,47 @@ def __init__(self, mpstate):
4242

4343
# create chat window (should be called from a new thread)
4444
def create_chat_window(self):
45+
print("Trying to create chat window")
4546
if mp_util.has_wxpython:
46-
# create chat window
47+
# create chat window, and return the chat_window object created
4748
self.chat_window = chat_window.chat_window(self.mpstate, self.wait_for_command_ack)
49+
# Call main loop of chat window
50+
self.chat_window.start()
4851
else:
4952
print("chat: wx support required")
5053

5154
# show help on command line options
5255
def usage(self):
53-
return "Usage: chat <show>"
56+
return "Usage: chat <hide|show>"
5457

5558
# control behaviour of the module
5659
def cmd_chat(self, args):
5760
if len(args) == 0:
5861
print(self.usage())
5962
elif args[0] == "show":
6063
self.show()
64+
elif args[0] == "hide":
65+
self.hide()
6166
else:
6267
print(self.usage())
6368

6469
# show chat input window
6570
def show(self):
6671
self.chat_window.show()
6772

73+
def hide(self):
74+
self.chat_window.hide()
75+
76+
def close(self):
77+
self.chat_window.close()
78+
79+
# unload function override for module interface
80+
def unload(self):
81+
# Close the chat window
82+
self.close()
83+
# Call the unload function of super class, to include its functionality
84+
super(chat, self).unload()
85+
6886
# handle mavlink packet
6987
def mavlink_packet(self, m):
7088
if m.get_type() == 'COMMAND_ACK':

MAVProxy/modules/mavproxy_chat/chat_window.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,13 @@ def __init__(self, mpstate, wait_for_command_ack_fn):
9090
# show frame
9191
self.frame.Show()
9292

93+
def start(self):
9394
# chat window loop (this does not return until the window is closed)
9495
self.app.MainLoop()
9596

9697
# show the chat window
9798
def show(self):
98-
wx.CallAfter(self.frame.Show())
99+
wx.CallAfter(self.frame.Show)
99100

100101
# hide the chat window
101102
def hide(self):

0 commit comments

Comments
 (0)