@@ -1026,13 +1026,24 @@ class ToolHelpBase(ToolBase):
10261026 default_keymap = rcParams ['keymap.help' ]
10271027 image = 'help.png'
10281028
1029+
1030+ @staticmethod
1031+ def format_shortcut (keysequence ):
1032+ """
1033+ Converts a shortcut string from the notation used in rc config to the
1034+ standard notation for displaying shortcuts, e.g. 'ctrl+a' -> 'Ctrl+A'.
1035+ """
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 )
1043+
10291044 def _format_tool_keymap (self , name ):
10301045 keymaps = self .toolmanager .get_tool_keymap (name )
1031- # Capitalize "ctrl+a" -> "Ctrl+A" but leave "a" as is.
1032- return ", " .join (re .sub (r"\w{2,}|(?<=\+)\w" ,
1033- lambda m : m .group (0 ).capitalize (),
1034- keymap )
1035- for keymap in keymaps )
1046+ return ", " .join (self .format_shortcut (keymap ) for keymap in keymaps )
10361047
10371048 def _get_help_text (self ):
10381049 entries = []
@@ -1053,7 +1064,8 @@ def _get_help_html(self):
10531064 continue
10541065 rows .append (fmt .format (
10551066 name , self ._format_tool_keymap (name ), tool .description ))
1056- return ("<table><thead>" + rows [0 ] + "</thead>"
1067+ return ("<style>td {padding: 0px 4px}</style>"
1068+ "<table><thead>" + rows [0 ] + "</thead>"
10571069 "<tbody>" .join (rows [1 :]) + "</tbody></table>" )
10581070
10591071
0 commit comments