@@ -1540,28 +1540,30 @@ def main():
15401540 args .remove (filename )
15411541 if not args :
15421542 flist .new ()
1543+
15431544 if enable_shell :
15441545 shell = flist .open_shell ()
15451546 if not shell :
15461547 return # couldn't open shell
1547-
15481548 if macosxSupport .runningAsOSXApp () and flist .dict :
15491549 # On OSX: when the user has double-clicked on a file that causes
15501550 # IDLE to be launched the shell window will open just in front of
15511551 # the file she wants to see. Lower the interpreter window when
15521552 # there are open files.
15531553 shell .top .lower ()
1554+ else :
1555+ shell = flist .pyshell
15541556
1555- shell = flist . pyshell
1556- # handle remaining options:
1557+ # Handle remaining options. If any of these are set, enable_shell
1558+ # was set also, so shell must be true to reach here.
15571559 if debug :
15581560 shell .open_debugger ()
15591561 if startup :
15601562 filename = os .environ .get ("IDLESTARTUP" ) or \
15611563 os .environ .get ("PYTHONSTARTUP" )
15621564 if filename and os .path .isfile (filename ):
15631565 shell .interp .execfile (filename )
1564- if shell and cmd or script :
1566+ if cmd or script :
15651567 shell .interp .runcommand ("""if 1:
15661568 import sys as _sys
15671569 _sys.argv = %r
@@ -1572,13 +1574,14 @@ def main():
15721574 elif script :
15731575 shell .interp .prepend_syspath (script )
15741576 shell .interp .execfile (script )
1575-
1576- # Check for problematic OS X Tk versions and print a warning message
1577- # in the IDLE shell window; this is less intrusive than always opening
1578- # a separate window.
1579- tkversionwarning = macosxSupport .tkVersionWarning (root )
1580- if tkversionwarning :
1581- shell .interp .runcommand ('' .join (("print('" , tkversionwarning , "')" )))
1577+ elif shell :
1578+ # If there is a shell window and no cmd or script in progress,
1579+ # check for problematic OS X Tk versions and print a warning
1580+ # message in the IDLE shell window; this is less intrusive
1581+ # than always opening a separate window.
1582+ tkversionwarning = macosxSupport .tkVersionWarning (root )
1583+ if tkversionwarning :
1584+ shell .interp .runcommand ("print('%s')" % tkversionwarning )
15821585
15831586 while flist .inversedict : # keep IDLE running while files are open.
15841587 root .mainloop ()
0 commit comments