Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 59cb786

Browse files
committed
Simpler format_shortcut.
1 parent afbbdd6 commit 59cb786

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

lib/matplotlib/backend_tools.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,20 +1026,14 @@ class ToolHelpBase(ToolBase):
10261026
default_keymap = rcParams['keymap.help']
10271027
image = 'help.png'
10281028

1029-
10301029
@staticmethod
1031-
def format_shortcut(keysequence):
1030+
def format_shortcut(key_sequence):
10321031
"""
10331032
Converts a shortcut string from the notation used in rc config to the
10341033
standard notation for displaying shortcuts, e.g. 'ctrl+a' -> 'Ctrl+A'.
10351034
"""
1036-
def repl(match):
1037-
s = match.group(0)
1038-
return 'Shift+' + s if len(
1039-
s) == 1 and s.isupper() else s.capitalize()
1040-
if len(keysequence) == 1:
1041-
return keysequence # do not modify single characters
1042-
return re.sub(r"\w{2,}|(?<=\+)\w", repl, keysequence)
1035+
return (key_sequence if len(key_sequence) == 1 else
1036+
re.sub(r"\+[A-Z]", r"+Shift\g<0>", key_sequence).title())
10431037

10441038
def _format_tool_keymap(self, name):
10451039
keymaps = self.toolmanager.get_tool_keymap(name)

lib/matplotlib/tests/test_backend_tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
('cmd+1', 'Cmd+1'),
1818
])
1919
def test_format_shortcut(rc_shortcut, expected):
20-
assert ToolHelpBase.format_shortcut(rc_shortcut) == expected
20+
assert ToolHelpBase.format_shortcut(rc_shortcut) == expected

0 commit comments

Comments
 (0)