From 3c5e20cc86d0991aacef2230eb0daa9da68afd85 2006-03-21 16:25:52 From: vivainio Date: 2006-03-21 16:25:52 Subject: [PATCH] reindent win32clip.py, add s = %clip --- diff --git a/IPython/Extensions/win32clip.py b/IPython/Extensions/win32clip.py index 75d7406..7fe9161 100644 --- a/IPython/Extensions/win32clip.py +++ b/IPython/Extensions/win32clip.py @@ -1,29 +1,40 @@ -import IPython.ipapi -import win32clipboard - -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.""" - - args = parameter_s.split() - if len(args) == 0: - return None # xxx todo return clipboard text - - ranges = args[0:] - cmds = ''.join(self.extract_input_slices(ranges)) - win32clipboard.OpenClipboard() - win32clipboard.EmptyClipboard() - win32clipboard.SetClipboardText(cmds) - win32clipboard.CloseClipboard() - print 'The following commands were written to the clipboard' - print cmds - -ip.expose_magic("clip",clip_f) \ No newline at end of file +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 + + ranges = args[0:] + cmds = ''.join( self.extract_input_slices( ranges ) ) + + cl.EmptyClipboard() + cl.SetClipboardText( cmds ) + cl.CloseClipboard() + print 'The following commands were written to the clipboard' + print cmds + +ip.expose_magic( "clip", clip_f )