##// END OF EJS Templates
check win32clipboard existence instead of platform==win32
vivainio -
Show More
@@ -1,45 +1,50 b''
1 1 #!/usr/bin/env python
2 2
3 3 import IPython.ipapi
4 4
5 5 ip = IPython.ipapi.get()
6 6
7 7 from string import Template
8 8 import sys
9 9
10 10 def toclip_w32(s):
11 """ places contents of s to clipboard """
11 """ places contents of s to clipboard
12
13 Needs pyvin32 to work:
14 http://sourceforge.net/projects/pywin32/
15 """
12 16 import win32clipboard as cl
13 17 import win32con
14 18 cl.OpenClipboard()
15 19 cl.EmptyClipboard()
16 20 cl.SetClipboardText( s )
17 21 cl.CloseClipboard()
18 22
19 if sys.platform == 'win32':
23 try:
24 import win32clipboard
20 25 toclip = toclip_w32
21 else:
26 except ImportError:
22 27 def toclip(s): pass
23 28
24 29
25 30 def render(tmpl):
26 31 """ Render a template (as specified in string.Template docs) from ipython variables
27 32
28 33 Example:
29 34
30 35 $ import ipy_render
31 36 $ my_name = 'Bob' # %store this for convenience
32 37 $ t_submission_form = "Submission report, author: $my_name" # %store also
33 38 $ render t_submission_form
34 39
35 40 => returns "Submission report, author: Bob" and copies to clipboard on win32
36 41
37 42 """
38 43
39 44 s = Template(tmpl)
40 45 res = s.substitute(ip.user_ns)
41 46 toclip(res)
42 47 return res
43 48
44 ip.user_ns['render'] = render
49 ip.to_user_ns('render')
45 50 No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now