Skip to content

Commit bcec380

Browse files
[3.15] gh-158067: Keep Python files first in IDLE Open dialog from Shell (GH-158071) (#158143)
Co-authored-by: Lazizbek Ergashev <lazerg2@gmail.com>
1 parent 58214d2 commit bcec380

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
@@ -384,8 +384,10 @@ def print_window(self, event):
384384
("All files", "*"),
385385
)
386386

387-
# Output windows (Shell, Output) are not Python source, so they list
388-
# text files first and default to ".txt" (gh-65339).
387+
save_filetypes = filetypes
388+
389+
# Output windows (Shell, Output) are not Python source, so they save
390+
# with text files listed first and default to ".txt" (gh-65339).
389391
text_filetypes = (
390392
("Text files", "*.txt", "TEXT"),
391393
("Python files", py_extensions, "TEXT"),
@@ -420,7 +422,7 @@ def asksavefile(self):
420422
if not self.savedialog:
421423
self.savedialog = filedialog.SaveAs(
422424
parent=self.text,
423-
filetypes=self.filetypes,
425+
filetypes=self.save_filetypes,
424426
defaultextension=self.defaultextension)
425427
filename = self.savedialog.show(initialdir=dir, initialfile=base)
426428
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)