March 3rd, 2005, 07:32 PM
Putting something to the clipboard
Is there a way that is not os dependant that puts something into the clipboard(you know when you hit copy for text), i am not wanting the user to have to highlight and select copy. I want to insert something into the clipboard so that it will be able to be pasted everywhere else(even outside the python program)
March 4th, 2005, 01:34 AM
In wxPython there is an easy to use clipboard class. Putting text to the clipboard looks like this:
clip = wxClipboard()
March 4th, 2005, 05:00 PM
I just got time to test that out, I found it really isn't working. I am glad it is done iwth wxPython bcause i am starting to use it. However when i run that it doesn't put it in the clipboard. I cannot past it anywhere else. I looked up the c code for wxClipboard, and i read through what everything does. I even tested a few thigns it still doesn't let me past it anywhere else. It just clears the clipboard and it freezes up a bit before not putting anything. almost like maybe the clipboard is being curroped or it can't read something
March 4th, 2005, 06:45 PM
Did you see if Clipboard is supported for you platform.
Did you intialize wx app first before using clipboard ?
I tried out the following code and it worked perfect
hope that helps
do = wx.TextDataObject()
March 4th, 2005, 08:31 PM
well, I was testing it on linux. I hope it works on linux because that is the main os that i am going ot be using it under. What tyou did should give the same output of what mine did. Yes i initized wxPython and such. I did not get any error msges i just got nothing put to the clipboard. Actually it deleted everything in the clipboard and then put nothing into it. When i try to past it actually kinda freezes up(try to past outside of the app, it also doesn't work inside the app).
March 5th, 2005, 02:54 PM
Ok, i have played around with it some more, I fond out it isn't in the wxPython module it is just in wx. So i imported just that. Then i ran what you put it works like when i import wxPython but now when it trys to set data to the clipboard i get a strange error. here is what a get:
14:46:07: Error: Failed to put data on the clipboard (error 2147221008: coInitialize has not been called.)
March 5th, 2005, 06:49 PM
Originally Posted by CyBerHigh
This means that you have not created and intialized Wx.app ( which calls coInitalize) .
Add the following line to you code
that should work
look into wx python demo for more on clipboard
March 5th, 2005, 10:50 PM
man, i don't think i have ever had this difficult of a problem. last time i checked i couldn't find anything in the demo files on it either.
now when i run this i get no errors but it just clears my clipboard memorie
i just can't figure out why my code isn't work. I have tryed to put the flush in it, but it says that it doesn't exsite. i read in the c ducs that to save it to the clipboard so it doesn't get deleted when you close it you have to run flush. but that doesn't work. either.
from wxPython.wx import *
clipdata = wxTextDataObject()
March 7th, 2005, 02:10 AM
Sorry for beeing too short with the example.
The problem is that wx objects must be run from within a working GUI environment. If you run them from the python command line interface, they will not work as expected, even if the command line is started from a GUI (like Konsole on KDE or cmd on windows).
To have the example working, you must run it either in an IDLE session (regardless of the operating sytem, it works on Linux AND windows) or in another Python GUI Shell, or from within a running wx application.
If you want to use wxPython, you may want to consider Boa Constructor as a RAD tool. The Boa IDE contains a Python Shell which can be used for testing code like the this.
If you run the example from IDLE or a Boa Shell you don't need to create a wxApp object. At least this works for me on windows and KDE. I didn't try it on Gnome or another GUI.
March 7th, 2005, 06:18 AM
o ok, well that makes since now why i coudln't get it to work. THank you very much for you help. I will test that out and try to figure out a way to put it in my tkinter app now..lol