From 4bf50e11ace7558dac93616b6d6964757d24d682 Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Fri, 26 Aug 2022 12:20:49 -0500 Subject: [PATCH] Layout: Move code to register custom layouts from MainWindow to it --- spyder/app/mainwindow.py | 15 ++------------- spyder/plugins/layout/plugin.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/spyder/app/mainwindow.py b/spyder/app/mainwindow.py index 6f764ff7399..fcac8d1c320 100644 --- a/spyder/app/mainwindow.py +++ b/spyder/app/mainwindow.py @@ -1012,19 +1012,8 @@ def pre_visible_setup(self): pass # Register custom layouts - for plugin_name in PLUGIN_REGISTRY.external_plugins: - plugin_instance = PLUGIN_REGISTRY.get_plugin(plugin_name) - if hasattr(plugin_instance, 'CUSTOM_LAYOUTS'): - if isinstance(plugin_instance.CUSTOM_LAYOUTS, list): - for custom_layout in plugin_instance.CUSTOM_LAYOUTS: - self.layouts.register_layout( - self.layouts, custom_layout) - else: - logger.info( - 'Unable to load custom layouts for {}. ' - 'Expecting a list of layout classes but got {}' - .format(plugin_name, plugin_instance.CUSTOM_LAYOUTS) - ) + if self.layouts is not None: + self.layouts.register_custom_layouts() # Needed to ensure dockwidgets/panes layout size distribution # when a layout state is already present. diff --git a/spyder/plugins/layout/plugin.py b/spyder/plugins/layout/plugin.py index c3a179b1028..caf8ed54fd7 100644 --- a/spyder/plugins/layout/plugin.py +++ b/spyder/plugins/layout/plugin.py @@ -285,6 +285,21 @@ def register_layout(self, parent_plugin, layout_type): """ self.get_container().register_layout(parent_plugin, layout_type) + def register_custom_layouts(self): + """Register custom layouts provided by external plugins.""" + for plugin_name in PLUGIN_REGISTRY.external_plugins: + plugin_instance = self.get_plugin(plugin_name) + if hasattr(plugin_instance, 'CUSTOM_LAYOUTS'): + if isinstance(plugin_instance.CUSTOM_LAYOUTS, list): + for custom_layout in plugin_instance.CUSTOM_LAYOUTS: + self.register_layout(self, custom_layout) + else: + logger.info( + f'Unable to load custom layouts for plugin ' + f'{plugin_name}. Expecting a list of layout classes ' + f'but got {plugin_instance.CUSTOM_LAYOUTS}.' + ) + def get_layout(self, layout_id): """ Get a registered layout by his ID.