8000 tacaswell comments aprl 1 · matplotlib/matplotlib@e8cd5d5 · GitHub
[go: up one dir, main page]

Skip to content

Commit e8cd5d5

Browse files
committed
tacaswell comments aprl 1
1 parent 64f947f commit e8cd5d5

File tree

3 files changed

+52
-40
lines changed

3 files changed

+52
-40
lines changed

examples/user_interfaces/navigation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class allows to:
1818
class ListTools(ToolBase):
1919
'''List all the tools controlled by `Navigation`'''
2020
# keyboard shortcut
21-
keymap = 'm'
21+
default_keymap = 'm'
2222
description = 'List Tools'
2323

2424
def trigger(self, *args, **kwargs):
@@ -46,7 +46,7 @@ def trigger(self, *args, **kwargs):
4646
# ref: at https://github.com/matplotlib/matplotlib/issues/1987
4747
class CopyToolGTK3(ToolBase):
4848
'''Copy canvas to clipboard'''
49-
keymap = 'ctrl+c'
49+
default_keymap = 'ctrl+c'
5050
description = 'Copy canvas'
5151

5252
def trigger(self, *args, **kwargs):

lib/matplotlib/backend_bases.py

Lines changed: 36 additions & 24 deletions
< 8000 /tr>
Original file line numberDiff line numberDiff line change
@@ -2586,6 +2586,8 @@ def __init__(self, canvas, num):
25862586
self.key_press_handler_id = self.canvas.mpl_connect(
25872587
'key_press_event',
25882588
self.key_press)
2589+
else:
2590+
self.key_press_handler_id = None
25892591
"""
25902592
The returned id from connecting the default key handler via
25912593
:meth:`FigureCanvasBase.mpl_connnect`.
@@ -3331,11 +3333,7 @@ def message_event(self, message, sender=None):
33313333

33323334
@property
33333335
def active_toggle(self):
3334-
"""
3335-
Toggled Tool
3336-
3337-
**dict** : Currently toggled tools
3338-
"""
3336+
"""Currently toggled tools"""
33393337

33403338
return self._toggled
33413339

@@ -3360,7 +3358,7 @@ def _remove_keys(self, name):
33603358
for k in self.get_tool_keymap(name):
33613359
del self._keys[k]
33623360

3363-
def set_tool_keymap(self, name, *keys):
3361+
def update_keymap(self, name, *keys):
33643362
"""
33653363
Set the keymap to associate with the specified tool
33663364
@@ -3449,30 +3447,31 @@ def add_tool(self, name, tool, *args, **kwargs):
34493447
"""
34503448

34513449
tool_cls = self._get_cls_to_instantiate(tool)
3452-
if tool_cls is False:
3450+
if not tool_cls:
34533451
raise ValueError('Impossible to find class for %s' % str(tool))
34543452

34553453
if name in self._tools:
34563454
warnings.warn('A "Tool class" with the same name already exists, '
34573455
'not added')
34583456
return self._tools[name]
34593457

3460-
self._tools[name] = tool_cls(self, name, *args, **kwargs)
3458+
tool_obj = tool_cls(self, name, *args, **kwargs)
3459+
self._tools[name] = tool_obj
34613460

3462-
if tool_cls.keymap is not None:
3463-
self.set_tool_keymap(name, tool_cls.keymap)
3461+
if tool_cls.default_keymap is not None:
3462+
self.update_keymap(name, tool_cls.default_keymap)
34643463

34653464
# For toggle tools init the radio_group in self._toggled
3466-
if isinstance(self._tools[name], tools.ToolToggleBase):
3465+
if isinstance(tool_obj, tools.ToolToggleBase):
34673466
# None group is not mutually exclusive, a set is used to keep track
34683467
# of all toggled tools in this group
3469-
if tool_cls.radio_group is None:
3468+
if tool_obj.radio_group is None:
34703469
self._toggled.setdefault(None, set())
34713470
else:
3472-
self._toggled.setdefault(tool_cls.radio_group, None)
3471+
self._toggled.setdefault(tool_obj.radio_group, None)
34733472

3474-
self._tool_added_event(self._tools[name])
3475-
return self._tools[name]
3473+
self._tool_added_event(tool_obj)
3474+
return tool_obj
34763475

34773476
def _tool_added_event(self, tool):
34783477
s = 'tool_added_event'
@@ -3483,6 +3482,16 @@ def _handle_toggle(self, tool, sender, canvasevent, data):
34833482
"""
34843483
Toggle tools, need to untoggle prior to using other Toggle tool
34853484
Called from tool_trigger_event
3485+
3486+
Parameters
3487+
----------
3488+
tool: Tool object
3489+
sender: object
3490+
Object that wishes to trigger the tool
3491+
canvasevent : Event
3492+
Original Canvas event or None
3493+
data : Object
3494+
Extra data to pass to the tool when triggering
34863495
"""
34873496

34883497
radio_group = tool.radio_group
@@ -3500,7 +3509,7 @@ def _handle_toggle(self, tool, sender, canvasevent, data):
35003509
toggled = None
35013510
# If no tool was toggled in the radio_group
35023511
# toggle it
3503-
elif self._toggled.get(radio_group, None) is None:
3512+
elif self._toggled[radio_group] is None:
35043513
toggled = tool.name
35053514
# Other tool in the radio_group is toggled
35063515
else:
@@ -3521,15 +3530,18 @@ def _get_cls_to_instantiate(self, callback_class):
35213530
if isinstance(callback_class, six.string_types):
35223531
# FIXME: make more complete searching structure
35233532
if callback_class in globals():
3524-
return globals()[callback_class]
3525-
3526-
mod = self.__class__.__module__
3527-
current_module = __import__(mod,
3528-
globals(), locals(), [mod], 0)
3533+
callback_class = globals()[callback_class]
3534+
else:
3535+
mod = self.__class__.__module__
3536+
current_module = __import__(mod,
3537+
globals(), locals(), [mod], 0)
35293538

3530-
return getattr(current_module, callback_class, False)
3539+
callback_class = getattr(current_module, callback_class, False)
35313540

3532-
return callback_class
3541+
if callable(callback_class):
3542+
return callback_class
3543+
else:
3544+
return None
35333545

35343546
def tool_trigger_event(self, name, sender=None, canvasevent=None,
35353547
data=None):
@@ -3598,7 +3610,7 @@ def get_tool(self, name, warn=True):
35983610
-----------
35993611
name : str, ToolBase
36003612
Name of the tool, or the tool itself
3601-
warn : bool
3613+
warn : bool, optional
36023614
If this method should give warnings.
36033615
"""
36043616
if isinstance(name, tools.ToolBase) and name.name in self._tools:

