Hi! Im writing an application, where I need to display the changes of the clipboard. So if the text of the clipboard are changed, the application need to display it.
I didnt find any gtk function to provide me this automatically(so the Gtk itself trigger an events, when the clipboard changes), am I right? Or do I need the check the clipboard periodically? (for example every 100 ms, and if it is changed, launch the appropriate function) What is the best approach the handle this problem (new timer thread which check the clipboard periodically?)? Any pointer for the right docs is really appreciated! Best regards, Khiraly ps: For the curious, here is the program which display the clipboard on anotification area (but only once, bottom-right corner): #! /usr/bin/python import pygtk pygtk.require("2.0") import gtk,gobject import egg.trayicon class TrayDemonstration: def close_balloon(self,a,b): print "closing balloon..." self.balloon.destroy(); return True def set_label(self,text): #text = text + "hmm" self.label.set_text(text) size = self.label.size_request() self.rect.x = size[0] self.rect.y = size[1] self.balloon.resize(self.rect.x,self.rect.y) self.balloon.move(self.width-self.rect.x,self.height-self.rect.y) return def clipboard_text_received(self, clipboard, text, data): self.set_label(text) return def __init__(self): window = gtk.Window(gtk.WINDOW_POPUP); self.balloon = window; self.label = gtk.Label("Balloon!! \n another row!\n es meg egy"); eventbox = gtk.EventBox() eventbox.set_events (gtk.gdk.BUTTON_PRESS_MASK) eventbox.connect("button-press-event",self.close_balloon) # close balloon is for closing the balloon, # the status icon is kept in self.trayicon # so it could be used in the whole class eventbox.add(self.label) window.add(eventbox); ty = egg.trayicon.TrayIcon("TrayIconDemo") eventbox2 = gtk.EventBox() pixbuf = gtk.gdk.pixbuf_new_from_file ("/usr/share/icons/gnome/scalable/emblems/emblem-favorite.svg") image = gtk.Image() image.set_from_pixbuf(pixbuf) eventbox2.add(image) ty.add(eventbox2) ty.show_all() #window.resize(200,200) size = self.label.size_request() self.rect = rect_class(size[0],size[1]); window.resize(self.rect.x,self.rect.y) print "x: %s, y: %s" % (self.rect.x,self.rect.y) self.height = gtk.gdk.screen_height() self.width = gtk.gdk.screen_width() window.move(self.width-self.rect.x,self.height-self.rect.y) gobject.timeout_add(6000, window.destroy) # simple timeout # to close the balloon after 6 secs self.clipboard = gtk.clipboard_get(gtk.gdk.SELECTION_PRIMARY) self.clipboard.request_text(self.clipboard_text_received) szoveg ="alma" gobject.timeout_add(3000, self.set_label, szoveg) window.show_all(); class rect_class: def __init__(self,x,y): self.x = x self.y = y def main(): gtk.main() return 0 if __name__ == '__main__': program = TrayDemonstration() main() _______________________________________________ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/