2
# Copyright (c) 2010 Canonical
4
# Written by Gustavo Niemeyer <gustavo@niemeyer.net>
6
# This file is part of the Xpresser GUI automation library.
8
# Xpresser is free software; you can redistribute it and/or modify
9
# it under the terms of the GNU Lesser General Public License version 3,
10
# as published by the Free Software Foundation.
12
# Xpresser is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU Lesser General Public License for more details.
17
# You should have received a copy of the GNU Lesser General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
from xpresser.image import Image
27
# pygtk is using a deprecated method from numpy in get_pixels_array().
28
warnings.filterwarnings("ignore", ".*use PyArray_NewFromDescr.*")
32
pyatspi.Registry.generateMouseEvent(x, y, pyatspi.MOUSE_B1C)
34
def right_click(x, y):
35
pyatspi.Registry.generateMouseEvent(x, y, pyatspi.MOUSE_B3C)
37
def double_click(x, y):
38
pyatspi.Registry.generateMouseEvent(x, y, pyatspi.MOUSE_B1D)
41
pyatspi.Registry.generateMouseEvent(x, y, pyatspi.MOUSE_ABS)
44
if string == "<Backspace>":
45
keyval == gtk.keysyms.BackSpace
46
elif string == "<Begin>":
47
keyval = gtk.keysyms.Begin
48
elif string == "<Delete>":
49
keyval = gtk.keysyms.Delete
50
elif string == "<Down>":
51
keyval = gtk.keysyms.Down
52
elif string == "<Escape>":
53
keyval = gtk.keysyms.Escape
54
elif string == "<End>":
55
keyval = gtk.keysyms.End
56
elif string == "<F1>":
57
keyval = gtk.keysyms.F1
58
elif string == "<F2>":
59
keyval = gtk.keysyms.F2
60
elif string == "<F3>":
61
keyval = gtk.keysyms.F3
62
elif string == "<F4>":
63
keyval = gtk.keysyms.F4
64
elif string == "<F5>":
65
keyval = gtk.keysyms.F5
66
elif string == "<F6>":
67
keyval = gtk.keysyms.F6
68
elif string == "<F7>":
69
keyval = gtk.keysyms.F7
70
elif string == "<F8>":
71
keyval = gtk.keysyms.F8
72
elif string == "<F9>":
73
keyval = gtk.keysyms.F9
74
elif string == "<F10>":
75
keyval = gtk.keysyms.F10
76
elif string == "<F11>":
77
keyval = gtk.keysyms.F11
78
elif string == "<F12>":
79
keyval = gtk.keysyms.F12
80
elif string == "<Home>":
81
keyval = gtk.keysyms.Home
82
elif string == "<Insert>":
83
keyval = gtk.keysyms.Insert
84
elif string == "<KP_Down>":
85
keyval = gtk.keysyms.KP_Down
86
elif string == "<KP_Enter>":
87
keyval = gtk.keysyms.KP_Enter
88
elif string == "<KP_Left>":
89
keyval = gtk.keysyms.KP_Left
90
elif string == "<KP_Right>":
91
keyval = gtk.keysyms.KP_Right
92
elif string == 'KP_Space':
93
keyval = gtk.keysyms.KP_Space
94
elif string == "KP_Tab":
95
keyval = gtk.keysyms.KP_Tab
96
elif string == "<KP_Up>":
97
keyval = gtk.keysyms.KP_Up
98
elif string == "<Left>":
99
keyval = gtk.keysyms.Left
100
elif string == "<Page_down>":
101
keyval = gtk.keysyms.Page_Down
102
elif string == "<Page_up>":
103
keyval = gtk.keysyms.Page_Up
104
elif string == "<Return>":
105
keyval = gtk.keysyms.Return
106
elif string == "<Right>":
107
keyval = gtk.keysyms.Right
108
elif string == "<Up>":
109
keyval = gtk.keysyms.Up
110
elif string == "<Tab>":
111
keyval = gtk.keysyms.Tab
115
keyval = gtk.gdk.unicode_to_keyval(ord(char))
117
pyatspi.Registry.generateKeyboardEvent(keyval, None, pyatspi.KEY_SYM)
119
def take_screenshot(x=0, y=0, width=None, height=None):
120
window = gtk.gdk.get_default_root_window()
121
if not (width and height):
122
size = window.get_size()
127
pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, width, height)
128
pixbuf = pixbuf.get_from_drawable(window, window.get_colormap(),
129
x, y, 0, 0, width, height)
130
array = pixbuf.get_pixels_array()
131
return Image("screenshot", array=array,
132
width=array.shape[1], height=array.shape[0])