Skip to content

Commit 10a8ff2

Browse files
[3.14] gh-158067: Keep Python files first in IDLE Open dialog from Shell (GH-158071) (#158142)
gh-158067: Keep Python files first in IDLE Open dialog from Shell (GH-158071) Fix regression in July releases. (cherry picked from commit e08b0d4) Co-authored-by: Lazizbek Ergashev <lazerg2@gmail.com>
1 parent 8207539 commit 10a8ff2

4 files changed

Lines changed: 13 additions & 5 deletions

File tree

‎Lib/idlelib/idle_test/test_outwin.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ def test_save_defaults_to_text(self):
4646
io = self.window.io
4747
self.assertEqual(io.defaultextension, '.txt')
4848
# Text files are offered before Python files.
49-
self.assertEqual(io.filetypes[0][0], 'Text files')
49+
self.assertEqual(io.save_filetypes[0][0], 'Text files')
50+
51+
def test_open_defaults_to_python(self):
52+
# gh-158067: File Open still lists Python files first.
53+
self.assertEqual(self.window.io.filetypes[0][0], 'Python files')
5054

5155
def test_window_title(self):
5256
self.assertEqual(self.window.top.title(), 'Output' + ' (%s)' % platform.python_version())

‎Lib/idlelib/iomenu.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,10 @@ def print_window(self, event):
386386
("All files", "*"),
387387
)
388388

389-
# Output windows (Shell, Output) are not Python source, so they list
390-
# text files first and default to ".txt" (gh-65339).
389+
save_filetypes = filetypes
390+
391+
# Output windows (Shell, Output) are not Python source, so they save
392+
# with text files listed first and default to ".txt" (gh-65339).
391393
text_filetypes = (
392394
("Text files", "*.txt", "TEXT"),
393395
("Python files", py_extensions, "TEXT"),
@@ -427,7 +429,7 @@ def asksavefile(self):
427429
if not self.savedialog:
428430
self.savedialog = filedialog.SaveAs(
429431
parent=self.text,
430-
filetypes=self.filetypes,
432+
filetypes=self.save_filetypes,
431433
defaultextension=self.defaultextension)
432434
filename = self.savedialog.show(initialdir=dir, initialfile=base)
433435
return filename

‎Lib/idlelib/outwin.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def __init__(self, *args):
8080
self.text.bind("<<goto-file-line>>", self.goto_file_line)
8181
# Output is not Python source, so save it as text by default
8282
# (gh-65339).
83-
self.io.filetypes = self.io.text_filetypes
83+
self.io.save_filetypes = self.io.text_filetypes
8484
self.io.defaultextension = self.io.text_defaultextension
8585

8686
# Customize EditorWindow
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix the IDLE File Open dialog listing text files before Python files when
2+
opened from the Shell or an Output window.

0 commit comments

Comments
 (0)