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,42 @@ 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+ def _format_tool_keymap (self , name ):
1030+ 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 )
1036+
1037+ def _get_help_text (self ):
1038+ entries = []
1039+ for name , tool in sorted (self .toolmanager .tools .items ()):
1040+ if not tool .description :
1041+ continue
1042+ entries .append (
1043+ "{}: {}\n \t {}" .format (
1044+ name , self ._format_tool_keymap (name ), tool .description ))
1045+ return "\n " .join (entries )
1046+
1047+ def _get_help_html (self ):
1048+ fmt = "<tr><td>{}</td><td>{}</td><td>{}</td></tr>"
1049+ rows = [fmt .format (
1050+ "<b>Action</b>" , "<b>Shortcuts</b>" , "<b>Description</b>" )]
1051+ for name , tool in sorted (self .toolmanager .tools .items ()):
1052+ if not tool .description :
1053+ continue
1054+ rows .append (fmt .format (
1055+ name , self ._format_tool_keymap (name ), tool .description ))
1056+ return ("<table><thead>" + rows [0 ] + "</thead>"
1057+ "<tbody>" .join (rows [1 :]) + "</tbody></table>" )
1058+
1059+
10231060default_tools = {'home' : ToolHome , 'back' : ToolBack , 'forward' : ToolForward ,
10241061 'zoom' : ToolZoom , 'pan' : ToolPan ,
10251062 'subplots' : 'ToolConfigureSubplots' ,
@@ -1037,12 +1074,13 @@ def _mouse_move(self, event):
10371074 _views_positions : ToolViewsPositions ,
10381075 'cursor' : 'ToolSetCursor' ,
10391076 'rubberband' : 'ToolRubberband' ,
1077+ 'help' : 'ToolHelp' ,
10401078 }
10411079"""Default tools"""
10421080
10431081default_toolbar_tools = [['navigation' , ['home' , 'back' , 'forward' ]],
10441082 ['zoompan' , ['pan' , 'zoom' , 'subplots' ]],
1045- ['io' , ['save' ]]]
1083+ ['io' , ['save' , 'help' ]]]
10461084"""Default tools in the toolbar"""
10471085
10481086
0 commit comments