views:

144

answers:

1

Hi! I was wondering how to make a simple Clipboard Monitor in python, for GUI I'm using PyGTK. I found gtk.clipboard class and all that but I couldn't find any solution to get the "signals" to trigger the event when the clipboard content has changed :(

Any ideas?

Thanks you! :)

A: 

Without a proper notification API, such as WM_DrawClipboard messages, you would probably have to resort to a polling loop. And then you will cause major conflicts with other apps that are trying to use this shared resource.
Do not resort to a polling loop.

Chris Thornton
I agree in general, notification is better, and I haven't down-voted, but polling loops are not inherently bad: what about one that runs once every 5 seconds? That should be enough to monitor a clipboard.
Ali A
@Ali - polling will introduce collisions with the app that the user is trying to copy data from. When you highlight some text and press Ctrl+C, the app assumes that it can use the clipboard. But if another app has it open for inspection, you'll get "cannot open clipboard" errors. Or crashes, if that condition isn't handled gracefully.Furthermore, when relying on polling, the only way to really know if the data has changed, is to paste that data into a buffer. That will trigger any delayed rendering that's waiting to occur.
Chris Thornton