summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib/editor.py
diff options
context:
space:
mode:
authorTerry Jan Reedy <tjreedy@udel.edu>2019-09-16 23:04:21 (GMT)
committerGitHub <noreply@github.com>2019-09-16 23:04:21 (GMT)
commit0048afc16a7e7301d5c565237db271505e5fbed9 (patch)
tree51784b04b971073163df417c8cc81dddc98e1480 /Lib/idlelib/editor.py
parent81528ba2e81c39f4d6bca5b785e818c7d08b8501 (diff)
downloadcpython-0048afc16a7e7301d5c565237db271505e5fbed9.zip
cpython-0048afc16a7e7301d5c565237db271505e5fbed9.tar.gz
cpython-0048afc16a7e7301d5c565237db271505e5fbed9.tar.bz2
bpo-38183: Test_idle ignores user config directory GH-16198)
It no longer tries to create or access .idlerc or any files within. Users must run IDLE to discover problems with saving settings.
Diffstat (limited to 'Lib/idlelib/editor.py')
-rw-r--r--Lib/idlelib/editor.py34
1 files changed, 18 insertions, 16 deletions
diff --git a/Lib/idlelib/editor.py b/Lib/idlelib/editor.py
index 5cbf704..838cb04 100644
--- a/Lib/idlelib/editor.py
+++ b/Lib/idlelib/editor.py
@@ -116,7 +116,7 @@ class EditorWindow(object):
self.tkinter_vars = {} # keys: Tkinter event names
# values: Tkinter variable instances
self.top.instance_dict = {}
- self.recent_files_path = os.path.join(
+ self.recent_files_path = idleConf.userdir and os.path.join(
idleConf.userdir, 'recent-files.lst')
self.prompt_last_line = '' # Override in PyShell
@@ -924,9 +924,11 @@ class EditorWindow(object):
def update_recent_files_list(self, new_file=None):
"Load and update the recent files list and menus"
+ # TODO: move to iomenu.
rf_list = []
- if os.path.exists(self.recent_files_path):
- with open(self.recent_files_path, 'r',
+ file_path = self.recent_files_path
+ if file_path and os.path.exists(file_path):
+ with open(file_path, 'r',
encoding='utf_8', errors='replace') as rf_list_file:
rf_list = rf_list_file.readlines()
if new_file:
@@ -942,19 +944,19 @@ 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)]
- try:
- with open(self.recent_files_path, 'w',
- encoding='utf_8', errors='replace') as rf_file:
- rf_file.writelines(rf_list)
- except OSError as err:
- if not getattr(self.root, "recentfilelist_error_displayed", False):
- self.root.recentfilelist_error_displayed = True
- tkMessageBox.showwarning(title='IDLE Warning',
- message="Cannot update File menu Recent Files list. "
- "Your operating system says:\n%s\n"
- "Select OK and IDLE will continue without updating."
- % self._filename_to_unicode(str(err)),
- parent=self.text)
+ if file_path:
+ try:
+ with open(file_path, 'w',
+ encoding='utf_8', errors='replace') as rf_file:
+ rf_file.writelines(rf_list)
+ except OSError as err:
+ if not getattr(self.root, "recentfiles_message", False):
+ self.root.recentfiles_message = True
+ tkMessageBox.showwarning(title='IDLE Warning',
+ message="Cannot save Recent Files list to disk.\n"
+ f" {err}\n"
+ "Select OK to continue.",
+ 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