MCPcopy Index your code
hub / github.com/python/cpython / get_accelerator

Function get_accelerator

Lib/idlelib/editor.py:1645–1685  ·  view source on GitHub ↗

Return a formatted string for the keybinding of an event. Convert the first keybinding for a given event to a form that can be displayed as an accelerator on the menu. Args: keydefs: Dictionary of valid events to keybindings. eventname: Event to retrieve keybinding for.

(keydefs, eventname)

Source from the content-addressed store, hash-verified

1643}
1644
1645def get_accelerator(keydefs, eventname):
1646 """Return a formatted string for the keybinding of an event.
1647
1648 Convert the first keybinding for a given event to a form that
1649 can be displayed as an accelerator on the menu.
1650
1651 Args:
1652 keydefs: Dictionary of valid events to keybindings.
1653 eventname: Event to retrieve keybinding for.
1654
1655 Returns:
1656 Formatted string of the keybinding.
1657 """
1658 keylist = keydefs.get(eventname)
1659 # issue10940: temporary workaround to prevent hang with OS X Cocoa Tk 8.5
1660 # if not keylist:
1661 if (not keylist) or (macosx.isCocoaTk() and eventname in {
1662 "<<open-module>>",
1663 "<<goto-line>>",
1664 "<<change-indentwidth>>"}):
1665 return ""
1666 s = keylist[0]
1667 # Convert strings of the form -singlelowercase to -singleuppercase.
1668 s = re.sub(r"-[a-z]\b", lambda m: m.group().upper(), s)
1669 # Convert certain keynames to their symbol.
1670 s = re.sub(r"\b\w+\b", lambda m: keynames.get(m.group(), m.group()), s)
1671 # Remove Key- from string.
1672 s = re.sub("Key-", "", s)
1673 # Convert Cancel to Ctrl-Break.
1674 s = re.sub("Cancel", "Ctrl-Break", s) # dscherer@cmu.edu
1675 # Convert Control to Ctrl-.
1676 s = re.sub("Control-", "Ctrl-", s)
1677 # Change - to +.
1678 s = re.sub("-", "+", s)
1679 # Change >< to space.
1680 s = re.sub("><", " ", s)
1681 # Remove <.
1682 s = re.sub("<", "", s)
1683 # Remove >.
1684 s = re.sub(">", "", s)
1685 return s
1686
1687
1688def fixwordbreaks(root):

Callers 2

ApplyKeybindingsMethod · 0.85
fill_menusMethod · 0.85

Calls 4

getMethod · 0.45
subMethod · 0.45
upperMethod · 0.45
groupMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…