|
|
2009-05-19
, 21:46
|
|
Posts: 3,319 |
Thanked: 5,610 times |
Joined on Aug 2008
@ Finland
|
#2
|
import threading
import gtk
import time
class Clipboard(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
while(True): # Forever loop
self.clip = self.get_clipboard()
time.sleep(2)
def get_clipboard(self):
clip = gtk.clipboard_get(gtk.gdk.SELECTION_CLIPBOARD)
print 1
text = clip.request_text(self.get_text)
def get_text(self, clipboard, text):
print 2
print text
Clipboard().start()
| The Following User Says Thank You to attila77 For This Useful Post: | ||
|
|
2009-05-19
, 23:21
|
|
|
Posts: 903 |
Thanked: 632 times |
Joined on Apr 2008
|
#3
|
|
|
2009-05-20
, 01:13
|
|
|
Posts: 903 |
Thanked: 632 times |
Joined on Apr 2008
|
#5
|
(which is probably painfully obvious).
|
|
2009-05-20
, 01:48
|
|
|
Posts: 2,427 |
Thanked: 2,986 times |
Joined on Dec 2007
|
#6
|
if __name__ == "__main__":
gtk.gdk.threads_init()
...
gtk.main()
|
|
2009-05-20
, 06:46
|
|
Posts: 432 |
Thanked: 645 times |
Joined on Mar 2009
|
#7
|
To get a better understanding try this and some help tutorial how to implement it you will find here, even though I do not agree with the title of the blog entry
It might be easier to blog than to put it into a wiki, but it is definitely easier to find in a properly organised wiki. Actually there were so many questions related to Qt and GTK in the last couple of days which could be interesting for everyone, that I think it would be worth it to create a Qt and GTK Q&A section in the wiki as the first starting point with small issues (mostly related to maemo) or like this here...what do you think?| The Following 5 Users Say Thank You to danielwilms For This Useful Post: | ||
|
|
2009-05-20
, 08:27
|
|
Posts: 3,319 |
Thanked: 5,610 times |
Joined on Aug 2008
@ Finland
|
#8
|
| The Following User Says Thank You to attila77 For This Useful Post: | ||
|
|
2009-05-20
, 19:37
|
|
|
Posts: 903 |
Thanked: 632 times |
Joined on Apr 2008
|
#9
|

|
|
2009-05-20
, 19:58
|
|
|
Posts: 903 |
Thanked: 632 times |
Joined on Apr 2008
|
#10
|
![]() |
| Tags |
| clipboard, python, threading |
| Thread Tools | |
|
I'm trying to create a class, that when called, spawns into a new thread (as to allow the calling code to keep running) and prints out the current contents of the clipboard every 2 seconds. In reality, I'll create gtk.MenuItems from the polled history, so this is more or less just a test to see if I can get the basics of the code to work.
Here it is:
import threading import gtk import time class Clipboard(threading.Thread): def __init__(self): threading.Thread.__init__(self) while(True): # Forever loop self.clip = self.get_clipboard() time.sleep(2) def get_clipboard(self): clip = gtk.clipboard_get(gtk.gdk.SELECTION_CLIPBOARD) print 1 text = clip.request_text(self.get_text) def get_text(self, clipboard, text): print 2 print text Clipboard().start()Is it because I'm not actually using the gtk mainloop? Or is the threading messing with something?
This is mostly a backend class, and I didn't want to involve gtk in the first place, but there doesn't seem to be a way to access the clipboard otherwise.
Any help, and suggestions on a more elegant solution, is very much needed!
Thanks.
-Brent
Author of TouchSearch -- web searching software for Maemo 5.
Mobile Device lineage: Palm Z22 -> Palm TX -> Nokia N800 -> Nokia N900