classification
Title: Original window focus when opening IDLE by double clicking Python file Mac
Type: behavior Stage:
Components: IDLE Versions: Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: terry.reedy Nosy List: IrvKalb, ned.deily, terry.reedy
Priority: normal Keywords:

Created on 2020-01-14 01:24 by IrvKalb, last changed 2020-03-27 19:23 by terry.reedy.

Messages (4)
msg359942 - (view) Author: Irv Kalb (IrvKalb) Date: 2020-01-14 01:24
I have my Mac to open ".py" files with IDLE.  If IDLE is not running, and I double click on a Python file, the Shell window opens, then the Python file I clicked on opens in front, but the Shell has keyboard focus.  In order to edit or run the source file, I must click in that window to give it focus.

I have made a two minute video that is available here as a private video:

https://youtu.be/Fs_ZAiej-WI

Thanks for your consideration.

Irv
msg365181 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-03-27 18:53
Ned, I believe that this issue results from peculiarities of how macOS runs apps.  Insight from you would be appreciated.

macOS Sierra 10.2.8?, Python 3.7.3 (Did you use python.org installer?)

On my Win10, multiple IDLE windows are cascaded to the right and down.  Each window opened gets the focus until the focus is moved.  So on startup, the last window opened ends up with the focus.
  'python -m idlelib tem tem2' opens tem and then tem2.
  'python -m idlelib -i tem' opens tem then a shell.

The order is set in pyshell.main(), where sys.args is parsed to set boolean enable_edit and enable_shell.  Then 'if enable_edit: ...' and 'if enable_shell: ...' execute.  I presume that the logic is that if one wants to immediately edit and run an existing file, there is little reason pass args to cause a shell opened also.

I watched your video a couple of times.  It appears to show Shell being opened first (with the focus) and then an editor being opened on top of it, but without getting the focus.  AFAIK, both are impossible.

One possible interpretation: editor and shell are opened in the normal order, with the editor somehow not appearing.  Then macOS intervenes to lift the editor above the shell, but without shifting the focus.  Or macOS intervenes some other way.  Or the specific tk in use on macOS has some undocumented macOS-specific behavior.  (The tcl/tk folk claim that 8.6.10 follows the doc better.)  In all these cases, IDLE's code is not responsible.  If you want to chase down the details, add some logging to pyshell.main.

The root problem is asking IDLE to open a shell.  For me, 'python -m idlelib tem' only opens tem without a shell.  Ditto for right-click 'Edit with IDLE'.  Can you tell what command is used to start IDLE with double clicks?  Can you change it to not open Shell?  Also, does updating to 3.7.7 (recommended) change anything?

I am inclined to close this as a 3rd party or non-bug issue, but will wait a bit for Ned to comment.
msg365185 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-03-27 19:17
Double clicking in finder with current Mohave (10.14.6?) does same as described here.  See Ned's comment (msg357667) for #38946.
msg365188 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-03-27 19:23
In mac Terminal, 'python3 -m idlelib tem.py' opens tem.py without shell, just as on Windows.
History
Date User Action Args
2020-03-27 19:23:20terry.reedysetmessages: + msg365188
2020-03-27 19:17:18terry.reedysetmessages: + msg365185
2020-03-27 18:53:19terry.reedysetnosy: + ned.deily
messages: + msg365181
2020-01-14 01:24:01IrvKalbcreate