diff -r 03df2c1c6892 Lib/idlelib/EditorWindow.py --- a/Lib/idlelib/EditorWindow.py Thu Apr 03 10:31:25 2014 -0400 +++ b/Lib/idlelib/EditorWindow.py Thu Apr 03 20:58:41 2014 +0530 @@ -735,13 +735,8 @@ base, ext = os.path.splitext(os.path.basename(filename)) if os.path.normcase(ext) in (".py", ".pyw"): return True - try: - f = open(filename) - line = f.readline() - f.close() - except IOError: - return False - return line.startswith('#!') and line.find('python') >= 0 + line = self.text.get('1.0', '1.0 lineend') + return line.startswith('#!') and 'python' in line def close_hook(self): if self.flist: diff -r 03df2c1c6892 Lib/idlelib/IOBinding.py --- a/Lib/idlelib/IOBinding.py Thu Apr 03 10:31:25 2014 -0400 +++ b/Lib/idlelib/IOBinding.py Thu Apr 03 20:58:41 2014 +0530 @@ -553,9 +553,13 @@ def asksavefile(self): dir, base = self.defaultfilename("save") + filetypes = self.filetypes + if not self.editwin.ispythonsource(self.filename): + #See issue21140 + filetypes[0], filetypes[1] = filetypes[1], filetypes[0] if not self.savedialog: self.savedialog = tkFileDialog.SaveAs(master=self.text, - filetypes=self.filetypes) + filetypes=filetypes) filename = self.savedialog.show(initialdir=dir, initialfile=base) if isinstance(filename, unicode): filename = filename.encode(filesystemencoding) @@ -586,6 +590,8 @@ self.text.event_generate("<>") def save_a_copy(self, event): self.text.event_generate("<>") + def ispythonsource(self, filename): + return True #Change to False to mock OutputWindow. text = Text(root) text.pack() text.focus_set() diff -r 03df2c1c6892 Lib/idlelib/OutputWindow.py --- a/Lib/idlelib/OutputWindow.py Thu Apr 03 10:31:25 2014 -0400 +++ b/Lib/idlelib/OutputWindow.py Thu Apr 03 20:58:41 2014 +0530 @@ -20,7 +20,7 @@ def ispythonsource(self, filename): # No colorization needed - return 0 + return False def short_title(self): return "Output"