Skip to content

Commit

Permalink
force close all files
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin Peter committed Jul 22, 2022
1 parent fcbdaca commit 9ab93ba
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
14 changes: 9 additions & 5 deletions spyder/app/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import sys
import threading
import traceback
import weakref

#==============================================================================
# Check requirements before proceeding
Expand Down Expand Up @@ -674,7 +675,7 @@ def signal_handler(signum, frame=None):
self.window_position = None

# To keep track of the last focused widget
self.last_focused_widget = None
self.last_focused_widget = lambda: None
self.previous_focused_widget = None

# Server to open external files on a single instance
Expand Down Expand Up @@ -1477,14 +1478,17 @@ def hideEvent(self, event):
try:
for plugin in (self.widgetlist + self.thirdparty_plugins):
# TODO: Remove old API
last_focused_widget = self.last_focused_widget()
if not last_focused_widget:
continue
try:
# New API
if plugin.get_widget().isAncestorOf(
self.last_focused_widget):
last_focused_widget):
plugin.change_visibility(True)
except AttributeError:
# Old API
if plugin.isAncestorOf(self.last_focused_widget):
if plugin.isAncestorOf(last_focused_widget):
plugin._visibility_changed(True)

QMainWindow.hideEvent(self, event)
Expand All @@ -1495,9 +1499,9 @@ def change_last_focused_widget(self, old, now):
"""To keep track of to the last focused widget"""
if (now is None and QApplication.activeWindow() is not None):
QApplication.activeWindow().setFocus()
self.last_focused_widget = QApplication.focusWidget()
self.last_focused_widget = weakref.ref(QApplication.focusWidget())
elif now is not None:
self.last_focused_widget = now
self.last_focused_widget = weakref.ref(now)

self.previous_focused_widget = old

Expand Down
5 changes: 4 additions & 1 deletion spyder/app/tests/test_mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,9 @@ def main_window(request, tmpdir, qtbot):

# Close editor related elements
window.editor.close_all_files()
# force close all files
while window.editor.editorstacks[0].close_file(force=True):
pass
for editorwindow in window.editor.editorwindows:
editorwindow.close()
editorstack = window.editor.get_current_editorstack()
Expand Down Expand Up @@ -401,7 +404,7 @@ def main_window(request, tmpdir, qtbot):
for o in objects:
if type(o).__name__ == "ShellWidget":
n_shell += 1
# More than one because the help plugin might keep some refs
# Some widgets might still be shutting down
assert n_shell < 4

if os.name == 'nt':
Expand Down

0 comments on commit 9ab93ba

Please sign in to comment.