summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib/EditorWindow.py
diff options
context:
space:
mode:
authorNed Deily <nad@acm.org>2011-12-14 22:58:24 (GMT)
committerNed Deily <nad@acm.org>2011-12-14 22:58:24 (GMT)
commitf505b7425c1e46e847dfc1e4528bc178af06b085 (patch)
treee06db8ae4fab9080ea6b64501e65a7ae5e208686 /Lib/idlelib/EditorWindow.py
parent83ef2549de1f1f1eddf43934cacd6c57295e6681 (diff)
downloadcpython-f505b7425c1e46e847dfc1e4528bc178af06b085.zip
cpython-f505b7425c1e46e847dfc1e4528bc178af06b085.tar.gz
cpython-f505b7425c1e46e847dfc1e4528bc178af06b085.tar.bz2
Issue #4625: If IDLE cannot write to its recent file or breakpoint
files, display a message popup and continue rather than crash. (original patch by Roger Serwy)
Diffstat (limited to 'Lib/idlelib/EditorWindow.py')
-rw-r--r--Lib/idlelib/EditorWindow.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/Lib/idlelib/EditorWindow.py b/Lib/idlelib/EditorWindow.py
index d77f0a4..203a195 100644
--- a/Lib/idlelib/EditorWindow.py
+++ b/Lib/idlelib/EditorWindow.py
@@ -799,12 +799,17 @@ class EditorWindow(object):
rf_list = [path for path in rf_list if path not in bad_paths]
ulchars = "1234567890ABCDEFGHIJK"
rf_list = rf_list[0:len(ulchars)]
- rf_file = open(self.recent_files_path, 'w',
- encoding='utf_8', errors='replace')
try:
- rf_file.writelines(rf_list)
- finally:
- rf_file.close()
+ with open(self.recent_files_path, 'w',
+ encoding='utf_8', errors='replace') as rf_file:
+ rf_file.writelines(rf_list)
+ except IOError as err:
+ if not getattr(self.root, "recentfilelist_error_displayed", False):
+ self.root.recentfilelist_error_displayed = True
+ tkMessageBox.showerror(title='IDLE Error',
+ message='Unable to update Recent Files list:\n%s'
+ % str(err),
+ parent=self.text)
# for each edit window instance, construct the recent files menu
for instance in self.top.instance_dict:
menu = instance.recent_files_menu