Skip to content

Commit

Permalink
Layout: Move code to register custom layouts from MainWindow to it
Browse files Browse the repository at this point in the history
  • Loading branch information
ccordoba12 committed Aug 26, 2022
1 parent cae2a7b commit 4bf50e1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
15 changes: 2 additions & 13 deletions spyder/app/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 15 additions & 0 deletions spyder/plugins/layout/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 4bf50e1

Please sign in to comment.