Image grab in Python

David wizzardx at gmail.com
Sun May 4 13:33:49 EDT 2008


On Sun, May 4, 2008 at 5:28 PM, Valerio Valerio <vdv100 at gmail.com> wrote:
> I can grab the image,  I need a way of grab the region size with the mouse,
> a easy way of the user select a region of the image to analyze, something
> like the  "Rectangle selection tool" of gimp.
>

I assume what you want to do is allow the user to drag the mouse
across your desktop, and your program, running in the background,
picks this up? As opposed to the user making a rectangular selection
entirely within your app.

I think the simplest way to do this is to capture the entire screen,
then show it as an image on a window covering the entire screen (eg:
fullscreen mode, or a regular window without decorations).  Then
listen for mouse events. There should be a way to show the 'rectangle
elastic band' at the same time. Otherwise just draw a rectangle
between where the user first clicked and where the mouse is now (until
they release the mouse button).

Another way would be to listen to all events sent through X, and act
based on the mouse events. VNC does something similar.

A good starting point would be the Python xlib libraries:

http://python-xlib.sourceforge.net/

David.



More information about the Python-list mailing list