I have a need to write data to the Windows clipboard from a Python script.
I found a nice, simple solution @
http://wiki.wxpython.org/index.cgi/ClipBoard. The problem is, I can only
get it to work from within the PythonWin and SPE IDE's. I get errors if I
try to run the exact same code from the command line or via IDLE's
interactive shell. I can't figure it out. Any ideas? Possibly something
missing from my PYTHONPATH environment variable?
Any help is appreciated. Thanks,
Tim
From PythonWin (works fine):[color=blue][color=green][color=darkred]
>>> from wxPython.wx import *
>>> wxTheClipboard. Open()[/color][/color][/color]
True[color=blue][color=green][color=darkred]
>>> wxTheClipboard. Clear()
>>> wxTheClipboard. SetData(wxTextD ataObject("Test 1"))[/color][/color][/color]
True[color=blue][color=green][color=darkred]
>>> wxTheClipboard. Close()
>>> ## ctrl+v = Test 1[/color][/color][/color]
From IDLE (doesn't work):[color=blue][color=green][color=darkred]
>>> from wxPython.wx import *
>>> wxTheClipboard. Open()[/color][/color][/color]
True[color=blue][color=green][color=darkred]
>>> wxTheClipboard. SetData(wxTextD ataObject("Test 2"))[/color][/color][/color]
False[color=blue][color=green][color=darkred]
>>> ## ctrl+v = Test 1
>>> wxTheClipboard. Clear()
>>> ## ctrl+v = Test 1
>>> wxTheClipboard. Close()[/color][/color][/color]
From Python (command-line) (doesn't work, more verbose errors):[color=blue][color=green][color=darkred]
>>> from wxPython.wx import *
>>> wxTheClipboard. Open()[/color][/color][/color]
True[color=blue][color=green][color=darkred]
>>> wxTheClipboard. SetData(wxTextD ataObject("Test 3"))[/color][/color][/color]
02:17:48: Error: Failed to put data on the clipboard (error -2147221008:
coIniti
alize has not been called.)
False[color=blue][color=green][color=darkred]
>>> wxTheClipboard. Clear()[/color][/color][/color]
02:17:56: Debug: ..\..\src\msw\c lipbrd.cpp(554) : 'OleSetClipboar d(NULL)'
failed
with error 0x00000002 (the system cannot find the file specified.).
I found a nice, simple solution @
http://wiki.wxpython.org/index.cgi/ClipBoard. The problem is, I can only
get it to work from within the PythonWin and SPE IDE's. I get errors if I
try to run the exact same code from the command line or via IDLE's
interactive shell. I can't figure it out. Any ideas? Possibly something
missing from my PYTHONPATH environment variable?
Any help is appreciated. Thanks,
Tim
From PythonWin (works fine):[color=blue][color=green][color=darkred]
>>> from wxPython.wx import *
>>> wxTheClipboard. Open()[/color][/color][/color]
True[color=blue][color=green][color=darkred]
>>> wxTheClipboard. Clear()
>>> wxTheClipboard. SetData(wxTextD ataObject("Test 1"))[/color][/color][/color]
True[color=blue][color=green][color=darkred]
>>> wxTheClipboard. Close()
>>> ## ctrl+v = Test 1[/color][/color][/color]
From IDLE (doesn't work):[color=blue][color=green][color=darkred]
>>> from wxPython.wx import *
>>> wxTheClipboard. Open()[/color][/color][/color]
True[color=blue][color=green][color=darkred]
>>> wxTheClipboard. SetData(wxTextD ataObject("Test 2"))[/color][/color][/color]
False[color=blue][color=green][color=darkred]
>>> ## ctrl+v = Test 1
>>> wxTheClipboard. Clear()
>>> ## ctrl+v = Test 1
>>> wxTheClipboard. Close()[/color][/color][/color]
From Python (command-line) (doesn't work, more verbose errors):[color=blue][color=green][color=darkred]
>>> from wxPython.wx import *
>>> wxTheClipboard. Open()[/color][/color][/color]
True[color=blue][color=green][color=darkred]
>>> wxTheClipboard. SetData(wxTextD ataObject("Test 3"))[/color][/color][/color]
02:17:48: Error: Failed to put data on the clipboard (error -2147221008:
coIniti
alize has not been called.)
False[color=blue][color=green][color=darkred]
>>> wxTheClipboard. Clear()[/color][/color][/color]
02:17:56: Debug: ..\..\src\msw\c lipbrd.cpp(554) : 'OleSetClipboar d(NULL)'
failed
with error 0x00000002 (the system cannot find the file specified.).
Comment