Skip to content

Commit

Permalink
Editor: Catch KeyError when getting toolbars/menus in EditorMainWindow
Browse files Browse the repository at this point in the history
Also, check for the presence of splitter handler because it can't be
available during tests.
  • Loading branch information
ccordoba12 committed Dec 28, 2023
1 parent d8f1544 commit 846e9e8
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions spyder/plugins/editor/widgets/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@ def toggle_outlineexplorer(self, value):
height=self.SPLITTER_WIDTH
)
self.splitter.setStyleSheet(self._splitter_css.toString())
self.splitter.handle(1).setEnabled(True)
if self.splitter.handle(1) is not None:
self.splitter.handle(1).setEnabled(True)
else:
self._sizes = self.splitter.sizes()
self.splitter.setChildrenCollapsible(True)
Expand All @@ -309,7 +310,8 @@ def toggle_outlineexplorer(self, value):
height="0px"
)
self.splitter.setStyleSheet(self._splitter_css.toString())
self.splitter.handle(1).setEnabled(False)
if self.splitter.handle(1) is not None:
self.splitter.handle(1).setEnabled(False)

self.splitter.setChildrenCollapsible(False)

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

for toolbar_id in toolbar_list:
toolbar = self.get_toolbar(toolbar_id, plugin=Plugins.Toolbar)
# This is necessary to run tests for this widget without Spyder's
# main window
try:
toolbar = self.get_toolbar(toolbar_id, plugin=Plugins.Toolbar)
except KeyError:
continue

new_toolbar = ApplicationToolbar(self, toolbar_id, toolbar._title)
for action in toolbar.actions():
new_toolbar.add_item(
Expand Down Expand Up @@ -397,9 +405,14 @@ def __init__(self, plugin, menu_actions, outline_plugin, parent=None):
view_menu = self._create_view_menu()
self.menuBar().addMenu(view_menu)
else:
self.menuBar().addMenu(
self.get_menu(menu_id, plugin=Plugins.MainMenu)
)
# This is necessary to run tests for this widget without
# Spyder's main window
try:
self.menuBar().addMenu(
self.get_menu(menu_id, plugin=Plugins.MainMenu)
)
except KeyError:
continue

# ---- Qt methods
# -------------------------------------------------------------------------
Expand Down

0 comments on commit 846e9e8

Please sign in to comment.