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

Skip to content

Commit 8176f20

Browse files
committed
Simpler format_shortcut.
1 parent afbbdd6 commit 8176f20

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
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)

0 commit comments

Comments
 (0)