Skip to content

Commit

Permalink
console: allow for adding of menu items in mavinit.scr
Browse files Browse the repository at this point in the history
  • Loading branch information
tridge committed Jul 14, 2023
1 parent 02d5d4f commit 537313e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
7 changes: 6 additions & 1 deletion MAVProxy/modules/lib/mp_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,12 @@ def add_to_submenu(self, submenu_path, item):
if m.name == submenu_path[0]:
m.add_to_submenu(submenu_path[1:], item)
return
raise(ValueError("No submenu (%s) found" % (submenu_path[0])))
# new submenu
if len(submenu_path) > 2:
self.add(MPMenuSubMenu(submenu_path[0], []))
self.add_to_submenu(submenu_path, item)
else:
self.add(MPMenuSubMenu(submenu_path[0], [item]))

def wx_menu(self):
'''return a wx.MenuBar() for the menu'''
Expand Down
22 changes: 21 additions & 1 deletion MAVProxy/modules/mavproxy_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def __init__(self, mpstate):
self.add_menu(self.vehicle_menu)

def cmd_console(self, args):
usage = 'usage: console <add|list|remove>'
usage = 'usage: console <add|list|remove|menu>'
if len(args) < 1:
print(usage)
return
Expand All @@ -119,6 +119,8 @@ def cmd_console(self, args):
id = args[1]
if id in self.user_added:
self.user_added.pop(id)
elif cmd == 'menu':
self.cmd_menu(args[1:])
else:
print(usage)

Expand All @@ -127,6 +129,24 @@ def add_menu(self, menu):
self.menu.add(menu)
self.mpstate.console.set_menu(self.menu, self.menu_callback)

def cmd_menu_add(self, args):
'''add to console menus'''
if len(args) < 2:
print("Usage: console menu add MenuPath command")
return
menupath = args[0].split(':')
name = menupath[-1]
cmd = '# ' + ' '.join(args[1:])
self.menu.add_to_submenu(menupath[:-1], MPMenuItem(name, name, cmd))

def cmd_menu(self, args):
'''control console menus'''
if len(args) < 2:
print("Usage: console menu <add>")
return
if args[0] == 'add':
self.cmd_menu_add(args[1:])

def remove_menu(self, menu):
'''add a new menu'''
self.menu.remove(menu)
Expand Down

0 comments on commit 537313e

Please sign in to comment.