Repository: spyder-ide/spyder

Issue:
There's a blank space in the menus in the top in macOS
<!--- **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

* [ ] Searched the [issues page](https://github.com/spyder-ide/spyder/issues?q=is%3Aissue) for similar reports
* [ ] Read the relevant sections of the [Spyder Troubleshooting Guide](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ) and followed its advice
* [ ] Reproduced the issue after updating with ``conda update spyder`` (or ``pip``, if not using Anaconda)
* [ ] Could not reproduce inside ``jupyter qtconsole`` (if console-related)
* [ ] Tried basic troubleshooting (if a bug/error)
    * [ ] 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
* [ ] Completed the **Problem Description**, **Steps to Reproduce** and **Version** sections below


## Problem Description
In the current master, when navigating through the menus a blank entry is shown

![image](https://user-images.githubusercontent.com/20992645/106196494-7cf36980-617f-11eb-91a8-765eab6ce1a5.png)

![image](https://user-images.githubusercontent.com/20992645/106196514-8250b400-617f-11eb-9a28-f910f837ae75.png)




Discussion:
Note: Maybe this is being caused by the changes in PR #14619 . Probably the space is the initial 'empty' action to enable the addition of the menu to the `menuBar` on Mac since the menus are populated dynamically in the `aboutToShow` signal
Seems like this happens only for non-migrated menus (currently only `Views` and `Help` are migrated).

@ccordoba12 should I add handling for non-migrated and migrated menus to prevent this (basically some kind of flag when creating the menu to indicate if the initial action is needed or not) or just wait to have all the menus migrated?
> should I add handling for non-migrated and migrated menus to prevent this (basically some kind of flag when creating the menu to indicate if the initial action is needed or not)

Yes, please do that so we can have a uniform look and feel for menus until all of them are migrated.

Resolving patch:
diff --git a/spyder/api/widgets/menus.py b/spyder/api/widgets/menus.py
--- a/spyder/api/widgets/menus.py
+++ b/spyder/api/widgets/menus.py
@@ -41,7 +41,7 @@ class SpyderMenu(QMenu):
     """
     MENUS = []
 
-    def __init__(self, parent=None, title=None):
+    def __init__(self, parent=None, title=None, dynamic=True):
         self._parent = parent
         self._title = title
         self._sections = []
@@ -55,7 +55,7 @@ def __init__(self, parent=None, title=None):
             super().__init__(title, parent)
 
         self.MENUS.append((parent, title, self))
-        if sys.platform == 'darwin':
+        if sys.platform == 'darwin' and dynamic:
             # Needed to enable the dynamic population of actions in menus
             # in the aboutToShow signal
             # See spyder-ide/spyder#14612
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
@@ -54,16 +54,20 @@ def register(self):
         # Reference holder dict for the menus
         self._APPLICATION_MENUS = OrderedDict()
         # Create Application menus using plugin public API
+        # FIXME: Migrated menus need to have 'dynamic=True' (default value) to
+        # work on Mac. Remove the 'dynamic' kwarg when migrating a menu!
         create_app_menu = self.create_application_menu
-        create_app_menu(ApplicationMenus.File, _("&File"))
-        create_app_menu(ApplicationMenus.Edit, _("&Edit"))
-        create_app_menu(ApplicationMenus.Search, _("&Search"))
-        create_app_menu(ApplicationMenus.Source, _("Sour&ce"))
-        create_app_menu(ApplicationMenus.Run, _("&Run"))
-        create_app_menu(ApplicationMenus.Debug, _("&Debug"))
-        create_app_menu(ApplicationMenus.Consoles, _("C&onsoles"))
-        create_app_menu(ApplicationMenus.Projects, _("&Projects"))
-        create_app_menu(ApplicationMenus.Tools, _("&Tools"))
+        create_app_menu(ApplicationMenus.File, _("&File"), dynamic=False)
+        create_app_menu(ApplicationMenus.Edit, _("&Edit"), dynamic=False)
+        create_app_menu(ApplicationMenus.Search, _("&Search"), dynamic=False)
+        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.Projects, _("&Projects"), dynamic=False)
+        create_app_menu(ApplicationMenus.Tools, _("&Tools"), dynamic=False)
         create_app_menu(ApplicationMenus.View, _("&View"))
         create_app_menu(ApplicationMenus.Help, _("&Help"))
 
@@ -180,7 +184,7 @@ def _setup_menus(self):
 
     # --- Public API
     # ------------------------------------------------------------------------
-    def create_application_menu(self, menu_id, title):
+    def create_application_menu(self, menu_id, title, dynamic=True):
         """
         Create a Spyder application menu.
 
@@ -195,7 +199,7 @@ def create_application_menu(self, menu_id, title):
             raise SpyderAPIError(
                 'Menu with id "{}" already added!'.format(menu_id))
 
-        menu = ApplicationMenu(self.main, title)
+        menu = ApplicationMenu(self.main, title, dynamic=dynamic)
         menu.menu_id = menu_id
         self._APPLICATION_MENUS[menu_id] = menu
         self.main.menuBar().addMenu(menu)


Test patch: