Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Help tool.#11045
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Help tool.#11045
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -11,6 +11,7 @@ | ||
`matplotlib.backend_managers.ToolManager` | ||
""" | ||
import re | ||
import time | ||
import warnings | ||
from weakref import WeakKeyDictionary | ||
@@ -403,7 +404,7 @@ def trigger(self, sender, event, data=None): | ||
class ToolEnableAllNavigation(ToolBase): | ||
"""Tool to enable all axes for toolmanager interaction""" | ||
description = 'Enable all axes toolmanager' | ||
default_keymap = rcParams['keymap.all_axes'] | ||
def trigger(self, sender, event, data=None): | ||
@@ -419,7 +420,7 @@ def trigger(self, sender, event, data=None): | ||
class ToolEnableNavigation(ToolBase): | ||
"""Tool to enable a specific axes for toolmanager interaction""" | ||
description = 'Enable one axes toolmanager' | ||
default_keymap = (1, 2, 3, 4, 5, 6, 7, 8, 9) | ||
def trigger(self, sender, event, data=None): | ||
@@ -470,7 +471,7 @@ def _get_uniform_grid_state(ticks): | ||
class ToolGrid(_ToolGridBase): | ||
"""Tool to toggle the major grids of the figure""" | ||
description = 'Toggle major grids' | ||
default_keymap = rcParams['keymap.grid'] | ||
def _get_next_grid_states(self, ax): | ||
@@ -491,7 +492,7 @@ def _get_next_grid_states(self, ax): | ||
class ToolMinorGrid(_ToolGridBase): | ||
"""Tool to toggle the major and minor grids of the figure""" | ||
description = 'Toggle major and minor grids' | ||
default_keymap = rcParams['keymap.grid_minor'] | ||
def _get_next_grid_states(self, ax): | ||
@@ -511,7 +512,7 @@ def _get_next_grid_states(self, ax): | ||
class ToolFullScreen(ToolToggleBase): | ||
"""Tool to toggle full screen""" | ||
description = 'Toggle fullscreen mode' | ||
default_keymap = rcParams['keymap.fullscreen'] | ||
def enable(self, event): | ||
@@ -541,7 +542,7 @@ def disable(self, event): | ||
class ToolYScale(AxisScaleBase): | ||
"""Tool to toggle between linear and logarithmic scales on the Y axis""" | ||
description = 'Toggle scale Y axis' | ||
default_keymap = rcParams['keymap.yscale'] | ||
def set_scale(self, ax, scale): | ||
@@ -551,7 +552,7 @@ def set_scale(self, ax, scale): | ||
class ToolXScale(AxisScaleBase): | ||
"""Tool to toggle between linear and logarithmic scales on the X axis""" | ||
description = 'Toggle scale X axis' | ||
default_keymap = rcParams['keymap.xscale'] | ||
def set_scale(self, ax, scale): | ||
@@ -1020,6 +1021,48 @@ def _mouse_move(self, event): | ||
self.toolmanager.canvas.draw_idle() | ||
class ToolHelpBase(ToolBase): | ||
description = 'Print tool list, shortcuts and description' | ||
default_keymap = rcParams['keymap.help'] | ||
image = 'help.png' | ||
@staticmethod | ||
def format_shortcut(key_sequence): | ||
""" | ||
Converts a shortcut string from the notation used in rc config to the | ||
standard notation for displaying shortcuts, e.g. 'ctrl+a' -> 'Ctrl+A'. | ||
""" | ||
return (key_sequence if len(key_sequence) == 1 else | ||
re.sub(r"\+[A-Z]", r"+Shift\g<0>", key_sequence).title()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. This doesn't add Shift for single letter shortcuts like 'L' for xscale; is that on purpose? Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Good question. I've been implicitly assuming that we keep the case sensitivity for single letters, i.e.
Now thinking about it, this is probably what we want to do. Otherwise, we'd have
This could be slightly misleading, because "L" really means only typing the L-Key, which in a text field would result in a lowercase "l". An alternative way out (similar to what the GtkShortcutWindow is doing) would be to enclose the keys.
Im +0.3 for sticking with the present solution. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. vim just uses lowercase for lowercase and uppercase for uppercase (http://vimdoc.sourceforge.net/htmldoc/editing.html#CTRL-^), which seems just fine to me. ctrl+x are always documented as CTRL-X (UPPERCASE), but there are no shortcuts of the form ctrl+shift+x due to internal constraints. | ||
def _format_tool_keymap(self, name): | ||
keymaps = self.toolmanager.get_tool_keymap(name) | ||
return ", ".join(self.format_shortcut(keymap) for keymap in keymaps) | ||
def _get_help_text(self): | ||
entries = [] | ||
for name, tool in sorted(self.toolmanager.tools.items()): | ||
if not tool.description: | ||
continue | ||
entries.append( | ||
"{}: {}\n\t{}".format( | ||
name, self._format_tool_keymap(name), tool.description)) | ||
return "\n".join(entries) | ||
def _get_help_html(self): | ||
fmt = "<tr><td>{}</td><td>{}</td><td>{}</td></tr>" | ||
rows = [fmt.format( | ||
"<b>Action</b>", "<b>Shortcuts</b>", "<b>Description</b>")] | ||
for name, tool in sorted(self.toolmanager.tools.items()): | ||
if not tool.description: | ||
continue | ||
rows.append(fmt.format( | ||
name, self._format_tool_keymap(name), tool.description)) | ||
return ("<style>td {padding: 0px 4px}</style>" | ||
"<table><thead>" + rows[0] + "</thead>" | ||
"<tbody>".join(rows[1:]) + "</tbody></table>") | ||
default_tools = {'home': ToolHome, 'back': ToolBack, 'forward': ToolForward, | ||
'zoom': ToolZoom, 'pan': ToolPan, | ||
'subplots': 'ToolConfigureSubplots', | ||
@@ -1037,12 +1080,13 @@ def _mouse_move(self, event): | ||
_views_positions: ToolViewsPositions, | ||
'cursor': 'ToolSetCursor', | ||
'rubberband': 'ToolRubberband', | ||
'help': 'ToolHelp', | ||
} | ||
"""Default tools""" | ||
default_toolbar_tools = [['navigation', ['home', 'back', 'forward']], | ||
['zoompan', ['pan', 'zoom', 'subplots']], | ||
['io', ['save', 'help']]] | ||
"""Default tools in the toolbar""" | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import pytest | ||
from matplotlib.backend_tools import ToolHelpBase | ||
@pytest.mark.parametrize('rc_shortcut,expected', [ | ||
('home', 'Home'), | ||
('backspace', 'Backspace'), | ||
('f1', 'F1'), | ||
('ctrl+a', 'Ctrl+A'), | ||
('ctrl+A', 'Ctrl+Shift+A'), | ||
('a', 'a'), | ||
('A', 'A'), | ||
('ctrl+shift+f1', 'Ctrl+Shift+F1'), | ||
('1', '1'), | ||
('cmd+p', 'Cmd+P'), | ||
('cmd+1', 'Cmd+1'), | ||
]) | ||
def test_format_shortcut(rc_shortcut, expected): | ||
assert ToolHelpBase.format_shortcut(rc_shortcut) == expected |