]> granicus.if.org Git - python/commitdiff
Issue #10365: File open dialog now works instead of crashing
authorTerry Jan Reedy <tjreedy@udel.edu>
Sun, 27 May 2012 00:23:45 +0000 (20:23 -0400)
committerTerry Jan Reedy <tjreedy@udel.edu>
Sun, 27 May 2012 00:23:45 +0000 (20:23 -0400)
even when parent window is closed. Patch by Roger Serwy.

Lib/idlelib/IOBinding.py
Lib/idlelib/PyShell.py
Misc/NEWS

index d20c708ef9c814c5d0b80e200f4396cf4fa254c3..eb7f97b0737be9c29e77adea5836ef837a9d5114 100644 (file)
@@ -156,7 +156,8 @@ class IOBinding:
                 self.filename_change_hook()
 
     def open(self, event=None, editFile=None):
-        if self.editwin.flist:
+        flist = self.editwin.flist
+        if flist:
             if not editFile:
                 filename = self.askopenfile()
             else:
@@ -167,16 +168,22 @@ class IOBinding:
                 # we open a new window.  But we won't replace the
                 # shell window (which has an interp(reter) attribute), which
                 # gets set to "not modified" at every new prompt.
+                # Also, make sure the current window has not been closed,
+                # since it can be closed during the Open File dialog.
                 try:
                     interp = self.editwin.interp
                 except AttributeError:
                     interp = None
-                if not self.filename and self.get_saved() and not interp:
-                    self.editwin.flist.open(filename, self.loadfile)
+
+                if self.editwin and not self.filename and \
+                          self.get_saved() and not interp:
+                    flist.open(filename, self.loadfile)
                 else:
-                    self.editwin.flist.open(filename)
+                    flist.open(filename)
             else:
-                self.text.focus_set()
+                if self.text:
+                    self.text.focus_set()
+            
             return "break"
         #
         # Code for use outside IDLE:
index 74a37db862e5023f46df1842cfc021f487e077e9..edb4f37669c438651df86cc3a94183f80a184454 100644 (file)
@@ -1435,7 +1435,8 @@ def main():
     if tkversionwarning:
         shell.interp.runcommand(''.join(("print('", tkversionwarning, "')")))
 
-    root.mainloop()
+    while flist.inversedict:  # keep IDLE running while files are open.
+        root.mainloop()
     root.destroy()
 
 if __name__ == "__main__":
index 98e52b03edc409fd4b9371d8023d21064b4005c4..4cafa5df6a456716e08a870ee9296295c3b97343 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -67,6 +67,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #10365: File open dialog now works instead of crashing
+  even when parent window is closed. Patch by Roger Serwy.
+
 - Issue #14876: Use user-selected font for highlight configuration.
 
 - Issue #14920: Fix the help(urllib.parse) failure on locale C on terminals.