8000 adding copy tool to example · OceanWolf/matplotlib@8835b9b · GitHub
[go: up one dir, main page]

Skip to content

Commit 8000 8835b9b

Browse files
committed
adding copy tool to example
1 parent deb834c commit 8835b9b

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

examples/user_interfaces/navigation.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import matplotlib
2-
matplotlib.use('GTK3AGG')
2+
matplotlib.use('GTK3Cairo')
33
import matplotlib.pyplot as plt
44

55
fig = plt.figure()
@@ -28,5 +28,23 @@ def activate(self, event):
2828

2929
#Just for fun, lets remove the back button
3030
fig.canvas.manager.navigation.remove_tool('Back')
31-
31+
32+
#looking at https://github.com/matplotlib/matplotlib/issues/1987
33+
#a simple example of copy canvas
34+
class CopyTool(ToolBase):
35+
keymap = 'ctrl+c'
36+
name = 'Copy'
37+
description = 'Copy canvas'
38+
position = -1
39+
40+
def activate(self, event):
41+
from gi.repository import Gtk, Gdk, GdkPixbuf
42+
clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
43+
window = self.figure.canvas.get_window()
44+
x, y, width, height = window.get_geometry()
45+
pb = Gdk.pixbuf_get_from_window(window, x, y, width, height)
46+
clipboard.set_image(pb)
47+
48+
fig.canvas.manager.navigation.add_tool(CopyTool)
49+
3250
plt.show()

0 commit comments

Comments
 (0)
0