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 dda9144

Browse filesBrowse files
authored
Merge pull request #11045 from anntzer/helptool
Help tool.
2 parents 2d41a8d + 59cb786 commit dda9144
Copy full SHA for dda9144

File tree

Expand file treeCollapse file tree

14 files changed

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

14 files changed

+155
-10
lines changed

‎lib/matplotlib/backend_tools.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backend_tools.py
+52-8Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
`matplotlib.backend_managers.ToolManager`
1212
"""
1313

14+
import re
1415
import time
1516
import warnings
1617
from weakref import WeakKeyDictionary
@@ -403,7 +404,7 @@ def trigger(self, sender, event, data=None):
403404
class 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):
419420
class 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):
470471
class 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):
491492
class 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):
511512
class 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):
541542
class 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):
551552
class 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+
10231066
default_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

10431087
default_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

‎lib/matplotlib/backends/_backend_tk.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/_backend_tk.py
+10-1Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import six
2-
from six.moves import tkinter as Tk
32

43
import math
54
import logging
65
import os.path
76
import sys
7+
import tkinter as Tk
8+
from tkinter.simpledialog import SimpleDialog
89

910
import numpy as np
1011

@@ -963,10 +964,18 @@ def destroy(self, *args, **kwargs):
963964
self.window = None
964965

965966

967+
class HelpTk(backend_tools.ToolHelpBase):
968+
def trigger(self, *args):
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],
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import pytest
2+
3+
from matplotlib.backend_tools import ToolHelpBase
4+
5+
6+
@pytest.mark.parametrize('rc_shortcut,expected', [
7+
('home', 'Home'),
8+
('backspace', 'Backspace'),
9+
('f1', 'F1'),
10+
('ctrl+a', 'Ctrl+A'),
11+
('ctrl+A', 'Ctrl+Shift+A'),
12+
('a', 'a'),
13+
('A', 'A'),
14+
('ctrl+shift+f1', 'Ctrl+Shift+F1'),
15+
('1', '1'),
16+
('cmd+p', 'Cmd+P'),
17+
('cmd+1', 'Cmd+1'),
18+
])
19+
def test_format_shortcut(rc_shortcut, expected):
20+
assert ToolHelpBase.format_shortcut(rc_shortcut) == expected

‎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.