This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: IDLE: Revise macOS key bindings, make new one.
Type: behavior Stage: test needed
Components: IDLE, macOS Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: terry.reedy Nosy List: markroseman, ned.deily, rhettinger, roger.serwy, ronaldoussoren, terry.reedy
Priority: normal Keywords:

Created on 2013-07-14 04:44 by Todd.Rovito, last changed 2022-04-11 14:57 by admin.

Messages (12)
msg193025 - (view) Author: Todd Rovito (Todd.Rovito) * Date: 2013-07-14 04:44
covers point 1.1) "Pressing the Home key moves the cursor before the >>> prompt, which then makes the keyboard unresponsive."

This issues was fixed on Windows XP and Linux here http://bugs.python.org/issue3851


On Mac OS X the "home" key is control-A or function left arrow both have the same effect of moving the cursor left of prompt, which them makes the keyboard unresponsive.  I tested this with Python 3.4 and Python 2.7 on Mac OS X 10.8.4.
msg193035 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2013-07-14 07:28
The reason for the observed behavior is that the built-in "IDLE Classic OSX" keyset, which is the default for OS X framework installs, has a different keybinding for "beginning-of-line".  See Lib/idlelib/config-key.def

[IDLE Classic OSX]
...
beginning-of-line = <Control-Key-Left>

I'm not sure why the decision was made to use this binding originally.  Unfortunately, on current OS X systems (with US keyboards at least) Control-Left is preemptively defined as the default system Mission Contol keyboard shortcut to "Move left a space" (e.g a desktop) so, by default, Tk (and, hence, IDLE) never sees it.  This can be seen by going to System Preferences -> Keyboard -> Keyboard Shortcuts -> Mission Control.  You can temporarily disable or change "Move left a space" and verify that then Control-L does perform as expected.  You can also verify that changing the IDLE keyset to "IDLE Classic Windows" redefines "beginning-of-line" to Control-A and Home.

There are a number of other problematic (non-functional) key bindings in the "IDLE Classic OSX" keyset depending on a number of factors: which Tk variant is in use (Cocoa Tk, Carbon Tk, X11 Tk), System Preferences keyboard shortcuts, possibly which keyboard and which system input method are in use.  For more info on some of the hard-to-fathom Tk differences see: http://wiki.tcl.tk/28331

After spending some time trying to understand how this all works or doesn't across the various Tk's, I am coming to the conclusion that we need to define a new set of default key bindings for OS X, one that generally avoids as much as possible the use of Command key and Option key accelerators, as these tend to be especially problematic either in Tk or with system conflicts, and, instead, use Fn keys for non-trivial accelerators.
msg193036 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2013-07-14 07:30
er, Lib/idlelib/config-keys.def
msg193067 - (view) Author: Todd Rovito (Todd.Rovito) * Date: 2013-07-14 19:51
Ned,
   Thanks for such a thorough comment this saved me lots of time now I don't have to dig so deeply into the problem.


"After spending some time trying to understand how this all works or doesn't across the various Tk's, I am coming to the conclusion that we need to define a new set of default key bindings for OS X, one that generally avoids as much as possible the use of Command key and Option key accelerators, as these tend to be especially problematic either in Tk or with system conflicts, and, instead, use Fn keys for non-trivial accelerators."

I like your purposed solution so I will look into trying to creat a new key binding for OS X.
msg193079 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2013-07-15 07:51
IIRC the key bindings that are currently used on OSX basicly are partially based on the key bindings on "classic macos", and partially on using the CMD key instead of the ALT key.

It would be nice to have a clean set of key bindings for OSX that's based on the default key bindings for text widgets in Cocoa[1], with "logical" additions for IDLE-specific functionality.

It would also be nice if the key bindings for the various platforms could be kept in sync [2], that makes it easier to switch between platforms and is easier for educators. 

BTW. I don't think it using function keys for key bindings is necessarily a good idea on OSX. I'm pretty sure that the default keyboard settings on OSX require two key presses to use a function key on OSX laptops (the "fn" key and the actual function key) because the keys are used for their hardware control role without the "fn" key (that is, "fn" + "f8" is F8, while just "f8" is "play/pauze"). A number of function keys also have system-wide shortcuts (such as "show desktop"), I'm not sure if those shortcuts are still enabled by default on new installs.


[1] More or less documented here: <https://developer.apple.com/library/mac/#documentation/cocoa/Conceptual/EventOverview/TextDefaultsBindings/TextDefaultsBindings.html>, the file "/System/Library/Frameworks/AppKit.framework/Resources/StandardKeyBinding.dict" is a (binary) plist that contains the default keybinding.

[2] With the obvious differences, such as using the CMD key on OSX and ALT on Windows.
msg193128 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2013-07-15 20:57
I think that those two requirements, i.e. (1) a set of key bindings compatible with standard Cocoa text key bindings and (2) a set of key bindings kept in sync across all IDLE platforms, would be desirable but probably unattainable.  A good next step would be for someone to make a table of the IDLE key bindings across the various keysets and platforms.  That would make it easier to make informed design decisions.

The "Classic Unix" keyset is quite different, with emacs-like multiple key strokes (like Ctrl-X Ctrl-N for New Window).  I wonder how widely it is used. For OS X, we have the aforementioned conflicts with system accelerators and with the Cocoa Tk we have already had to disable some common accelerators (like Cmd-M for Open Module..) because of conflicts with Cocoa Tk's builtin accelerators and the as-yet-unresolved Ctrl-5 and Ctrl-6 crashes (Issue16023).  The X11 situation is a mess with Option and Command being reversed and, yes, there are still users of Python with X11 Tk on OS X (for one, MacPorts provides it as the default option).  Perhaps the best solution for it is a separate OS X X11 keyset.

