List Info

Thread: PIL ImageGrab clipboard block




PIL ImageGrab clipboard block
country flaguser name
Germany
2007-04-14 11:32:22
Hi List,

I'm currently using the ImageGrab module of PIL for a small
image upload 
client. I've noticed that the ImageGrab.grabclipboard()
method seems to 
somehow block the clipboard. I'll try to explain:

This is what works: When the Windows clipboard contains
image data when 
first trying to use ImageGrab.grabclipboard() it works as
supposed. You 
can further change the clipboard contents (copy image data
from another 
application) and reinvoke ImageGrab.grabclipboard() to fetch
the new data.

And this is what doesn't work: When the windows clipboard
contains text 
  (or nothing) when trying to use ImageGrab.grabclipboard(),
any 
subsequent calls to ImageGrab.grabclipboard() fail. AND it
seems as if 
the clipboard was blocked, i.e. none of my graphical apps is
able to 
copy image data to the clipboard until my upload client is
finished.

This minimal loop can be used to test the behavior:

import Image, ImageGrab
while True:
     img = ImageGrab.grabclipboard()
     if isinstance(img, Image.Image):
         print "Found Image"
     else:
         print "No Image"
     print "Press Enter to continue...",
     raw_input()

I'd love to see a way to "reset" the clipboard or
fix my app to be able 
to paste image data even if the clipboard was empty or just
contained 
text on startup.


Thanks in advance,
Ole Trenner
_______________________________________________
Image-SIG maillist  -  Image-SIGpython.org
htt
p://mail.python.org/mailman/listinfo/image-sig

Re: PIL ImageGrab clipboard block
user name
2007-04-14 11:56:42
On 4/14/07, Ole Trenner <ole.trennergmx.de> wrote:
> Hi List,
>
> I'm currently using the ImageGrab module of PIL for a
small image upload
> client. I've noticed that the ImageGrab.grabclipboard()
method seems to
> somehow block the clipboard.

This is a bug, you can use this patch to fix that:

diff -ruN Imaging-1.1.6-orig/display.c
Imaging-1.1.6/display.c
--- Imaging-1.1.6-orig/display.c	Sun Dec  3 14:51:25 2006
+++ Imaging-1.1.6/display.c	Sat Apr 14 20:54:37 2007
 -496,6
+496,7 
     if (!handle) {
         /* FIXME: add CF_HDROP support to allow
cut-and-paste from
            the explorer */
+        CloseClipboard();
         Py_INCREF(Py_None);
         return Py_None;
     }

Best regards,
Alexey.
_______________________________________________
Image-SIG maillist  -  Image-SIGpython.org
htt
p://mail.python.org/mailman/listinfo/image-sig

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )