Skip to content

Commit

Permalink
Migrate statusbar, toolbar and tours to use the new teardown mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
andfoy committed Aug 30, 2021
1 parent e4af3da commit 570bc51
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
8 changes: 7 additions & 1 deletion spyder/plugins/statusbar/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
14 changes: 13 additions & 1 deletion spyder/plugins/toolbar/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down
10 changes: 9 additions & 1 deletion spyder/plugins/tours/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit 570bc51

Please sign in to comment.