~xpresser-team/xpresser/xpresser-type-with-hold

« back to all changes in this revision

Viewing changes to xpresser/xutils.py

  • Committer: Gustavo Niemeyer
  • Date: 2010-05-16 22:59:48 UTC
  • Revision ID: gustavo@niemeyer.net-20100516225948-hm96jar095u9jhm2
Creating branch with initial version of Xpresser.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from xpresser.image import Image
 
2
 
 
3
import pyatspi
 
4
import gtk
 
5
 
 
6
import warnings
 
7
 
 
8
# pygtk is using a deprecated method from numpy in get_pixels_array().
 
9
warnings.filterwarnings("ignore", ".*use PyArray_NewFromDescr.*")
 
10
 
 
11
 
 
12
def click(x, y):
 
13
    pyatspi.Registry.generateMouseEvent(x, y, pyatspi.MOUSE_B1C)
 
14
 
 
15
def hover(x, y):
 
16
    pyatspi.Registry.generateMouseEvent(x, y, pyatspi.MOUSE_ABS)
 
17
 
 
18
def take_screenshot(x=0, y=0, width=None, height=None):
 
19
    window = gtk.gdk.get_default_root_window()
 
20
    if not (width and height):
 
21
        size = window.get_size()
 
22
        if not width:
 
23
            width = size[0]
 
24
        if not height:
 
25
            height = size[1]
 
26
    pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, width, height)
 
27
    pixbuf = pixbuf.get_from_drawable(window, window.get_colormap(),
 
28
                                      x, y, 0, 0, width, height)
 
29
    array = pixbuf.get_pixels_array()
 
30
    return Image("screenshot", array=array,
 
31
                 width=array.shape[1], height=array.shape[0])