Merge lp:~xpresser-team/xpresser/xpresser-with-special-keys into lp:xpresser

Proposed by Chris Wayne
Status: Merged
Merged at revision: 13
Proposed branch: lp:~xpresser-team/xpresser/xpresser-with-special-keys
Merge into: lp:xpresser
Diff against target: 194 lines (+97/-9)
7 files modified
debian/changelog (+26/-0)
debian/control (+5/-3)
debian/copyright (+17/-5)
debian/watch (+3/-0)
setup.py (+1/-1)
xpresser/tests/test_xutils.py (+13/-0)
xpresser/xutils.py (+32/-0)
To merge this branch: bzr merge lp:~xpresser-team/xpresser/xpresser-with-special-keys
Reviewer Review Type Date Requested Status
Chris Gagnon (community) Approve
Review via email: mp+121060@code.launchpad.net

Description of the change

Adding in special key support!

To post a comment you must log in.
24. By Chris Wayne

Adding in Enter key per Chris Gagnon's request

Revision history for this message
Chris Gagnon (chris.gagnon) wrote :

the keycode for enter is 28

review: Needs Fixing
Revision history for this message
Chris Wayne (cwayne) wrote :

Using 28 makes it type a 't'

Revision history for this message
Chris Gagnon (chris.gagnon) wrote :