lib/matplotlib/backend_tools.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class ToolBase(object):
4545
Navigation
4646
"""
4747

48-
keymap = None
48+
default_keymap = None
4949
"""
5050
Keymap to associate with this tool
5151
@@ -311,7 +311,7 @@ class ToolQuit(ToolBase):
311311
"""Tool to call the figure manager destroy method"""
312312

313313
description = 'Quit the figure'
314-
keymap = rcParams['keymap.quit']
314+
default_keymap = rcParams['keymap.quit']
315315

316316
def trigger(self, sender, event, data=None):
317317
Gcf.destroy_fig(self.figure)
@@ -321,7 +321,7 @@ class ToolEnableAllNavigation(ToolBase):
321321
"""Tool to enable all axes for navigation interaction"""
322322

323323
description = 'Enables all axes navigation'
324-
keymap = rcParams['keymap.all_axes']
324+
default_keymap = rcParams['keymap.all_axes']
325325

326326
def trigger(self, sender, event, data=None):
327327
if event.inaxes is None:
@@ -337,7 +337,7 @@ class ToolEnableNavigation(ToolBase):
337337
"""Tool to enable a specific axes for navigation interaction"""
338338

339339
description = 'Enables one axes navigation'
340-
keymap = (1, 2, 3, 4, 5, 6, 7, 8, 9)
340+
default_keymap = (1, 2, 3, 4, 5, 6, 7, 8, 9)
341341

