|
6 | 6 | from matplotlib.backend_tools import ToolBase
|
7 | 7 |
|
8 | 8 |
|
9 |
| -# # Create a simple tool to list all the tools |
10 |
| -# class ListTools(ToolBase): |
11 |
| -# # keyboard shortcut |
12 |
| -# keymap = 'm' |
13 |
| -# description = 'List Tools' |
14 |
| -# |
15 |
| -# def trigger(self, event): |
16 |
| -# tools = self.navigation.get_tools() |
17 |
| -# |
18 |
| -# print ('_' * 80) |
19 |
| -# print ("{0:12} {1:45} {2}".format('Name (id)', |
20 |
| -# 'Tool description', |
21 |
| -# 'Keymap')) |
22 |
| -# print ('_' * 80) |
23 |
| -# for name in sorted(tools.keys()): |
24 |
| -# keys = ', '.join(sorted(tools[name]['keymap'])) |
25 |
| -# print ("{0:12} {1:45} {2}".format(name, |
26 |
| -# tools[name]['description'], |
27 |
| -# keys)) |
28 |
| -# print ('_' * 80) |
29 |
| -# |
30 |
| -# |
31 |
| -# # A simple example of copy canvas |
32 |
| -# # ref: at https://github.com/matplotlib/matplotlib/issues/1987 |
33 |
| -# class CopyToolGTK3(ToolBase): |
34 |
| -# keymap = 'ctrl+c' |
35 |
| -# description = 'Copy canvas' |
36 |
| -# # It is not added to the toolbar as a button |
37 |
| -# intoolbar = False |
38 |
| -# |
39 |
| -# def trigger(self, event): |
40 |
| -# from gi.repository import Gtk, Gdk |
41 |
| -# clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD) |
42 |
| -# window = self.figure.canvas.get_window() |
43 |
| -# x, y, width, height = window.get_geometry() |
44 |
| -# pb = Gdk.pixbuf_get_from_window(window, x, y, width, height) |
45 |
| -# clipboard.set_image(pb) |
| 9 | +# Create a simple tool to list all the tools |
| 10 | +class ListTools(ToolBase): |
| 11 | + # keyboard shortcut |
| 12 | + keymap = 'm' |
| 13 | + description = 'List Tools' |
| 14 | + |
| 15 | + def trigger(self, event): |
| 16 | + tools = self.navigation.get_tools() |
| 17 | + |
| 18 | + print ('_' * 80) |
| 19 | + print ("{0:12} {1:45} {2}".format('Name (id)', |
| 20 | + 'Tool description', |
| 21 | + 'Keymap')) |
| 22 | + print ('_' * 80) |
| 23 | + for name in sorted(tools.keys()): |
| 24 | + keys = ', '.join(sorted(tools[name]['keymap'])) |
| 25 | + print ("{0:12} {1:45} {2}".format(name, |
| 26 | + tools[name]['description'], |
| 27 | + keys)) |
| 28 | + print ('_' * 80) |
| 29 | + |
| 30 | + |
| 31 | +# A simple example of copy canvas |
| 32 | +# ref: at https://github.com/matplotlib/matplotlib/issues/1987 |
| 33 | +class CopyToolGTK3(ToolBase): |
| 34 | + keymap = 'ctrl+c' |
| 35 | + description = 'Copy canvas' |
| 36 | + # It is not added to the toolbar as a button |
| 37 | + intoolbar = False |
| 38 | + |
| 39 | + def trigger(self, event): |
| 40 | + from gi.repository import Gtk, Gdk |
| 41 | + clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD) |
| 42 | + window = self.figure.canvas.get_window() |
| 43 | + x, y, width, height = window.get_geometry() |
| 44 | + pb = Gdk.pixbuf_get_from_window(window, x, y, width, height) |
| 45 | + clipboard.set_image(pb) |
46 | 46 |
|
47 | 47 |
|
48 | 48 | fig = plt.figure()
|
49 | 49 | plt.plot([1, 2, 3])
|
50 | 50 |
|
51 | 51 | # Add the custom tools that we created
|
52 |
| -# fig.canvas.manager.navigation.add_tool('List', ListTools) |
53 |
| -# if matplotlib.rcParams['backend'] == 'GTK3Cairo': |
54 |
| -# fig.canvas.manager.navigation.add_tool('copy', CopyToolGTK3) |
| 52 | +fig.canvas.manager.navigation.add_tool('List', ListTools) |
| 53 | +if matplotlib.rcParams['backend'] == 'GTK3Cairo': |
| 54 | + fig.canvas.manager.navigation.add_tool('copy', CopyToolGTK3) |
55 | 55 | #
|
56 |
| -# # Just for fun, lets remove the forward button |
57 |
| -# fig.canvas.manager.navigation.remove_tool('Forward') |
| 56 | +# Just for fun, lets remove the forward button |
| 57 | +fig.canvas.manager.navigation.remove_tool('forward') |
58 | 58 |
|
59 | 59 | plt.show()
|
0 commit comments