From 570bc51d529ea9ea89be9ea2b110bcd2a49a021a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Andr=C3=A9s=20Margffoy=20Tuay?= Date: Mon, 30 Aug 2021 16:59:00 -0500 Subject: [PATCH] Migrate statusbar, toolbar and tours to use the new teardown mechanism --- spyder/plugins/statusbar/plugin.py | 8 +++++++- spyder/plugins/toolbar/plugin.py | 14 +++++++++++++- spyder/plugins/tours/plugin.py | 10 +++++++++- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/spyder/plugins/statusbar/plugin.py b/spyder/plugins/statusbar/plugin.py index 58a5bc0cea7..45b7fc55c56 100644 --- a/spyder/plugins/statusbar/plugin.py +++ b/spyder/plugins/statusbar/plugin.py @@ -14,7 +14,8 @@ # Local imports from spyder.api.exceptions import SpyderAPIError from spyder.api.plugins import Plugins, SpyderPluginV2 -from spyder.api.plugin_registration.decorators import on_plugin_available +from spyder.api.plugin_registration.decorators import ( + on_plugin_available, on_plugin_teardown) from spyder.api.translations import get_translation from spyder.api.widgets.status import StatusBarWidget from spyder.config.base import running_under_pytest @@ -72,6 +73,11 @@ def on_preferences_available(self): preferences = self.get_plugin(Plugins.Preferences) preferences.register_plugin_preferences(self) + @on_plugin_teardown(plugin=Plugins.Preferences) + def on_preferences_teardown(self): + preferences = self.get_plugin(Plugins.Preferences) + preferences.deregister_plugin_preferences(self) + def after_container_creation(self): container = self.get_container() container.sig_show_status_bar_requested.connect( diff --git a/spyder/plugins/toolbar/plugin.py b/spyder/plugins/toolbar/plugin.py index 4dbb98390d7..a10c0c7d491 100644 --- a/spyder/plugins/toolbar/plugin.py +++ b/spyder/plugins/toolbar/plugin.py @@ -15,7 +15,8 @@ # Local imports from spyder.api.exceptions import SpyderAPIError from spyder.api.plugins import SpyderPluginV2, Plugins -from spyder.api.plugin_registration.decorators import on_plugin_available +from spyder.api.plugin_registration.decorators import ( + on_plugin_available, on_plugin_teardown) from spyder.api.translations import get_translation from spyder.plugins.mainmenu.api import ApplicationMenus, ViewMenuSections from spyder.plugins.toolbar.api import ApplicationToolbars @@ -71,6 +72,17 @@ def on_main_menu_available(self): section=ViewMenuSections.Toolbar, before_section=ViewMenuSections.Layout) + @on_plugin_teardown(plugin=Plugins.MainMenu) + def on_main_menu_teardown(self): + mainmenu = self.get_plugin(Plugins.MainMenu) + # View menu Toolbar section + mainmenu.remove_item_from_application_menu( + self.toolbars_menu, + menu_id=ApplicationMenus.View) + mainmenu.remove_item_from_application_menu( + self.show_toolbars_action, + menu_id=ApplicationMenus.View) + def on_mainwindow_visible(self): container = self.get_container() diff --git a/spyder/plugins/tours/plugin.py b/spyder/plugins/tours/plugin.py index 8b041e1ce5c..4509f6f7129 100644 --- a/spyder/plugins/tours/plugin.py +++ b/spyder/plugins/tours/plugin.py @@ -12,7 +12,8 @@ # Local imports from spyder.api.plugins import Plugins, SpyderPluginV2 -from spyder.api.plugin_registration.decorators import on_plugin_available +from spyder.api.plugin_registration.decorators import ( + on_plugin_available, on_plugin_teardown) from spyder.api.translations import get_translation from spyder.config.base import get_safe_mode, running_under_pytest from spyder.plugins.application.api import ApplicationActions @@ -64,6 +65,13 @@ def on_main_menu_available(self): section=HelpMenuSections.Documentation, before=ApplicationActions.SpyderDocumentationAction) + @on_plugin_teardown(plugin=Plugins.MainMenu) + def on_main_menu_teardown(self): + mainmenu = self.get_plugin(Plugins.MainMenu) + mainmenu.remove_item_from_application_menu( + self.get_container().tour_action, + menu_id=ApplicationMenus.Help) + def on_mainwindow_visible(self): self.show_tour_message()