1111 `matplotlib.backend_managers.ToolManager`
1212"""
1313
14+ import re
1415import time
1516import warnings
1617from weakref import WeakKeyDictionary
@@ -403,7 +404,7 @@ def trigger(self, sender, event, data=None):
403404class ToolEnableAllNavigation (ToolBase ):
404405 """Tool to enable all axes for toolmanager interaction"""
405406
406- description = 'Enables all axes toolmanager'
407+ description = 'Enable all axes toolmanager'
407408 default_keymap = rcParams ['keymap.all_axes' ]
408409
409410 def trigger (self , sender , event , data = None ):
@@ -419,7 +420,7 @@ def trigger(self, sender, event, data=None):
419420class ToolEnableNavigation (ToolBase ):
420421 """Tool to enable a specific axes for toolmanager interaction"""
421422
422- description = 'Enables one axes toolmanager'
423+ description = 'Enable one axes toolmanager'
423424 default_keymap = (1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 )
424425
425426 def trigger (self , sender , event , data = None ):
@@ -470,7 +471,7 @@ def _get_uniform_grid_state(ticks):
470471class ToolGrid (_ToolGridBase ):
471472 """Tool to toggle the major grids of the figure"""
472473
473- description = 'Toogle major grids'
474+ description = 'Toggle major grids'
474475 default_keymap = rcParams ['keymap.grid' ]
475476
476477 def _get_next_grid_states (self , ax ):
@@ -491,7 +492,7 @@ def _get_next_grid_states(self, ax):
491492class ToolMinorGrid (_ToolGridBase ):
492493 """Tool to toggle the major and minor grids of the figure"""
493494
494- description = 'Toogle major and minor grids'
495+ description = 'Toggle major and minor grids'
495496 default_keymap = rcParams ['keymap.grid_minor' ]
496497
497498 def _get_next_grid_states (self , ax ):
@@ -511,7 +512,7 @@ def _get_next_grid_states(self, ax):
511512class ToolFullScreen (ToolToggleBase ):
512513 """Tool to toggle full screen"""
513514
514- description = 'Toogle Fullscreen mode'
515+ description = 'Toggle fullscreen mode'
515516 default_keymap = rcParams ['keymap.fullscreen' ]
516517
517518 def enable (self , event ):
@@ -541,7 +542,7 @@ def disable(self, event):
541542class ToolYScale (AxisScaleBase ):
542543 """Tool to toggle between linear and logarithmic scales on the Y axis"""
543544
544- description = 'Toogle Scale Y axis'
545+ description = 'Toggle scale Y axis'
545546 default_keymap = rcParams ['keymap.yscale' ]
546547
547548 def set_scale (self , ax , scale ):
@@ -551,7 +552,7 @@ def set_scale(self, ax, scale):
551552class ToolXScale (AxisScaleBase ):
552553 """Tool to toggle between linear and logarithmic scales on the X axis"""
553554
554- description = 'Toogle Scale X axis'
555+ description = 'Toggle scale X axis'
555556 default_keymap = rcParams ['keymap.xscale' ]
556557
557558 def set_scale (self , ax , scale ):
@@ -1020,6 +1021,48 @@ def _mouse_move(self, event):
10201021 self .toolmanager .canvas .draw_idle ()
10211022
10221023
1024+ class ToolHelpBase (ToolBase ):
1025+ description = 'Print tool list, shortcuts and description'
1026+ default_keymap = rcParams ['keymap.help' ]
1027+ image = 'help.png'
1028+
1029+ @staticmethod
1030+ def format_shortcut (key_sequence ):
1031+ """
1032+ Converts a shortcut string from the notation used in rc config to the
1033+ standard notation for displaying shortcuts, e.g. 'ctrl+a' -> 'Ctrl+A'.
1034+ """
1035+ return (key_sequence if len (key_sequence ) == 1 else
1036+ re .sub (r"\+[A-Z]" , r"+Shift\g<0>" , key_sequence ).title ())
1037+
1038+ def _format_tool_keymap (self , name ):
1039+ keymaps = self .toolmanager .get_tool_keymap (name )
1040+ return ", " .join (self .format_shortcut (keymap ) for keymap in keymaps )
1041+
1042+ def _get_help_text (self ):
1043+ entries = []
1044+ for name , tool in sorted (self .toolmanager .tools .items ()):
1045+ if not tool .description :
1046+ continue
1047+ entries .append (
1048+ "{}: {}\n \t {}" .format (
1049+ name , self ._format_tool_keymap (name ), tool .description ))
1050+ return "\n " .join (entries )
1051+
1052+ def _get_help_html (self ):
1053+ fmt = "<tr><td>{}</td><td>{}</td><td>{}</td></tr>"
1054+ rows = [fmt .format (
1055+ "<b>Action</b>" , "<b>Shortcuts</b>" , "<b>Description</b>" )]
1056+ for name , tool in sorted (self .toolmanager .tools .items ()):
1057+ if not tool .description :
1058+ continue
1059+ rows .append (fmt .format (
1060+ name , self ._format_tool_keymap (name ), tool .description ))
1061+ return ("<style>td {padding: 0px 4px}</style>"
1062+ "<table><thead>" + rows [0 ] + "</thead>"
1063+ "<tbody>" .join (rows [1 :]) + "</tbody></table>" )
1064+
1065+
10231066default_tools = {'home' : ToolHome , 'back' : ToolBack , 'forward' : ToolForward ,
10241067 'zoom' : ToolZoom , 'pan' : ToolPan ,
10251068 'subplots' : 'ToolConfigureSubplots' ,
@@ -1037,12 +1080,13 @@ def _mouse_move(self, event):
10371080 _views_positions : ToolViewsPositions ,
10381081 'cursor' : 'ToolSetCursor' ,
10391082 'rubberband' : 'ToolRubberband' ,
1083+ 'help' : 'ToolHelp' ,
10401084 }
10411085"""Default tools"""
10421086
10431087default_toolbar_tools = [['navigation' , ['home' , 'back' , 'forward' ]],
10441088 ['zoompan' , ['pan' , 'zoom' , 'subplots' ]],
1045- ['io' , ['save' ]]]
1089+ ['io' , ['save' , 'help' ]]]
10461090"""Default tools in the toolbar"""
10471091
10481092
0 commit comments