Open 2d7eb291-d5a0-47da-9069-aaa138c02b11 opened 4 years ago
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:
Thanks for your consideration.
Irv
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.
Double clicking in finder with current Mohave (10.14.6?) does same as described here. See Ned's comment (msg357667) for bpo-38946.
In mac Terminal, 'python3 -m idlelib tem.py' opens tem.py without shell, just as on Windows.
Irv also posted to idledev, where he explained his particular need: He teaches a class with assignment to write a .py file with certain behavior. Submissions are in 1 directory. He would like to double-click to load a file and F5 to run it. Currently, he has to move the mouse and click the loaded editor before running and move it back.
In reply to my post yesterday, he explained how to make double-click in finder open in IDLE: """I did change the default for how my Mac opens ".py" files. To do that I selected any ".py" and did a Get Info on it. A tall window opens, and allows me to change the default application for opening the file. I selected IDLE.app and chose "Change all"."""
More testing with my Macbook: both 'python3.9 -m idlelib -i file.py' in terminal *and* double-clicking in Finder open an editor, with 'Format' in the IDLE menu, open Shell (shifted right), with 'Shell' in the IDLE menu, and then lift the editor window, without giving it focus and changing the IDLE menu back. Rereview of the video (which omits the IDLE menu) suggests the same because Shell is to the right of the editor. The video is not as clear because the IDLE menu is omitted, the editor has only one line, and Irv's machine is much faster.
I consider the inconsistency to be a bug. The cause is this code after the creation of Shell.
if macosx.isAquaTk() and flist.dict:
# On OSX: when the user has double-clicked on a file that causes
# IDLE to be launched the shell window will open just in front of
# the file she wants to see. Lower the interpreter window when
# there are open files.
shell.top.lower()
Widgit.raise() and .lower() do not change focus. Since there is no way to shed focus, we need to save the focus window, if there is one (and make sure it is not the withdrawn root), before creating Shell and restore it after. There might be situations in which Shell should be left on top with the focus.
I can only reproduce the problem on first open of IDLE, when the system asks if IDLE is allowed access to the documents windows. On subsequent tests keyboard focus was on the newly opened file (I quit IDLE between tests).
macOS 13.0.1, Python 3.10.8, python.org installer.
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields: ```python assignee = 'https://github.com/terryjreedy' closed_at = None created_at =
labels = ['OS-mac', 'expert-IDLE', 'type-bug', '3.7']
title = 'Original window focus when opening IDLE by double clicking Python file Mac'
updated_at =
user = 'https://github.com/IrvKalb'
```
bugs.python.org fields:
```python
activity =
actor = 'terry.reedy'
assignee = 'terry.reedy'
closed = False
closed_date = None
closer = None
components = ['IDLE', 'macOS']
creation =
creator = 'IrvKalb'
dependencies = []
files = []
hgrepos = []
issue_num = 39325
keywords = []
message_count = 5.0
messages = ['359942', '365181', '365185', '365188', '370747']
nosy_count = 4.0
nosy_names = ['terry.reedy', 'ronaldoussoren', 'ned.deily', 'IrvKalb']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue39325'
versions = ['Python 3.7']
```