Skip to content

Commit 9266447

Browse files
committed
classmethods for default tools modification
1 parent b207a72 commit 9266447

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

examples/user_interfaces/navigation.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ class ListTools(ToolBase):
1010
#keyboard shortcut
1111
keymap = 'm'
1212
#Name used as id, must be unique between tools of the same navigation
13-
name = 'List'
14-
description = 'List Tools'
13+
name = 'List'
14+
description = 'List Tools'
1515
#Where to put it in the toolbar, -1 = at the end, None = Not in toolbar
1616
position = -1
17-
17+
1818
def trigger(self, event):
1919
#The most important attributes are navigation and figure
2020
self.navigation.list_tools()
@@ -29,7 +29,7 @@ class CopyTool(ToolBase):
2929
position = -1
3030

3131
def trigger(self, event):
32-
from gi.repository import Gtk, Gdk, GdkPixbuf
32+
from gi.repository import Gtk, Gdk
3333
clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
3434
window = self.figure.canvas.get_window()
3535
x, y, width, height = window.get_geometry()
@@ -46,7 +46,7 @@ def trigger(self, event):
4646
fig.canvas.manager.navigation.add_tool(ListTools)
4747
fig.canvas.manager.navigation.add_tool(CopyTool)
4848

49-
##Just for fun, lets remove the back button
49+
##Just for fun, lets remove the back button
5050
fig.canvas.manager.navigation.remove_tool('Back')
5151

5252
plt.show()

lib/matplotlib/backend_bases.py

+16-6
Original file line numberDiff line numberDiff line change
@@ -3287,10 +3287,20 @@ def __init__(self, canvas, toolbar=None):
32873287

32883288
self._last_cursor = self._default_cursor
32893289

3290+
@classmethod
3291+
def get_default_tools(cls):
3292+
"""Get the default tools"""
3293+
return cls._default_tools
3294+
3295+
@classmethod
3296+
def set_default_tools(cls, tools):
3297+
"""Set default tools"""
3298+
cls._default_tools = tools
3299+
32903300
def _get_toolbar(self, toolbar, canvas):
32913301
# must be inited after the window, drawingArea and figure
32923302
# attrs are set
3293-
if rcParams['toolbar'] == 'navigation' and toolbar is not None:
3303+
if rcParams['toolbar'] == 'navigation' and toolbar is not None:
32943304
toolbar = toolbar(canvas.manager)
32953305
else:
32963306
toolbar = None
@@ -3324,7 +3334,7 @@ def get_tool_keymap(self, name):
33243334
----------
33253335
list : list of keys associated with the Tool
33263336
"""
3327-
keys = [k for k, i in self._keys.items() if i == name]
3337+
keys = [k for k, i in six.iteritems(self._keys) if i == name]
33283338
return keys
33293339

33303340
def set_tool_keymap(self, name, *keys):
@@ -3340,7 +3350,7 @@ def set_tool_keymap(self, name, *keys):
33403350
if name not in self._tools:
33413351
raise AttributeError('%s not in Tools' % name)
33423352

3343-
active_keys = [k for k, i in self._keys.items() if i == name]
3353+
active_keys = [k for k, i in six.iteritems(self._keys) if i == name]
33443354
for k in active_keys:
33453355
del self._keys[k]
33463356

@@ -3385,7 +3395,7 @@ def remove_tool(self, name):
33853395
"""
33863396
self.unregister(name)
33873397
del self._tools[name]
3388-
keys = [k for k, v in self._keys.items() if v == name]
3398+
keys = [k for k, v in six.iteritems(self._keys) if v == name]
33893399
for k in keys:
33903400
del self._keys[k]
33913401

@@ -3434,7 +3444,7 @@ def add_tool(self, tool):
34343444
toggle)
34353445

34363446
def _get_cls_to_instantiate(self, callback_class):
3437-
if isinstance(callback_class, basestring):
3447+
if isinstance(callback_class, six.string_types):
34383448
#FIXME: make more complete searching structure
34393449
if callback_class in globals():
34403450
return globals()[callback_class]
@@ -3533,7 +3543,7 @@ def list_tools(self):
35333543
print ('_' * 80)
35343544
for name in sorted(self._tools.keys()):
35353545
tool = self._tools[name]
3536-
keys = [k for k, i in self._keys.items() if i == name]
3546+
keys = [k for k, i in six.iteritems(self._keys) if i == name]
35373547
print ("{0:20} {1:50} {2}".format(tool.name, tool.description,
35383548
', '.join(keys)))
35393549
print ('_' * 80, '\n')

lib/matplotlib/backend_tools.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ class ToolEnableNavigation(ToolBase):
205205
"""
206206
name = 'EnableOne'
207207
description = 'Enables one axes navigation'
208-
keymap = range(1, 10)
208+
keymap = (1, 2, 3, 4, 5, 6, 7, 8, 9)
209209

210210
def trigger(self, event):
211211
if event.inaxes is None:

0 commit comments

Comments
 (0)