LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-28-2010, 08:09 PM   #1
narnie
Member
 
Registered: Jan 2010
Distribution: Linux Mint, Ubuntu Netbook Edition, et al
Posts: 108

Rep: Reputation: 17
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
 
Old 08-28-2010, 09:43 PM   #2
narnie
Member
 
Registered: Jan 2010
Distribution: Linux Mint, Ubuntu Netbook Edition, et al
Posts: 108

Original Poster
Rep: Reputation: 17
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy to 'clipboard' from shell anth0ny5 Linux - Newbie 9 04-08-2010 01:19 PM
Copy an entire document in Vi to clipboard geokker Linux - Newbie 2 08-06-2009 03:14 PM
Copy to Clipboard rubadub Programming 5 02-11-2008 02:39 AM
Copy screenshot to clipboard simbamford Linux - Newbie 1 11-24-2006 03:17 PM
copy from terminal to clipboard curos Linux - Newbie 2 02-04-2006 09:39 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration