LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Python: Won't copy to the clipboard (https://www.linuxquestions.org/questions/programming-9/python-wont-copy-to-the-clipboard-829072/)

narnie 08-28-2010 08:09 PM

Python: Won't copy to the clipboard
 
Hello,

I having a hard time figuring out why this code works in an interactive ipython shell, but it gives a blank clipboard when run in a bash terminal.

Code:

#! /usr/bin/python2.6
#

from gtk import Clipboard

cb = Clipboard()
text = cb.wait_for_text().split('\n')
text = ''.join(text)
cb.set_text(text)

It works if run as ./fix_line_breaks (and of course the shell wrapper I'm using for it)

Code:

#! /bin/bash
#

$HOME/python/fix_line_breaks.py

If I put in a 'print text' at the end, it shows the correct text, it is just not being put into the clipboard from gnome-terminal in X (but it will from the ipython console in gnome-terminal).

However, a paste shows the clipboard to be empty.

Any ideas?

Thanks,
Narnie

narnie 08-28-2010 09:43 PM

Opps. I found it. I needed to call cb.store() to "seal the deal" after calling cb.set_text(text)

Here is how the code should read for those needing to know.

Code:

#! /usr/bin/python2.6
#

from gtk import Clipboard

cb = Clipboard()
text = cb.wait_for_text().split('\n')
text = ''.join(text)
cb.set_text(text)
cb.store()

Cheerio,
Narnie


All times are GMT -5. The time now is 02:19 AM.