Re function keys: I created a new user account on a current OS X 10.8 (with a US keyboard on a MacBook Pro).  It seems that function keys are enabled by default.  This is controlled by a checkbox setting in the Keyboard panel of System Preferences.  With the box checked (the default), you have to press the fn modifier key to enable the hardware control functions.  Inspecting the default set of Keyboard Shortcuts in the panel, the only F(n) keys defined are F11, F12, Cmd-F5, Opt-Cmd-F5, and Ctrl-F1 through Ctrl-F7.  This conforms to the current OS X Human Interface Guidelines, Appendix A Keyboard Shortcuts, with the addition that the entire range F8 through F12 are marked as Apple reserved.  (Interestingly, the guidelines do not note that Ctrl-Left and Ctrl-Right are now used by Mission Control by default.)

That said, it would be great if IDLE could more closely follow the OS X Human Interface Guidelines, including the accessibility guidelines for Universal Access.  Of course, IDLE is very much dependent on Tk in these matters.  So trying to improve things will require a fair amount of research and experimentation with the Apple docs, Tk code, and IDLE itself.  It would be a good project for someone interested in practical User Experience design.

Additional references:

https://developer.apple.com/library/mac/#documentation/UserExperience/Conceptual/AppleHIGuidelines/KeyboardShortcuts/KeyboardShortcuts.html

https://developer.apple.com/library/mac/#documentation/Accessibility/Conceptual/AccessibilityMacOSX/OSXAXIntro/OSXAXintro.html

http://www.hcs.harvard.edu/~jrus/Site/System%20Bindings.html
msg193154 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2013-07-16 05:53
> BTW. I don't think it using function keys for key bindings is 
> necessarily a good idea on OSX. I'm pretty sure that the default
> keyboard settings on OSX require two key presses to use a function
> key on OSX laptops

On Mac laptops, there is separate "fn" key that enables the function keys.  Users press "fn" and "F5" to run a script from IDLE.

I teach Python classes to Mac users and they are are no problems at all with the function keys.
msg193155 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2013-07-16 06:04
Raymond: good to hear that using fn+F5 is not a problem for new users
msg296374 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2017-06-19 20:47
I closed #17060 as a duplicate of this.  Roger Serwy there said
 "The .home_callback() in Lib/idlelib/EditorWindow.py contains the logic from #3851 for placing the cursor at the beginning of the prompt, but it requires that a key combination be bound to the beginning-of-line virtual event.

Should we append "<Key-Home> <Control-Key-a>" to the begining-of-line config in Lib/idlelib/config-keys.def ?"
msg370857 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-06-06 22:27
Serhiy add IDLE Modern Unix a couple of years ago.  Something similar is still needed for macOS.
msg395600 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-06-11 04:02
I closed #32761 about new macOS keyset, in favor of this one.  There is a bit more discussion there to consider.  I agree that a chart of <<key-event>> down side and keyset across top would be a good start.
msg395601 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-06-11 04:06
I also closed #21359, which has more comment from Ned about bindings not working.
History
Date User Action Args
2022-04-11 14:57:48adminsetgithub: 62644
2021-06-11 04:06:36terry.reedysetmessages: + msg395601
2021-06-11 04:05:42terry.reedylinkissue21359 superseder
2021-06-11 04:02:57terry.reedysetcomponents: + macOS
2021-06-11 04:02:38terry.reedysetnosy: - Todd.Rovito
title: IDLE: Revise Mac OS X key bindings. -> IDLE: Revise macOS key bindings, make new one.
messages: + msg395600

versions: + Python 3.11, - Python 3.10
2021-06-11 03:58:56terry.reedylinkissue32761 superseder
2020-06-08 00:29:28terry.reedyunlinkissue13504 dependencies
2020-06-06 22:27:04terry.reedysettitle: IDLE: Mac OS X pressing ctrl-A in Python shell moved cursor before the prompt, which then makes the keyboard unresponsive. -> IDLE: Revise Mac OS X key bindings.
messages: + msg370857
versions: + Python 3.10, - Python 3.6, Python 3.7
2017-06-19 20:47:50terry.reedysetversions: + Python 3.6, Python 3.7, - Python 2.7, Python 3.4
2017-06-19 20:47:32terry.reedysetassignee: terry.reedy
type: behavior
messages: + msg296374
stage: test needed
2017-06-19 20:45:59terry.reedylinkissue17060 superseder
2015-09-18 16:33:56markrosemansetnosy: + markroseman
2014-06-20 18:47:21zach.warelinkissue13504 dependencies
2013-07-16 06:04:23ronaldoussorensetmessages: + msg193155
2013-07-16 05:53:39rhettingersetnosy: + rhettinger
messages: + msg193154
2013-07-15 20:57:48ned.deilysetmessages: + msg193128
2013-07-15 07:51:57ronaldoussorensetnosy: + ronaldoussoren
messages: + msg193079
2013-07-14 19:51:29Todd.Rovitosetmessages: + msg193067
2013-07-14 07:30:36ned.deilysetmessages: + msg193036
2013-07-14 07:28:42ned.deilysetnosy: + ned.deily
messages: + msg193035
2013-07-14 04:44:10Todd.Rovitocreate