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)
| 1643 | } |
| 1644 | |
| 1645 | def 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 | |
| 1688 | def fixwordbreaks(root): |
no test coverage detected
searching dependent graphs…