Skip to content

Commit

Permalink
Add remove_application_menu to main menu
Browse files Browse the repository at this point in the history
  • Loading branch information
andfoy committed Aug 31, 2021
1 parent c28c320 commit 1b2e3f6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
24 changes: 24 additions & 0 deletions spyder/plugins/completion/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,30 @@ def on_statusbar_teardown(self):
for sb in container.all_statusbar_widgets():
self.statusbar.remove_status_widget(sb.ID)

@on_plugin_teardown(plugin=Plugins.MainMenu)
def on_mainmenu_teardown(self):
main_menu = self.get_plugin(Plugins.MainMenu)
signature = inspect.signature(main_menu.add_item_to_application_menu)

for args, kwargs in self.application_menus_to_create:
menu_id = args[0]
main_menu.remove_application_menu(menu_id)

for args, kwargs in self.items_to_add_to_application_menus:
binding = signature.bind(*args, **kwargs)
binding.apply_defaults()

item = binding.arguments['item']
menu_id = binding.arguments['menu_id']
item_id = None
if hasattr(item, 'action_id'):
item_id = item.action_id
elif hasattr(item, 'menu_id'):
item_id = item.menu_id
if item_id is not None:
main_menu.remove_item_from_application_menu(
item_id, menu_id=menu_id)

def unregister(self):
"""Stop all running completion providers."""
for provider_name in self.providers:
Expand Down
13 changes: 13 additions & 0 deletions spyder/plugins/mainmenu/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,19 @@ def add_item_to_application_menu(self, item: ItemType,
menu.add_action(item, section=section, before=before,
before_section=before_section, omit_id=omit_id)

def remove_application_menu(self, menu_id: str):
"""
Remove a Spyder application menu.
Parameters
----------
menu_id: str
The menu unique identifier string.
"""
if menu_id in self._APPLICATION_MENUS:
menu = self._APPLICATION_MENUS.pop(menu_id)
self.main.menuBar().removeAction(menu.menuAction())

def remove_item_from_application_menu(self, item_id: str,
menu_id: Optional[str] = None):
"""
Expand Down

0 comments on commit 1b2e3f6

Please sign in to comment.