Show More
@@ -1,40 +1,45 b'' | |||||
1 | import IPython.ipapi |
|
1 | import IPython.ipapi | |
2 |
|
2 | |||
3 | ip = IPython.ipapi.get() |
|
3 | ip = IPython.ipapi.get() | |
4 |
|
4 | |||
5 | def clip_f( self, parameter_s = '' ): |
|
5 | def clip_f( self, parameter_s = '' ): | |
6 | """Save a set of lines to the clipboard. |
|
6 | """Save a set of lines to the clipboard. | |
7 |
|
7 | |||
8 | Usage:\\ |
|
8 | Usage:\\ | |
9 | %clip n1-n2 n3-n4 ... n5 .. n6 ... |
|
9 | %clip n1-n2 n3-n4 ... n5 .. n6 ... | |
10 |
|
10 | |||
11 | This function uses the same syntax as %macro for line extraction, but |
|
11 | This function uses the same syntax as %macro for line extraction, but | |
12 | instead of creating a macro it saves the resulting string to the |
|
12 | instead of creating a macro it saves the resulting string to the | |
13 | clipboard. |
|
13 | clipboard. | |
14 |
|
14 | |||
15 | When used without arguments, this returns the text contents of the clipboard. |
|
15 | When used without arguments, this returns the text contents of the clipboard. | |
16 | E.g. |
|
16 | E.g. | |
17 |
|
17 | |||
18 | mytext = %clip |
|
18 | mytext = %clip | |
19 |
|
19 | |||
20 | """ |
|
20 | """ | |
21 |
|
21 | |||
22 | import win32clipboard as cl |
|
22 | import win32clipboard as cl | |
23 | import win32con |
|
23 | import win32con | |
24 | args = parameter_s.split() |
|
24 | args = parameter_s.split() | |
25 | cl.OpenClipboard() |
|
25 | cl.OpenClipboard() | |
26 | if len( args ) == 0: |
|
26 | if len( args ) == 0: | |
27 | data = cl.GetClipboardData( win32con.CF_TEXT ) |
|
27 | data = cl.GetClipboardData( win32con.CF_TEXT ) | |
28 | cl.CloseClipboard() |
|
28 | cl.CloseClipboard() | |
29 | return data |
|
29 | return data | |
30 |
|
30 | api = self.getapi() | ||
31 | ranges = args[0:] |
|
31 | ||
32 | cmds = ''.join( self.extract_input_slices( ranges ) ) |
|
32 | if parameter_s.lstrip().startswith('='): | |
|
33 | rest = parameter_s[parameter_s.index('=')+1:].strip() | |||
|
34 | val = str(api.ev(rest)) | |||
|
35 | else: | |||
|
36 | ranges = args[0:] | |||
|
37 | val = ''.join( self.extract_input_slices( ranges ) ) | |||
33 |
|
38 | |||
34 | cl.EmptyClipboard() |
|
39 | cl.EmptyClipboard() | |
35 |
cl.SetClipboardText( |
|
40 | cl.SetClipboardText( val ) | |
36 | cl.CloseClipboard() |
|
41 | cl.CloseClipboard() | |
37 |
print 'The following |
|
42 | print 'The following text was written to the clipboard' | |
38 |
print |
|
43 | print val | |
39 |
|
44 | |||
40 | ip.expose_magic( "clip", clip_f ) |
|
45 | ip.expose_magic( "clip", clip_f ) |
General Comments 0
You need to be logged in to leave comments.
Login now