View Single Post
BrentDC's Avatar
Posts: 903 | Thanked: 632 times | Joined on Apr 2008
#1
It seems like I've spent hours today trying to get something seemingly very simple to work, but have been unable to *bangs head on table*.

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:
Code:
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()
This code doesn't work at all. self.get_text is never called (that is why the print 1 and print 2 statements are there). I'm wondering, why?

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