Fedora Linux Support Community & Resources Center
  #1  
Old 5th April 2011, 06:31 PM
IHeart SymLinks Offline
Registered User
 
Join Date: Jan 2011
Posts: 128
linuxfedorafirefox
Python clipboard contents

How can I read and write the clipboard in python? Can I take the contents of the clipboard and set them into a variable and vice versa?

I have been searching and don't find much of anything helpful
__________________
I♥SymLinks

Junior SysAdmin and Python Newbie
Fedora 15 64 Bit (Fedora 13 install upgraded to 14 with preupgrade, then 15 using --distro-sync)
KDE 4.6.5

Laptop: Fedora 13 upgraded to 15 via --distro-sync

Can someone pls help me with The wireless on my laptop?
Reply With Quote
  #2  
Old 7th April 2011, 02:28 PM
fpmurphy Offline
Registered User
 
Join Date: May 2009
Location: /dev/ph
Posts: 308
linuxfirefox
Re: Python clipboard contents

It is easy. Here is a short example program
Code:
#!/usr/bin/python

import pygtk
import gtk

clipboard = gtk.clipboard_get()

# get clipboard content
# other options:  wait_for_image, wait_for_rich_text
text = clipboard.wait_for_text()
print "Clipboard contents:", text

# set clipboard text data
clipboard.set_text('Hello!')

# make clipboard content available 
clipboard.store()
Reply With Quote
  #3  
Old 7th April 2011, 05:09 PM
IHeart SymLinks Offline
Registered User
 
Join Date: Jan 2011
Posts: 128
linuxfedorafirefox
Re: Python clipboard contents

LOL When I ran that I seen the code got confused, but then I remember the code was the clipboard contents

When I run it before it says the clipboard contents I get "Xlib: extension "RANDR" missing on display ":0.0"."

Also setting the clipboard doesn't work for me
__________________
I♥SymLinks

Junior SysAdmin and Python Newbie
Fedora 15 64 Bit (Fedora 13 install upgraded to 14 with preupgrade, then 15 using --distro-sync)
KDE 4.6.5

Laptop: Fedora 13 upgraded to 15 via --distro-sync

Can someone pls help me with The wireless on my laptop?
Reply With Quote
  #4  
Old 7th April 2011, 05:15 PM
fpmurphy Offline
Registered User
 
Join Date: May 2009
Location: /dev/ph
Posts: 308
windows_7firefox
Re: Python clipboard contents

RANDR should have nothing to do with this. However, try changing imports to:
Code:
import pygtk
pygtk.require('2.0')
import gtk
What version of Fedora are you using?
Reply With Quote
  #5  
Old 7th April 2011, 10:21 PM
IHeart SymLinks Offline
Registered User
 
Join Date: Jan 2011
Posts: 128
linuxfedorafirefox
Re: Python clipboard contents

Still does it, Maybe it's because I am using KDE and importing gtk?

I am running Fedora 14.
__________________
I♥SymLinks

Junior SysAdmin and Python Newbie
Fedora 15 64 Bit (Fedora 13 install upgraded to 14 with preupgrade, then 15 using --distro-sync)
KDE 4.6.5

Laptop: Fedora 13 upgraded to 15 via --distro-sync

Can someone pls help me with The wireless on my laptop?
Reply With Quote
  #6  
Old 7th April 2011, 10:47 PM
marko's Avatar
marko Offline
Registered User
 
Join Date: Jun 2004
Location: Laurel, MD USA
Posts: 5,491
solarisfirefox
Re: Python clipboard contents

this might have some tips

http://stackoverflow.com/questions/3...-x11-clipboard
Reply With Quote
  #7  
Old 8th April 2011, 04:36 PM
IHeart SymLinks Offline
Registered User
 
Join Date: Jan 2011
Posts: 128
linuxfedorafirefox
Re: Python clipboard contents

@fpmurphy
I just tried your script in my Fedora VM (I don't want to log in and out of my production machine to switch between Gnome and KDE).

I doesn't give the RANDR error in either Gnome and KDE. Only difference is I have dual monitors on the host.

In Gnome it works as expected, reading and setting the clipboard. In KDE it reads the clipboard, but when it sets it the clipboard contents become blank.

@marko
That page is just links I have already found when I Googled, but I don't understand any of it...
__________________
I♥SymLinks

Junior SysAdmin and Python Newbie
Fedora 15 64 Bit (Fedora 13 install upgraded to 14 with preupgrade, then 15 using --distro-sync)
KDE 4.6.5

Laptop: Fedora 13 upgraded to 15 via --distro-sync

Can someone pls help me with The wireless on my laptop?
Reply With Quote
Reply

Tags
clipboard, contents, python

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
vnc clipboard silserwis Using Fedora 0 18th October 2009 08:42 PM
Python, IDLE, Python-tools Gnome. Deonis Using Fedora 2 12th March 2009 03:44 AM
clipboard garbage myname77 Using Fedora 3 19th September 2008 06:49 PM
Processing Conflict: python-devel conflicts python< 2.3.4-13.1 guarriman Using Fedora 0 15th September 2005 05:53 PM


Current GMT-time: 10:57 (Thursday, 20-06-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat