Skip to content

Commit 44a9b0e

Browse files
committed
events working
1 parent c2da483 commit 44a9b0e

File tree

4 files changed

+283
-242
lines changed

4 files changed

+283
-242
lines changed

examples/user_interfaces/navigation.py

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,54 +6,54 @@
66
from matplotlib.backend_tools import ToolBase
77

88

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)
4646

4747

4848
fig = plt.figure()
4949
plt.plot([1, 2, 3])
5050

5151
# 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)
5555
#
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')
5858

5959
plt.show()

0 commit comments

Comments
 (0)