Skip to content

Commit 846e9e8

Browse files
committed
Editor: Catch KeyError when getting toolbars/menus in EditorMainWindow
Also, check for the presence of splitter handler because it can't be available during tests.
1 parent d8f1544 commit 846e9e8

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

spyder/plugins/editor/widgets/window.py

+19-6
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,8 @@ def toggle_outlineexplorer(self, value):
295295
height=self.SPLITTER_WIDTH
296296
)
297297
self.splitter.setStyleSheet(self._splitter_css.toString())
298-
self.splitter.handle(1).setEnabled(True)
298+
if self.splitter.handle(1) is not None:
299+
self.splitter.handle(1).setEnabled(True)
299300
else:
300301
self._sizes = self.splitter.sizes()
301302
self.splitter.setChildrenCollapsible(True)
@@ -309,7 +310,8 @@ def toggle_outlineexplorer(self, value):
309310
height="0px"
310311
)
311312
self.splitter.setStyleSheet(self._splitter_css.toString())
312-
self.splitter.handle(1).setEnabled(False)
313+
if self.splitter.handle(1) is not None:
314+
self.splitter.handle(1).setEnabled(False)
313315

314316
self.splitter.setChildrenCollapsible(False)
315317

@@ -364,7 +366,13 @@ def __init__(self, plugin, menu_actions, outline_plugin, parent=None):
364366
]
365367

366368
for toolbar_id in toolbar_list:
367-
toolbar = self.get_toolbar(toolbar_id, plugin=Plugins.Toolbar)
369+
# This is necessary to run tests for this widget without Spyder's
370+
# main window
371+
try:
372+
toolbar = self.get_toolbar(toolbar_id, plugin=Plugins.Toolbar)
373+
except KeyError:
374+
continue
375+
368376
new_toolbar = ApplicationToolbar(self, toolbar_id, toolbar._title)
369377
for action in toolbar.actions():
370378
new_toolbar.add_item(
@@ -397,9 +405,14 @@ def __init__(self, plugin, menu_actions, outline_plugin, parent=None):
397405
view_menu = self._create_view_menu()
398406
self.menuBar().addMenu(view_menu)
399407
else:
400-
self.menuBar().addMenu(
401-
self.get_menu(menu_id, plugin=Plugins.MainMenu)
402-
)
408+
# This is necessary to run tests for this widget without
409+
# Spyder's main window
410+
try:
411+
self.menuBar().addMenu(
412+
self.get_menu(menu_id, plugin=Plugins.MainMenu)
413+
)
414+
except KeyError:
415+
continue
403416

404417
# ---- Qt methods
405418
# -------------------------------------------------------------------------

0 commit comments

Comments
 (0)