##// END OF EJS Templates
Fix alignment default.
Fix alignment default.

File last commit:

r265:3343d472
r280:f6383f05
Show More
win32clip.py
45 lines | 1.2 KiB | text/x-python | PythonLexer
vivainio
reindent win32clip.py, add s = %clip
r229 import IPython.ipapi
ip = IPython.ipapi.get()
def clip_f( self, parameter_s = '' ):
"""Save a set of lines to the clipboard.
Usage:\\
%clip n1-n2 n3-n4 ... n5 .. n6 ...
This function uses the same syntax as %macro for line extraction, but
instead of creating a macro it saves the resulting string to the
clipboard.
When used without arguments, this returns the text contents of the clipboard.
E.g.
mytext = %clip
"""
import win32clipboard as cl
import win32con
args = parameter_s.split()
cl.OpenClipboard()
if len( args ) == 0:
data = cl.GetClipboardData( win32con.CF_TEXT )
cl.CloseClipboard()
return data
vivainio
%clip = <expr> syntax in win32clip.py
r265 api = self.getapi()
if parameter_s.lstrip().startswith('='):
rest = parameter_s[parameter_s.index('=')+1:].strip()
val = str(api.ev(rest))
else:
ranges = args[0:]
val = ''.join( self.extract_input_slices( ranges ) )
vivainio
reindent win32clip.py, add s = %clip
r229
cl.EmptyClipboard()
vivainio
%clip = <expr> syntax in win32clip.py
r265 cl.SetClipboardText( val )
vivainio
reindent win32clip.py, add s = %clip
r229 cl.CloseClipboard()
vivainio
%clip = <expr> syntax in win32clip.py
r265 print 'The following text was written to the clipboard'
print val
vivainio
reindent win32clip.py, add s = %clip
r229
ip.expose_magic( "clip", clip_f )