From bb24ee4e9dfdd5947484c23180bc67f57d6d8bb5 Mon Sep 17 00:00:00 2001 From: dalthviz Date: Mon, 24 May 2021 16:23:16 +0200 Subject: [PATCH 1/4] IPython Console: Initial reorganizations of IPython Console actions registration the with the mainmenu --- spyder/app/mainwindow.py | 32 ++-------------- spyder/plugins/ipythonconsole/plugin.py | 49 ++++++++++++++++++++++--- spyder/plugins/mainmenu/plugin.py | 4 +- 3 files changed, 47 insertions(+), 38 deletions(-) diff --git a/spyder/app/mainwindow.py b/spyder/app/mainwindow.py index ca68fa07a99..1cb11a887d5 100644 --- a/spyder/app/mainwindow.py +++ b/spyder/app/mainwindow.py @@ -613,8 +613,9 @@ def signal_handler(signum, frame=None): self.run_menu_actions = [] self.debug_menu = None self.debug_menu_actions = [] + # TODO: Remove after signal handling for aboutToShow is moved to the + # IPython Console self.consoles_menu = None - self.consoles_menu_actions = [] self.projects_menu = None self.projects_menu_actions = [] @@ -978,6 +979,7 @@ def setup(self): self.run_menu = mainmenu.get_application_menu("run_menu") self.debug_menu = mainmenu.get_application_menu("debug_menu") self.consoles_menu = mainmenu.get_application_menu("consoles_menu") + # TODO: Move to the IPython Console self.consoles_menu.aboutToShow.connect( self.update_execution_state_kernel) self.projects_menu = mainmenu.get_application_menu("projects_menu") @@ -1124,33 +1126,6 @@ def create_edit_action(text, tr_text, icon): menu_id=ApplicationMenus.Help, section=HelpMenuSections.Documentation) - # TODO: Move to plugin - # IPython documentation - if self.help is not None: - self.ipython_menu = SpyderMenu( - parent=self, - title=_("IPython documentation")) - intro_action = create_action( - self, - _("Intro to IPython"), - triggered=self.ipyconsole.show_intro) - quickref_action = create_action( - self, - _("Quick reference"), - triggered=self.ipyconsole.show_quickref) - guiref_action = create_action( - self, - _("Console help"), - triggered=self.ipyconsole.show_guiref) - add_actions( - self.ipython_menu, - (intro_action, guiref_action, quickref_action)) - mainmenu.add_item_to_application_menu( - self.ipython_menu, - menu_id=ApplicationMenus.Help, - section=HelpMenuSections.ExternalDocumentation, - before_section=HelpMenuSections.About) - # TODO: Migrate to use the MainMenu Plugin instead of list of actions # Filling out menu/toolbar entries: add_actions(self.edit_menu, self.edit_menu_actions) @@ -1158,7 +1133,6 @@ def create_edit_action(text, tr_text, icon): add_actions(self.source_menu, self.source_menu_actions) add_actions(self.run_menu, self.run_menu_actions) add_actions(self.debug_menu, self.debug_menu_actions) - add_actions(self.consoles_menu, self.consoles_menu_actions) add_actions(self.projects_menu, self.projects_menu_actions) # Emitting the signal notifying plugins that main window menu and diff --git a/spyder/plugins/ipythonconsole/plugin.py b/spyder/plugins/ipythonconsole/plugin.py index 7e28fd98e6f..2f930ab199d 100644 --- a/spyder/plugins/ipythonconsole/plugin.py +++ b/spyder/plugins/ipythonconsole/plugin.py @@ -659,12 +659,49 @@ def get_plugin_actions(self): triggered=self.tab_name_editor) # Add the action to the 'Consoles' menu on the main window - main_consoles_menu = self.main.consoles_menu_actions - main_consoles_menu.insert(0, create_client_action) - main_consoles_menu += [special_console_menu, connect_to_kernel_action, - MENU_SEPARATOR, - self.interrupt_action, restart_action, - reset_action] + from spyder.plugins.mainmenu.api import ( + ApplicationMenus, ConsolesMenuSections, HelpMenuSections) + from spyder.api.widgets.menus import SpyderMenu + new_consoles_actions = [ + create_client_action, special_console_menu, + connect_to_kernel_action] + restart_connect_consoles_actions = [ + self.interrupt_action, restart_action, reset_action] + for console_new_action in new_consoles_actions: + self.main.mainmenu.add_item_to_application_menu( + console_new_action, + menu_id=ApplicationMenus.Consoles, + section=ConsolesMenuSections.New) + for console_restart_connect_action in restart_connect_consoles_actions: + self.main.mainmenu.add_item_to_application_menu( + console_restart_connect_action, + menu_id=ApplicationMenus.Consoles, + section=ConsolesMenuSections.New) + + # IPython documentation + self.ipython_menu = SpyderMenu( + parent=self, + title=_("IPython documentation")) + intro_action = create_action( + self, + _("Intro to IPython"), + triggered=self.show_intro) + quickref_action = create_action( + self, + _("Quick reference"), + triggered=self.show_quickref) + guiref_action = create_action( + self, + _("Console help"), + triggered=self.show_guiref) + add_actions( + self.ipython_menu, + (intro_action, guiref_action, quickref_action)) + self.main.mainmenu.add_item_to_application_menu( + self.ipython_menu, + menu_id=ApplicationMenus.Help, + section=HelpMenuSections.ExternalDocumentation, + before_section=HelpMenuSections.About) # Plugin actions self.menu_actions = [create_client_action, special_console_menu, diff --git a/spyder/plugins/mainmenu/plugin.py b/spyder/plugins/mainmenu/plugin.py index 87631bca9b2..d27b11cbc6c 100644 --- a/spyder/plugins/mainmenu/plugin.py +++ b/spyder/plugins/mainmenu/plugin.py @@ -56,8 +56,7 @@ def register(self): create_app_menu(ApplicationMenus.Source, _("Sour&ce"), dynamic=False) create_app_menu(ApplicationMenus.Run, _("&Run"), dynamic=False) create_app_menu(ApplicationMenus.Debug, _("&Debug"), dynamic=False) - create_app_menu( - ApplicationMenus.Consoles, _("C&onsoles"), dynamic=False) + create_app_menu(ApplicationMenus.Consoles, _("C&onsoles")) create_app_menu( ApplicationMenus.Projects, _("&Projects"), dynamic=False) create_app_menu(ApplicationMenus.Tools, _("&Tools")) @@ -224,7 +223,6 @@ def add_item_to_application_menu(self, item, menu=None, menu_id=None, ApplicationMenus.Source: self._main.source_menu_actions, ApplicationMenus.Run: self._main.run_menu_actions, ApplicationMenus.Debug: self._main.debug_menu_actions, - ApplicationMenus.Consoles: self._main.consoles_menu_actions, ApplicationMenus.Projects: self._main.projects_menu_actions, } From 7d2559b36476a2b013fa0268941f949090133845 Mon Sep 17 00:00:00 2001 From: dalthviz Date: Tue, 25 May 2021 18:59:57 +0200 Subject: [PATCH 2/4] IPython Console: Move remaining logic for the Consoles menu to the IPython Console plugin --- spyder/app/mainwindow.py | 14 -------------- spyder/plugins/ipythonconsole/plugin.py | 11 +++++++---- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/spyder/app/mainwindow.py b/spyder/app/mainwindow.py index 1cb11a887d5..3cf2e2f6496 100644 --- a/spyder/app/mainwindow.py +++ b/spyder/app/mainwindow.py @@ -613,9 +613,6 @@ def signal_handler(signum, frame=None): self.run_menu_actions = [] self.debug_menu = None self.debug_menu_actions = [] - # TODO: Remove after signal handling for aboutToShow is moved to the - # IPython Console - self.consoles_menu = None self.projects_menu = None self.projects_menu_actions = [] @@ -978,10 +975,6 @@ def setup(self): self.source_menu.aboutToShow.connect(self.update_source_menu) self.run_menu = mainmenu.get_application_menu("run_menu") self.debug_menu = mainmenu.get_application_menu("debug_menu") - self.consoles_menu = mainmenu.get_application_menu("consoles_menu") - # TODO: Move to the IPython Console - self.consoles_menu.aboutToShow.connect( - self.update_execution_state_kernel) self.projects_menu = mainmenu.get_application_menu("projects_menu") self.projects_menu.aboutToShow.connect(self.valid_project) @@ -1404,13 +1397,6 @@ def register_shortcut(self, qaction_or_qshortcut, context, name, ) # --- Other - def update_execution_state_kernel(self): - """Handle execution state of the current console.""" - try: - self.ipyconsole.update_execution_state_kernel() - except AttributeError: - return - def valid_project(self): """Handle an invalid active project.""" try: diff --git a/spyder/plugins/ipythonconsole/plugin.py b/spyder/plugins/ipythonconsole/plugin.py index 2f930ab199d..084b3781346 100644 --- a/spyder/plugins/ipythonconsole/plugin.py +++ b/spyder/plugins/ipythonconsole/plugin.py @@ -34,6 +34,7 @@ # Local imports from spyder.api.plugins import Plugins, SpyderPluginWidget +from spyder.api.widgets.menus import SpyderMenu from spyder.config.base import (_, get_conf_path, get_home_dir, running_under_pytest) from spyder.config.gui import get_font @@ -46,6 +47,8 @@ from spyder.plugins.ipythonconsole.widgets import ( ClientWidget, ConsoleRestartDialog, KernelConnectionDialog, PageControlWidget) +from spyder.plugins.mainmenu.api import ( + ApplicationMenus, ConsolesMenuSections, HelpMenuSections) from spyder.py3compat import is_string, to_text_string, PY2, PY38_OR_MORE from spyder.utils import encoding from spyder.utils.icon_manager import ima @@ -658,10 +661,10 @@ def get_plugin_actions(self): icon=ima.icon('rename'), triggered=self.tab_name_editor) - # Add the action to the 'Consoles' menu on the main window - from spyder.plugins.mainmenu.api import ( - ApplicationMenus, ConsolesMenuSections, HelpMenuSections) - from spyder.api.widgets.menus import SpyderMenu + # Add actions to the 'Consoles' menu on the main window + console_menu = self.main.mainmenu.get_application_menu("consoles_menu") + console_menu.aboutToShow.connect( + self.update_execution_state_kernel) new_consoles_actions = [ create_client_action, special_console_menu, connect_to_kernel_action] From 3850b87c446d2b3afb2acfb9165bc87a814dd5a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Althviz=20Mor=C3=A9?= Date: Wed, 26 May 2021 19:25:56 +0200 Subject: [PATCH 3/4] IPython Console: Apply code style suggestions from code review Co-authored-by: Carlos Cordoba --- spyder/plugins/ipythonconsole/plugin.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spyder/plugins/ipythonconsole/plugin.py b/spyder/plugins/ipythonconsole/plugin.py index 084b3781346..2fe10d1620c 100644 --- a/spyder/plugins/ipythonconsole/plugin.py +++ b/spyder/plugins/ipythonconsole/plugin.py @@ -663,8 +663,7 @@ def get_plugin_actions(self): # Add actions to the 'Consoles' menu on the main window console_menu = self.main.mainmenu.get_application_menu("consoles_menu") - console_menu.aboutToShow.connect( - self.update_execution_state_kernel) + console_menu.aboutToShow.connect(self.update_execution_state_kernel) new_consoles_actions = [ create_client_action, special_console_menu, connect_to_kernel_action] From 1547fe8cba040858628d520bd03dab29e0ca2931 Mon Sep 17 00:00:00 2001 From: dalthviz Date: Wed, 26 May 2021 19:28:57 +0200 Subject: [PATCH 4/4] IPython Console: Add restart actions in the Restart section --- spyder/plugins/ipythonconsole/plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spyder/plugins/ipythonconsole/plugin.py b/spyder/plugins/ipythonconsole/plugin.py index 2fe10d1620c..9b70483bba1 100644 --- a/spyder/plugins/ipythonconsole/plugin.py +++ b/spyder/plugins/ipythonconsole/plugin.py @@ -678,7 +678,7 @@ def get_plugin_actions(self): self.main.mainmenu.add_item_to_application_menu( console_restart_connect_action, menu_id=ApplicationMenus.Consoles, - section=ConsolesMenuSections.New) + section=ConsolesMenuSections.Restart) # IPython documentation self.ipython_menu = SpyderMenu(