The keycode is correct, enter is not 28... showkey does not return the correct value, xev does.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2012-07-05 13:52:37 +0000
3+++ debian/changelog 2012-08-23 17:34:19 +0000
4@@ -1,3 +1,29 @@
5+xpresser (1.1.3) precise; urgency=low
6+
7+ * Adding in special key support
8+
9+ [Chris Gagnon]
10+ * reversed keys_to_press for key release so things like ctrl-alt-
11+ backspace wont delete a typed key
12+
13+ [Chris Wayne]
14+ * Fixed sleep after each key press
15+ * Added some more special keys (all F keys, Function, and others)
16+
17+ -- Chris Wayne <chris.wayne@canonical.com> Sat, 18 Aug 2012 14:36:12 -0400
18+
19+xpresser (1.1.2) precise; urgency=low
20+
21+ * Small fix
22+
23+ -- Chris Wayne <chris.wayne@canonical.com> Thu, 19 Jul 2012 21:01:24 -0400
24+
25+xpresser (1.1.1) precise; urgency=low
26+
27+ * Adding in python-gi-cairo as a build dependency
28+
29+ -- Chris Wayne <chris.wayne@canonical.com> Thu, 19 Jul 2012 20:29:24 -0400
30+
31 xpresser (1.1) precise; urgency=low
32
33 * Initial Precise release into Xpresser PPA
34
35=== modified file 'debian/control'
36--- debian/control 2012-07-05 15:56:48 +0000
37+++ debian/control 2012-08-23 17:34:19 +0000
38@@ -1,12 +1,14 @@
39 Source: xpresser
40 Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
41-XSBC-Original-Maintainer: Xpresser Team <xpresser-team@lists.canonical.com>
42 Section: python
43-Priority: optional
44+Priority: extra
45 Build-Depends: python-all (>= 2.6.6-3), debhelper (>= 9)
46 Standards-Version: 3.9.3
47
48 Package: python-xpresser
49 Architecture: all
50-Depends: ${misc:Depends}, ${python:Depends}, python-opencv, python-pyatspi2, python-numpy, python-simplecv
51+Depends: ${misc:Depends}, ${python:Depends}, python-opencv, python-pyatspi2, python-numpy, python-simplecv, python-gi-cairo
52 Description: Python library to script Graphic User Interfaces.
53+ Xpresser is a python library to automate GUI testing. It uses screenshot matching
54+ to make automation easy, and can emulate actual user testing, rather than through
55+ introspection.
56
57=== modified file 'debian/copyright'
58--- debian/copyright 2012-07-05 15:56:48 +0000
59+++ debian/copyright 2012-08-23 17:34:19 +0000
60@@ -1,11 +1,23 @@
61-Format: http://dep.debian.net/deps/dep5
62+Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
63 Upstream-Name: python-xpresser
64 Source: http://bazaar.launchpad.net/~xpresser-team/xpresser
65
66 Files: *
67 Copyright: 2012 Canonical Ltd.
68-License: LGPL-3.0
69+License: LGPL-3
70
71-Files: debian/*
72-Copyright: 2012 Canonical Ltd.
73-License: LGPL-3.0
74+License: LGPL-3
75+ This program is free software: you can redistribute it and/or modify
76+ it under the terms of the GNU Lesser General Public License as published by
77+ the Free Software Foundation, version 3 of the License.
78+ .
79+ This program is distributed in the hope that it will be useful,
80+ but WITHOUT ANY WARRANTY; without even the implied warranty of
81+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
82+ GNU Lesser General Public License for more details.
83+ .
84+ You should have received a copy of the GNU Lesser General Public License
85+ along with this program. If not, see <http://www.gnu.org/licenses/>.
86+ .
87+ On Debian systems, the full text of the GNU Lesser General Public License
88+ version 3 can be found in the file /usr/share/common-licenses/LGPL-3.
89
90=== added file 'debian/watch'
91--- debian/watch 1970-01-01 00:00:00 +0000
92+++ debian/watch 2012-08-23 17:34:19 +0000
93@@ -0,0 +1,3 @@
94+version=3
95+http://launchpad.net/xpresser/+download .*/Xpresser-(.+)\.tar\.gz
96+
97
98=== added directory 'dist'
99=== added file 'dist/Xpresser-1.1.tar.gz'
100Binary files dist/Xpresser-1.1.tar.gz 1970-01-01 00:00:00 +0000 and dist/Xpresser-1.1.tar.gz 2012-08-23 17:34:19 +0000 differ
101=== modified file 'setup.py'
102--- setup.py 2010-07-22 14:04:17 +0000
103+++ setup.py 2012-08-23 17:34:19 +0000
104@@ -3,7 +3,7 @@
105 from distutils.core import setup
106
107 setup(name='Xpresser',
108- version='1.0',
109+ version='1.1',
110 description='Python library to script Graphic User Interfaces.',
111 author='Gustavo Niemeyer',
112 author_email='gustavo.niemeyer@canonical.com',
113
114=== modified file 'xpresser/tests/test_xutils.py'
115--- xpresser/tests/test_xutils.py 2012-05-21 19:57:09 +0000
116+++ xpresser/tests/test_xutils.py 2012-08-23 17:34:19 +0000
117@@ -86,6 +86,19 @@
118 finally:
119 window.destroy()
120
121+ def test_type_special(self):
122+ entry = Gtk.Entry()
123+ window = self.create_window(entry)
124+ try:
125+ window.present()
126+ entry.grab_focus()
127+ self.flush_gtk()
128+ xutils.type(["<Shift>", "hi there"])
129+ self.flush_gtk()
130+ self.assertEquals(entry.get_text(), "HI THERE")
131+ finally:
132+ window.destroy()
133+
134 def test_take_screenshot(self):
135 """Verify that take_screenshot works, with a real screenshot.
136
137
138=== modified file 'xpresser/xutils.py'
139--- xpresser/xutils.py 2012-05-21 19:57:09 +0000
140+++ xpresser/xutils.py 2012-08-23 17:34:19 +0000
141@@ -19,10 +19,19 @@
142 #
143 import pyatspi
144 import SimpleCV
145+import types
146+import time
147 from xpresser.image import Image
148 from tempfile import NamedTemporaryFile
149 from gi.repository import Gdk
150
151+specialkeys = {'<Ctrl>' : 37, "<Shift>" : 50, "<Alt>" : 64, "<Meta>" : 133,
152+ '<Tab>' : 23, '<Super>' : 133, '<Fn>' : 151, '<PgUp>' : 112,
153+ '<PgDn>' : 117, '<Delete>' : 119, '<Home>' : 110, '<Esc>' : 9,
154+ '<F1>' : 67, '<F2>' : 68, '<F3>' : 69, '<F4>' : 70, '<F5>' : 71,
155+ '<F6>' : 72, '<F7>' : 73, '<F8>' : 74, '<F9>' : 75, '<F10>' : 76,
156+ '<F11>' : 95, '<F12>' : 96, '<Enter>' : 36}
157+
158
159 def click(x, y):
160 pyatspi.Registry.generateMouseEvent(x, y, pyatspi.MOUSE_B1C)
161@@ -37,10 +46,33 @@
162 pyatspi.Registry.generateMouseEvent(x, y, pyatspi.MOUSE_ABS)
163
164 def type(string):
165+ if isinstance(string, types.ListType):
166+ keys_to_press = []
167+ for string_part in string:
168+ if string_part in specialkeys:
169+ keys_to_press.append(specialkeys[string_part])
170+ __press_key(keys_to_press[-1])
171+ else:
172+ __type_standard(string_part)
173+ keys_to_press.reverse()
174+ #hold the key long enough to constitute a hold, not a tap
175+ time.sleep(.4)
176+ for keys in keys_to_press:
177+ __release_key(keys)
178+ else:
179+ __type_standard(string)
180+
181+def __type_standard(string):
182 for char in string:
183 keyval = Gdk.unicode_to_keyval(ord(char))
184 pyatspi.Registry.generateKeyboardEvent(keyval, None, pyatspi.KEY_SYM)
185
186+def __press_key(keycode):
187+ pyatspi.Registry.generateKeyboardEvent(keycode, None, pyatspi.KEY_PRESS)
188+
189+def __release_key(keycode):
190+ pyatspi.Registry.generateKeyboardEvent(keycode, None, pyatspi.KEY_RELEASE)
191+
192 def take_screenshot():
193 window = Gdk.get_default_root_window()
194 surface = Gdk.cairo_create(window).get_target()

Subscribers

People subscribed via source and target branches

to all changes: