Skip to content

Commit efcfb1a

Browse files
gh-65339: Save IDLE Shell and Output windows as text by default (#152742)
Their content is not Python source, so the Save As dialog now lists text files first and defaults to a ".txt" extension.
1 parent 51b511d commit efcfb1a

4 files changed

Lines changed: 23 additions & 0 deletions

File tree

Lib/idlelib/idle_test/test_outwin.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ def test_ispythonsource(self):
4141
self.assertFalse(w.ispythonsource('test.txt'))
4242
self.assertFalse(w.ispythonsource(__file__))
4343

44+
def test_save_defaults_to_text(self):
45+
# gh-65339: output is saved as text, not Python source.
46+
io = self.window.io
47+
self.assertEqual(io.defaultextension, '.txt')
48+
# Text files are offered before Python files.
49+
self.assertEqual(io.filetypes[0][0], 'Text files')
50+
4451
def test_window_title(self):
4552
self.assertEqual(self.window.top.title(), 'Output' + ' (%s)' % platform.python_version())
4653

Lib/idlelib/iomenu.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,16 @@ 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).
389+
text_filetypes = (
390+
("Text files", "*.txt", "TEXT"),
391+
("Python files", py_extensions, "TEXT"),
392+
("All files", "*"),
393+
)
394+
387395
defaultextension = '.py' if sys.platform == 'darwin' else ''
396+
text_defaultextension = '.txt'
388397

389398
def askopenfile(self):
390399
dir, base = self.defaultfilename("open")

Lib/idlelib/outwin.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ class OutputWindow(EditorWindow):
7878
def __init__(self, *args):
7979
EditorWindow.__init__(self, *args)
8080
self.text.bind("<<goto-file-line>>", self.goto_file_line)
81+
# Output is not Python source, so save it as text by default
82+
# (gh-65339).
83+
self.io.filetypes = self.io.text_filetypes
84+
self.io.defaultextension = self.io.text_defaultextension
8185

8286
# Customize EditorWindow
8387
def ispythonsource(self, filename):
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Saving the IDLE Shell or an Output window now defaults to a ``.txt``
2+
extension and lists text files before Python files, since their content is
3+
not Python source.

0 commit comments

Comments
 (0)