11
11
`matplotlib.backend_managers.ToolManager`
12
12
"""
13
13
14
+ import re
14
15
import time
15
16
import warnings
16
17
from weakref import WeakKeyDictionary
@@ -403,7 +404,7 @@ def trigger(self, sender, event, data=None):
403
404
class ToolEnableAllNavigation (ToolBase ):
404
405
"""Tool to enable all axes for toolmanager interaction"""
405
406
406
- description = 'Enables all axes toolmanager'
407
+ description = 'Enable all axes toolmanager'
407
408
default_keymap = rcParams ['keymap.all_axes' ]
408
409
409
410
def trigger (self , sender , event , data = None ):
@@ -419,7 +420,7 @@ def trigger(self, sender, event, data=None):
419
420
class ToolEnableNavigation (ToolBase ):
420
421
"""Tool to enable a specific axes for toolmanager interaction"""
421
422
422
- description = 'Enables one axes toolmanager'
423
+ description = 'Enable one axes toolmanager'
423
424
default_keymap = (1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 )
424
425
425
426
def trigger (self , sender , event , data = None ):
@@ -470,7 +471,7 @@ def _get_uniform_grid_state(ticks):
470
471
class ToolGrid (_ToolGridBase ):
471
472
"""Tool to toggle the major grids of the figure"""
472
473
473
- description = 'Toogle major grids'
474
+ description = 'Toggle major grids'
474
475
default_keymap = rcParams ['keymap.grid' ]
475
476
476
477
def _get_next_grid_states (self , ax ):
@@ -491,7 +492,7 @@ def _get_next_grid_states(self, ax):
491
492
class ToolMinorGrid (_ToolGridBase ):
492
493
"""Tool to toggle the major and minor grids of the figure"""
493
494
494
- description = 'Toogle major and minor grids'
495
+ description = 'Toggle major and minor grids'
495
496
default_keymap = rcParams ['keymap.grid_minor' ]
496
497
497
498
def _get_next_grid_states (self , ax ):
@@ -511,7 +512,7 @@ def _get_next_grid_states(self, ax):
511
512
class ToolFullScreen (ToolToggleBase ):
512
513
"""Tool to toggle full screen"""
513
514
514
- description = 'Toogle Fullscreen mode'
515
+ description = 'Toggle fullscreen mode'
515
516
default_keymap = rcParams ['keymap.fullscreen' ]
516
517
517
518
def enable (self , event ):
@@ -541,7 +542,7 @@ def disable(self, event):
541
542
class ToolYScale (AxisScaleBase ):
542
543
"""Tool to toggle between linear and logarithmic scales on the Y axis"""
543
544
544
- description = 'Toogle Scale Y axis'
545
+ description = 'Toggle scale Y axis'
545
546
default_keymap = rcParams ['keymap.yscale' ]
546
547
547
548
def set_scale (self , ax , scale ):
@@ -551,7 +552,7 @@ def set_scale(self, ax, scale):
551
552
class ToolXScale (AxisScaleBase ):
552
553
"""Tool to toggle between linear and logarithmic scales on the X axis"""
553
554
554
- description = 'Toogle Scale X axis'
555
+ description = 'Toggle scale X axis'
555
556
default_keymap = rcParams ['keymap.xscale' ]
556
557
557
558
def set_scale (self , ax , scale ):
@@ -1020,6 +1021,42 @@ def _mouse_move(self, event):
1020
1021
self .toolmanager .canvas .draw_idle ()
1021
1022
1022
1023
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
+
1023
1060
default_tools = {'home' : ToolHome , 'back' : ToolBack , 'forward' : ToolForward ,
1024
1061
'zoom' : ToolZoom , 'pan' : ToolPan ,
1025
1062
'subplots' : 'ToolConfigureSubplots' ,
@@ -1037,12 +1074,13 @@ def _mouse_move(self, event):
1037
1074
_views_positions : ToolViewsPositions ,
1038
1075
'cursor' : 'ToolSetCursor' ,
1039
1076
'rubberband' : 'ToolRubberband' ,
1077
+ 'help' : 'ToolHelp' ,
1040
1078
}
1041
1079
"""Default tools"""
1042
1080
1043
1081
default_toolbar_tools = [['navigation' , ['home' , 'back' , 'forward' ]],
1044
1082
['zoompan' , ['pan' , 'zoom' , 'subplots' ]],
1045
- ['io' , ['save' ]]]
1083
+ ['io' , ['save' , 'help' ]]]
1046
1084
"""Default tools in the toolbar"""
1047
1085
1048
1086
0 commit comments