342342
def trigger(self, sender, event, data=None):
343343
if event.inaxes is None:
@@ -354,7 +354,7 @@ class ToolGrid(ToolToggleBase):
354354
"""Tool to toggle the grid of the figure"""
355355

356356
description = 'Toogle Grid'
357-
keymap = rcParams['keymap.grid']
357+
default_keymap = rcParams['keymap.grid']
358358

359359
def trigger(self, sender, event, data=None):
360360
if event.inaxes is None:
@@ -374,7 +374,7 @@ class ToolFullScreen(ToolToggleBase):
374374
"""Tool to toggle full screen"""
375375

376376
description = 'Toogle Fullscreen mode'
377-
keymap = rcParams['keymap.fullscreen']
377+
default_keymap = rcParams['keymap.fullscreen']
378378

379379
def enable(self, event):
380380
self.figure.canvas.manager.full_screen_toggle()
@@ -404,7 +404,7 @@ class ToolYScale(AxisScaleBase):
404404
"""Tool to toggle between linear and logarithmic scales on the Y axis"""
405405

406406
description = 'Toogle Scale Y axis'
407-
keymap = rcParams['keymap.yscale']
407+
default_keymap = rcParams['keymap.yscale']
408408

409409
def set_scale(self, ax, scale):
410410
ax.set_yscale(scale)
@@ -414,7 +414,7 @@ class ToolXScale(AxisScaleBase):
414414
"""Tool to toggle between linear and logarithmic scales on the X axis"""
415415

416416
description = 'Toogle Scale X axis'
417-
keymap = rcParams['keymap.xscale']
417+
default_keymap = rcParams['keymap.xscale']
418418

419419
def set_scale(self, ax, scale):
420420
ax.set_xscale(scale)
@@ -547,7 +547,7 @@ class ToolHome(ViewsPositionsBase):
547547

548548
description = 'Reset original view'
549549
image = 'home.png'
550-
keymap = rcParams['keymap.home']
550+
default_keymap = rcParams['keymap.home']
551551
_on_trigger = 'home'
552552

553553

@@ -556,7 +556,7 @@ class ToolBack(ViewsPositionsBase):
556556

557557
description = 'Back to previous view'
558558
image = 'back.png'
559-
keymap = rcParams['keymap.back']
559+
default_keymap = rcParams['keymap.back']
560560
_on_trigger = 'back'
561561

562562

@@ -565,7 +565,7 @@ class ToolForward(ViewsPositionsBase):
565565

566566
description = 'Forward to next view'
567567
image = 'forward.png'
568-
keymap = rcParams['keymap.forward']
568+
default_keymap = rcParams['keymap.forward']
569569
_on_trigger = 'forward'
570570

571571

@@ -581,7 +581,7 @@ class SaveFigureBase(ToolBase):
581581

582582
description = 'Save the figure'
583583
image = 'filesave.png'
584-
keymap = rcParams['keymap.save']
584+
default_keymap = rcParams['keymap.save']
585585

586586

587587
class ZoomPanBase(ToolToggleBase):
@@ -651,7 +651,7 @@ class ToolZoom(ZoomPanBase):
651651

652652
description = 'Zoom to rectangle'
653653
image = 'zoom_to_rect.png'
654-
keymap = rcParams['keymap.zoom']
654+
default_keymap = rcParams['keymap.zoom']
655655
cursor = cursors.SELECT_REGION
656656
radio_group = 'default'
657657

@@ -861,7 +861,7 @@ def _release(self, event):
861861
class ToolPan(ZoomPanBase):
862862
"""Pan axes with left mouse, zoom with right"""
863863

864-
keymap = rcParams['keymap.pan']
864+
default_keymap = rcParams['keymap.pan']
865865
description = 'Pan axes with left mouse, zoom with right'
866866
image = 'move.png'
867867
cursor = cursors.MOVE

0 commit comments

Comments
 (0)
0