Repository: spyder-ide/spyder

Issue:
Multiple IPython documentation help menus
<!--- **PLEASE READ:** When submitting here, please ensure you've completed the following checklist and checked the boxes to confirm. Issue reports without it may be closed. Thanks! --->

### Issue Report Checklist

* [x] Searched the [issues page](https://github.com/spyder-ide/spyder/issues?q=is%3Aissue) for similar reports
* [x] Read the relevant sections of the [Spyder Troubleshooting Guide](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ) and followed its advice
* [x] Reproduced the issue after updating with ``conda update spyder`` (or ``pip``, if not using Anaconda)
* [ ] Could not reproduce inside ``jupyter qtconsole`` (if console-related)
* [x] Tried basic troubleshooting (if a bug/error)
    * [x] Restarted Spyder
    * [ ] Reset preferences with ``spyder --reset``
    * [ ] Reinstalled the latest version of [Anaconda](https://www.anaconda.com/download/)
    * [ ] Tried the other applicable steps from the Troubleshooting Guide
* [x] Completed the **Problem Description**, **Steps to Reproduce** and **Version** sections below


## Problem Description
Every time you open a new console or restart a console using any of the IPython console menu options (not when you use Ctrl+t), a new IPython documentation submenu shows up under the help menu. After a while these become quite many...

Happens both with 5.0.5 and current master. Both Windows and Linux.

(I cannot seem to activate the screen shot feature on Linux while the menu is activated, so cannot provide a screen shot right now.)

### What steps reproduce the problem?

1. Open a new console or restart a console using the IPython console pane menu options

### What is the expected output? What do you see instead?
Ideally only a single IPython documentation submenu.


### Paste Traceback/Error Below (if applicable)
<!--- Copy from error dialog or View > Panes > Internal Console --->

```python-traceback

PASTE TRACEBACK HERE

```

## Versions
<!--- You can get this information from Help > About Spyder...
or (if Spyder won't launch) the "conda list" command
from the Anaconda Prompt/Terminal/command line. --->

* Spyder version: 6.0.0.dev0 bb2ed9a
* Python version: 3.8.10 64-bit
* Qt version: 5.9.7
* PyQt5 version: 5.9.2
* Operating System: Linux 3.10.0-1160.31.1.el7.x86_64

### Dependencies
<!--- Please go to the menu entry Help > Dependencies,
press the Copy to clipboard button and paste below --->

```

# Mandatory:
atomicwrites >=1.2.0          :  1.4.0 (OK)
chardet >=2.0.0               :  4.0.0 (OK)
cloudpickle >=0.5.0           :  1.6.0 (OK)
cookiecutter >=1.6.0          :  1.7.2 (OK)
diff_match_patch >=20181111   :  20200713 (OK)
intervaltree >=3.0.2          :  3.1.0 (OK)
IPython >=7.6.0               :  7.22.0 (OK)
jedi >=0.17.2;<0.19.0         :  0.17.2 (OK)
jsonschema >=3.2.0            :  3.2.0 (OK)
keyring >=17.0.0              :  23.0.1 (OK)
nbconvert >=4.0               :  6.1.0 (OK)
numpydoc >=0.6.0              :  1.1.0 (OK)
parso >=0.7.0;<0.9.0          :  0.7.0 (OK)
pexpect >=4.4.0               :  4.8.0 (OK)
pickleshare >=0.4             :  0.7.5 (OK)
psutil >=5.3                  :  5.8.0 (OK)
pygments >=2.0                :  2.9.0 (OK)
pylint >=2.5.0                :  2.9.1 (OK)
pyls_spyder >=0.4.0           :  0.4.0 (OK)
pylsp >=1.2.1;<1.3.0          :  1.3.0.dev0 (OK)
pylsp_black >=1.0.0           :  None (OK)
qdarkstyle =3.0.2             :  3.0.2 (OK)
qstylizer >=0.1.10            :  0.1.10 (OK)
qtawesome >=1.0.2             :  1.0.2 (OK)
qtconsole >=5.1.0             :  5.1.0 (OK)
qtpy >=1.5.0                  :  1.9.0 (OK)
rtree >=0.9.7                 :  0.9.7 (OK)
setuptools >=49.6.0           :  52.0.0.post20210125 (OK)
sphinx >=0.6.6                :  4.0.2 (OK)
spyder_kernels >=2.1.0;<2.2.0 :  3.0.0.dev0 (NOK)
textdistance >=4.2.0          :  4.2.1 (OK)
three_merge >=0.1.1           :  0.1.1 (OK)
watchdog >=0.10.3             :  2.1.3 (OK)
xdg >=0.26                    :  0.27 (OK)
zmq >=17                      :  20.0.0 (OK)

# Optional:
cython >=0.21                 :  0.29.23 (OK)
matplotlib >=2.0.0            :  3.3.4 (OK)
numpy >=1.7                   :  1.20.2 (OK)
pandas >=1.1.1                :  1.2.5 (OK)
scipy >=0.17.0                :  1.6.2 (OK)
sympy >=0.7.3                 :  1.8 (OK)
```



Discussion:
Hi @oscargus,

Can you please take a gif of the behavior you are having? I'm not sure if I'm doing the steps to reproduce it correctly.
I can reproduce this one. We'll fix it in our 5.1.2 version, to be released shortly.

Resolving patch:
diff --git a/spyder/plugins/ipythonconsole/plugin.py b/spyder/plugins/ipythonconsole/plugin.py
--- a/spyder/plugins/ipythonconsole/plugin.py
+++ b/spyder/plugins/ipythonconsole/plugin.py
@@ -182,6 +182,7 @@ def __init__(self, parent, testing=False, test_dir=None,
         self.css_path = CONF.get('appearance', 'css_path')
         self.run_cell_filename = None
         self.interrupt_action = None
+        self.add_actions_to_main_menus = True
 
         # Attrs for testing
         self.testing = testing
@@ -661,52 +662,55 @@ def get_plugin_actions(self):
                                        icon=ima.icon('rename'),
                                        triggered=self.tab_name_editor)
 
-        # 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]
-        restart_connect_consoles_actions = [
-            self.interrupt_action, restart_action, reset_action]
-        for console_new_action in new_consoles_actions:
+        # Add actions to main menus
+        if self.add_actions_to_main_menus:
+            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]
+            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,
+                    omit_id=True)
+            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.Restart,
+                    omit_id=True)
+
+            # 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(
-                console_new_action,
-                menu_id=ApplicationMenus.Consoles,
-                section=ConsolesMenuSections.New,
-                omit_id=True)
-        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.Restart,
+                self.ipython_menu,
+                menu_id=ApplicationMenus.Help,
+                section=HelpMenuSections.ExternalDocumentation,
+                before_section=HelpMenuSections.About,
                 omit_id=True)
 
-        # 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,
-            omit_id=True)
+        self.add_actions_to_main_menus = False
 
         # 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
--- a/spyder/plugins/mainmenu/plugin.py
+++ b/spyder/plugins/mainmenu/plugin.py
@@ -15,16 +15,14 @@
 
 # Third party imports
 from qtpy.QtGui import QKeySequence
-from qtpy.QtWidgets import QMenu
 
 # Local imports
 from spyder.api.exceptions import SpyderAPIError
-from spyder.api.plugins import Plugins, SpyderPluginV2, SpyderDockablePlugin
+from spyder.api.plugins import SpyderPluginV2, SpyderDockablePlugin
 from spyder.api.translations import get_translation
 from spyder.api.widgets.menus import MENU_SEPARATOR, SpyderMenu
-from spyder.plugins.mainmenu.api import (
-    ApplicationMenu, ApplicationMenus, HelpMenuSections)
-from spyder.utils.qthelpers import add_actions, set_menu_icons, SpyderAction
+from spyder.plugins.mainmenu.api import ApplicationMenu, ApplicationMenus
+from spyder.utils.qthelpers import set_menu_icons, SpyderAction
 
 # Localization
 _ = get_translation('spyder')


Test patch: