Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 10c1ecc

Browse filesBrowse files
committed
Help tool.
1 parent 640ecd9 commit 10c1ecc
Copy full SHA for 10c1ecc

File tree

Expand file treeCollapse file tree

13 files changed

+120
-10
lines changed
Filter options
Expand file treeCollapse file tree

13 files changed

+120
-10
lines changed

‎lib/matplotlib/backend_tools.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backend_tools.py
+38-9Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import time
1515
import warnings
1616
from weakref import WeakKeyDictionary
17-
1817
import numpy as np
1918

2019
from matplotlib import rcParams
@@ -403,7 +402,7 @@ def trigger(self, sender, event, data=None):
403402
class ToolEnableAllNavigation(ToolBase):
404403
"""Tool to enable all axes for toolmanager interaction"""
405404

406-
description = 'Enables all axes toolmanager'
405+
description = 'Enable all axes toolmanager'
407406
default_keymap = rcParams['keymap.all_axes']
408407

409408
def trigger(self, sender, event, data=None):
@@ -419,7 +418,7 @@ def trigger(self, sender, event, data=None):
419418
class ToolEnableNavigation(ToolBase):
420419
"""Tool to enable a specific axes for toolmanager interaction"""
421420

422-
description = 'Enables one axes toolmanager'
421+
description = 'Enable one axes toolmanager'
423422
default_keymap = (1, 2, 3, 4, 5, 6, 7, 8, 9)
424423

425424
def trigger(self, sender, event, data=None):
@@ -470,7 +469,7 @@ def _get_uniform_grid_state(ticks):
470469
class ToolGrid(_ToolGridBase):
471470
"""Tool to toggle the major grids of the figure"""
472471

473-
description = 'Toogle major grids'
472+
description = 'Toggle major grids'
474473
default_keymap = rcParams['keymap.grid']
475474

476475
def _get_next_grid_states(self, ax):
@@ -491,7 +490,7 @@ def _get_next_grid_states(self, ax):
491490
class ToolMinorGrid(_ToolGridBase):
492491
"""Tool to toggle the major and minor grids of the figure"""
493492

494-
description = 'Toogle major and minor grids'
493+
description = 'Toggle major and minor grids'
495494
default_keymap = rcParams['keymap.grid_minor']
496495

497496
def _get_next_grid_states(self, ax):
@@ -511,7 +510,7 @@ def _get_next_grid_states(self, ax):
511510
class ToolFullScreen(ToolToggleBase):
512511
"""Tool to toggle full screen"""
513512

514-
description = 'Toogle Fullscreen mode'
513+
description = 'Toggle fullscreen mode'
515514
default_keymap = rcParams['keymap.fullscreen']
516515

517516
def enable(self, event):
@@ -541,7 +540,7 @@ def disable(self, event):
541540
class ToolYScale(AxisScaleBase):
542541
"""Tool to toggle between linear and logarithmic scales on the Y axis"""
543542

544-
description = 'Toogle Scale Y axis'
543+
description = 'Toggle scale Y axis'
545544
default_keymap = rcParams['keymap.yscale']
546545

547546
def set_scale(self, ax, scale):
@@ -551,7 +550,7 @@ def set_scale(self, ax, scale):
551550
class ToolXScale(AxisScaleBase):
552551
"""Tool to toggle between linear and logarithmic scales on the X axis"""
553552

554-
description = 'Toogle Scale X axis'
553+
description = 'Toggle scale X axis'
555554
default_keymap = rcParams['keymap.xscale']
556555

557556
def set_scale(self, ax, scale):
@@ -1020,6 +1019,35 @@ def _mouse_move(self, event):
10201019
self.toolmanager.canvas.draw_idle()
10211020

10221021

1022+
class ToolHelpBase(ToolBase):
1023+
description = 'Print tool list, shortcuts and description'
1024+
default_keymap = rcParams['keymap.help']
1025+
image = 'help.png'
1026+
1027+
def _get_help_text(self):
1028+
entries = []
1029+
for name, tool in sorted(self.toolmanager.tools.items()):
1030+
if not tool.description:
1031+
continue
1032+
entries.append(
1033+
"{}: {}\n\t{}".format(
1034+
name,
1035+
", ".join(self.toolmanager.get_tool_keymap(name)),
1036+
tool.description))
1037+
return "\n".join(entries)
1038+
1039+
def _get_help_html(self):
1040+
fmt = "<tr><td>{}</td><td>{}</td><td>{}</td></tr>"
1041+
rows = [fmt.format("<b>Name</b>", "<b>Keys</b>", "<b>Description</b>")]
1042+
for name, tool in sorted(self.toolmanager.tools.items()):
1043+
if not tool.description:
1044+
continue
1045+
keys = ", ".join(self.toolmanager.get_tool_keymap(name))
1046+
rows.append(fmt.format(name, keys, tool.description))
1047+
return ("<table><thead>" + rows[0] + "</thead>"
1048+
"<tbody>".join(rows[1:]) + "</tbody></table>")
1049+
1050+
10231051
default_tools = {'home': ToolHome, 'back': ToolBack, 'forward': ToolForward,
10241052
'zoom': ToolZoom, 'pan': ToolPan,
10251053
'subplots': 'ToolConfigureSubplots',
@@ -1037,12 +1065,13 @@ def _mouse_move(self, event):
10371065
_views_positions: ToolViewsPositions,
10381066
'cursor': 'ToolSetCursor',
10391067
'rubberband': 'ToolRubberband',
1068+
'help': 'ToolHelp',
10401069
}
10411070
"""Default tools"""
10421071

10431072
default_toolbar_tools = [['navigation', ['home', 'back', 'forward']],
10441073
['zoompan', ['pan', 'zoom', 'subplots']],
1045-
['io', ['save']]]
1074+
['io', ['save', 'help']]]
10461075
"""Default tools in the toolbar"""
10471076

10481077

‎lib/matplotlib/backends/_backend_tk.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/_backend_tk.py
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,10 +963,19 @@ def destroy(self, *args, **kwargs):
963963
self.window = None
964964

965965

966+
class HelpTk(backend_tools.ToolHelpBase):
967+
def trigger(self, *args):
968+
from tkinter.simpledialog import SimpleDialog
969+
dialog = SimpleDialog(
970+
self.figure.canvas._tkcanvas, self._get_help_text(), ["OK"])
971+
dialog.done = lambda num: dialog.frame.master.withdraw()
972+
973+
966974
backend_tools.ToolSaveFigure = SaveFigureTk
967975
backend_tools.ToolConfigureSubplots = ConfigureSubplotsTk
968976
backend_tools.ToolSetCursor = SetCursorTk
969977
backend_tools.ToolRubberband = RubberbandTk
978+
backend_tools.ToolHelp = HelpTk
970979
Toolbar = ToolbarTk
971980

972981

‎lib/matplotlib/backends/backend_gtk3.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_gtk3.py
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,16 @@ def trigger(self, sender, event, data=None):
846846
self.window.present()
847847

848848

849+
class HelpGTK3(backend_tools.ToolHelpBase):
850+
def trigger(self, *args):
851+
dialog = Gtk.MessageDialog(
852+
self._figure.canvas.get_toplevel(),
853+
0, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, self._get_help_text(),
854+
title="Help")
855+
dialog.run()
856+
dialog.destroy()
857+
858+
849859
# Define the file to use as the GTk icon
850860
if sys.platform == 'win32':
851861
icon_filename = 'matplotlib.png'
@@ -877,6 +887,7 @@ def error_msg_gtk(msg, parent=None):
877887
backend_tools.ToolConfigureSubplots = ConfigureSubplotsGTK3
878888
backend_tools.ToolSetCursor = SetCursorGTK3
879889
backend_tools.ToolRubberband = RubberbandGTK3
890+
backend_tools.ToolHelp = HelpGTK3
880891

881892
Toolbar = ToolbarGTK3
882893

‎lib/matplotlib/backends/backend_qt5.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_qt5.py
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,10 +1064,16 @@ def remove_rubberband(self):
10641064
self.canvas.drawRectangle(None)
10651065

10661066

1067+
class HelpQt(backend_tools.ToolHelpBase):
1068+
def trigger(self, *args):
1069+
QtWidgets.QMessageBox.information(None, "Help", self._get_help_html())
1070+
1071+
10671072
backend_tools.ToolSaveFigure = SaveFigureQt
10681073
backend_tools.ToolConfigureSubplots = ConfigureSubplotsQt
10691074
backend_tools.ToolSetCursor = SetCursorQt
10701075
backend_tools.ToolRubberband = RubberbandQt
1076+
backend_tools.ToolHelp = HelpQt
10711077

10721078

10731079
def error_msg_qt(msg, parent=None):
1.77 KB
Binary file not shown.
472 Bytes
Loading
1.7 KB
Binary file not shown.
+52Lines changed: 52 additions & 0 deletions
Loading
747 Bytes
Loading
6.76 KB
Binary file not shown.

‎lib/matplotlib/rcsetup.py

Copy file name to clipboardExpand all lines: lib/matplotlib/rcsetup.py
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,6 +1420,7 @@ def _validate_linestyle(ls):
14201420
'keymap.yscale': [['l'], validate_stringlist],
14211421
'keymap.xscale': [['k', 'L'], validate_stringlist],
14221422
'keymap.all_axes': [['a'], validate_stringlist],
1423+
'keymap.help': [['f1'], validate_stringlist],
14231424

14241425
# sample data
14251426
'examples.directory': ['', validate_string],

‎matplotlibrc.template

Copy file name to clipboardExpand all lines: matplotlibrc.template
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ backend : $TEMPLATE_BACKEND
583583
#keymap.pan : p ## pan mnemonic
584584
#keymap.zoom : o ## zoom mnemonic
585585
#keymap.save : s, ctrl+s ## saving current figure
586+
#keymap.help : f1 ## display help about active tools
586587
#keymap.quit : ctrl+w, cmd+w, q ## close the current figure
587588
#keymap.quit_all : W, cmd+W, Q ## close all figures
588589
#keymap.grid : g ## switching on/off major grids in current axes

‎tools/make_icons.py

Copy file name to clipboardExpand all lines: tools/make_icons.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ def make_matplotlib_icon():
9797
('move', 0xf047),
9898
('filesave', 0xf0c7),
9999
('subplots', 0xf1de),
100-
('qt4_editor_options', 0xf201)]
100+
('qt4_editor_options', 0xf201),
101+
('help', 0xf128)]
101102

102103

103104
def make_icons():

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.