From 4b9958f5fda0d9844cfcc4c77a8e62117c61c24c Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Thu, 7 Dec 2023 10:07:23 -0500 Subject: [PATCH] API: Make render method of SpyderMenu public Also, make it run the _set_icons method because it's necessary after calling render manually. That will also avoid calling _set_icons externally. --- spyder/api/widgets/menus.py | 10 +++++++--- spyder/plugins/application/container.py | 2 +- spyder/plugins/ipythonconsole/widgets/main_widget.py | 3 +-- spyder/plugins/mainmenu/plugin.py | 7 +++---- spyder/plugins/projects/widgets/main_widget.py | 2 +- spyder/utils/qthelpers.py | 4 ++-- 6 files changed, 15 insertions(+), 13 deletions(-) diff --git a/spyder/api/widgets/menus.py b/spyder/api/widgets/menus.py index df393ae681f..4fbeb18ec37 100644 --- a/spyder/api/widgets/menus.py +++ b/spyder/api/widgets/menus.py @@ -102,7 +102,7 @@ def __init__( self.setMinimumWidth(min_width) # Signals - self.aboutToShow.connect(self._render) + self.aboutToShow.connect(self.render) # Adjustmens for Mac if sys.platform == 'darwin': @@ -267,7 +267,7 @@ def _add_missing_actions(self): self._unintroduced_actions = {} - def _render(self): + def render(self): """ Create the menu prior to showing it. This takes into account sections and location of menus. @@ -278,6 +278,8 @@ def _render(self): actions = self.get_actions() add_actions(self, actions) + self._set_icons() + self._dirty = False def _add_section(self, section, before_section=None): @@ -440,7 +442,7 @@ class PluginMainWidgetOptionsMenu(SpyderMenu): Options menu for PluginMainWidget. """ - def _render(self): + def render(self): """Render the menu's bottom section as expected.""" if self._dirty: self.clear() @@ -461,4 +463,6 @@ def _render(self): actions.append(action) add_actions(self, actions) + self._set_icons() + self._dirty = False diff --git a/spyder/plugins/application/container.py b/spyder/plugins/application/container.py index 095295f016e..cce31fa770a 100644 --- a/spyder/plugins/application/container.py +++ b/spyder/plugins/application/container.py @@ -617,7 +617,7 @@ def create_debug_log_actions(self): ) # Render menu - self.menu_debug_logs._render() + self.menu_debug_logs.render() def load_log_file(self, file): """Load log file in editor""" diff --git a/spyder/plugins/ipythonconsole/widgets/main_widget.py b/spyder/plugins/ipythonconsole/widgets/main_widget.py index 72b28ad0f46..d65a5751a8a 100644 --- a/spyder/plugins/ipythonconsole/widgets/main_widget.py +++ b/spyder/plugins/ipythonconsole/widgets/main_widget.py @@ -755,8 +755,7 @@ def update_environment_menu(self): menu=self.console_environment_menu ) - self.console_environment_menu._render() - self.console_environment_menu._set_icons() + self.console_environment_menu.render() # ---- GUI options @on_conf_change(section='help', option='connect/ipython_console') diff --git a/spyder/plugins/mainmenu/plugin.py b/spyder/plugins/mainmenu/plugin.py index 3524c115e69..3b08f1643b9 100644 --- a/spyder/plugins/mainmenu/plugin.py +++ b/spyder/plugins/mainmenu/plugin.py @@ -90,14 +90,13 @@ def on_initialize(self): create_app_menu(ApplicationMenus.Help, _("&Help")) def on_mainwindow_visible(self): - # Pre-render menus so actions with menu roles (like "About Spyder" - # and "Preferences") are located in the right place in Mac's menu - # bar. + # Pre-render menus so actions with menu roles (like "About Spyder" and + # "Preferences") are located in the right place in Mac's menu bar. # Fixes spyder-ide/spyder#14917 # This also registers shortcuts for actions that are only in menus. # Fixes spyder-ide/spyder#16061 for menu in self._APPLICATION_MENUS.values(): - menu._render() + menu.render() # ---- Private methods # ------------------------------------------------------------------------ diff --git a/spyder/plugins/projects/widgets/main_widget.py b/spyder/plugins/projects/widgets/main_widget.py index 2180671858d..883be42ea16 100644 --- a/spyder/plugins/projects/widgets/main_widget.py +++ b/spyder/plugins/projects/widgets/main_widget.py @@ -950,7 +950,7 @@ def _setup_menu_actions(self): section=RecentProjectsMenuSections.Extras) self._update_project_actions() - self.recent_project_menu._render() + self.recent_project_menu.render() def _build_opener(self, project): """Build function opening passed project""" diff --git a/spyder/utils/qthelpers.py b/spyder/utils/qthelpers.py index 16f62716499..b8772d7b5e9 100644 --- a/spyder/utils/qthelpers.py +++ b/spyder/utils/qthelpers.py @@ -703,10 +703,10 @@ def set_menu_icons(menu, state, in_app_menu=False): for action in menu_actions: try: if action.menu() is not None: - # This is necessary to decide if show icons or not + # This is necessary to decide if we need to show icons or not action.menu()._in_app_menu = in_app_menu - # This is submenu, so we need to call this again + # This is a submenu, so we need to call this again set_menu_icons(action.menu(), state, in_app_menu) elif action.isSeparator(): continue