Merge lp:~cwayne/xpresser/xpresser-double-click into lp:~niemeyer/xpresser/trunk

Proposed by Chris Wayne
Status: Merged
Merged at revision: 10
Proposed branch: lp:~cwayne/xpresser/xpresser-double-click
Merge into: lp:~niemeyer/xpresser/trunk
Diff against target: 188 lines (+68/-6)
4 files modified
xpresser/tests/test_xp.py (+41/-3)
xpresser/tests/test_xutils.py (+14/-3)
xpresser/xp.py (+10/-0)
xpresser/xutils.py (+3/-0)
To merge this branch: bzr merge lp:~cwayne/xpresser/xpresser-double-click
Reviewer Review Type Date Requested Status
Gustavo Niemeyer Pending
Review via email: mp+85175@code.launchpad.net

Description of the change

Add support for double clicking.

https://codereview.appspot.com/5485056/

To post a comment you must log in.
Revision history for this message
Chris Wayne (cwayne) wrote :

Reviewers: mp+85175_code.launchpad.net,

Message:
Please take a look.

Description:
Added double click funcitonality

https://code.launchpad.net/~cwayne18/xpresser/xpresser-double-click/+merge/85175

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/5485056/

Affected files:
   M xpresser/xp.py
   M xpresser/xutils.py

Index: xpresser/xp.py
=== <email address hidden> >
<email address hidden>
=== modified file 'xpresser/xp.py'
--- xpresser/xp.py 2010-11-08 14:38:23 +0000
+++ xpresser/xp.py 2011-12-09 18:35:34 +0000
@@ -76,6 +76,16 @@
              xp.right_click(x, y)
          """
          xutils.right_click(*self._compute_focus_point(args))
+
+ def double_click(self, *args):
+ '''Double clicks over the position specified by arguments
+
+ The following examples show valid ways of specifying te position:
+ xp.double_click("image-name")
+ xp.double_click(image_match)
+ xp.double_click(x, y)
+ '''
+ xutils.double_click(*self._compute_focus_point(args))

      def hover(self, *args):
          """Hover over the position specified by the provided arguments.

Index: xpresser/xutils.py
=== <email address hidden> >
<email address hidden>
=== modified file 'xpresser/xutils.py'
--- xpresser/xutils.py 2010-11-04 22:14:59 +0000
+++ xpresser/xutils.py 2011-12-09 18:35:34 +0000
@@ -34,6 +34,9 @@
  def right_click(x, y):
      pyatspi.Registry.generateMouseEvent(x, y, pyatspi.MOUSE_B3C)

+def double_click(x, y):
+ pyatspi.Registry.generateMouseEvent(x, y, pyatspi.MOUSE_B1D)
+
  def hover(x, y):
      pyatspi.Registry.generateMouseEvent(x, y, pyatspi.MOUSE_ABS)

Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

This looks fine, but it'd be nice to have some tests. As per the IRC
conversation:

<niemeyer> cwayne: Is there any chance we could have a test for that?
<niemeyer> cwayne: Should be very easy to introduce one
<niemeyer> cwayne: Check out test_xutils.py and test_xp.py
<niemeyer> cwayne: Search for right_click

https://codereview.appspot.com/5485056/

11. By Chris Wayne

added tests

12. By Chris Wayne

fixed small (re: stupid) erros in double click test

13. By Chris Wayne

small fix

14. By Chris Wayne

have it look for _2BUTTON_PRESS before regular, since doubleclicking sends both

15. By Chris Wayne

 took self.destroy_window() out of click method, and added it to the end of each test that needs it. no reason it should be killed when theres a click necessarily, but it does need to be killed between tests

Revision history for this message
Chris Wayne (cwayne) wrote :
Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

*** Submitted:

Add support for double clicking.

R=niemeyer
CC=
https://codereview.appspot.com/5485056

https://codereview.appspot.com/5485056/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'xpresser/tests/test_xp.py'
2--- xpresser/tests/test_xp.py 2010-11-08 14:38:23 +0000
3+++ xpresser/tests/test_xp.py 2011-12-13 23:58:23 +0000
4@@ -71,13 +71,15 @@
5 self.button_clicked = False
6 self.button_rclicked = False
7 self.button_hovered = False
8-
9+ self.button_dclicked = False
10+
11 def clicked(widget, event):
12- if event.button == 1:
13+ if event.button == 1 and event.type == gtk.gdk._2BUTTON_PRESS:
14+ self.button_dclicked = True
15+ elif event.button == 1 and event.type == gtk.gdk.BUTTON_PRESS:
16 self.button_clicked = True
17 elif event.button == 3:
18 self.button_rclicked = True
19- self.window.destroy()
20
21 def entered(widget):
22 self.button_hovered = True
23@@ -148,6 +150,7 @@
24 self.xp.click(*self.get_button_center())
25 self.flush_gtk()
26 self.assertTrue(self.button_clicked)
27+ self.window.destroy()
28
29 def test_hover_position(self):
30 self.xp.hover(*self.get_button_center())
31@@ -159,11 +162,19 @@
32 self.xp.click("red-square")
33 self.flush_gtk()
34 self.assertTrue(self.button_clicked)
35+ self.window.destroy()
36
37 def test_right_click_image_name(self):
38 self.xp.right_click("red-square")
39 self.flush_gtk()
40 self.assertTrue(self.button_rclicked)
41+ self.window.destroy()
42+
43+ def test_double_click_image_name(self):
44+ self.xp.double_click("red-square")
45+ self.flush_gtk()
46+ self.assertTrue(self.button_dclicked)
47+ self.window.destroy()
48
49 def test_hover_image_name(self):
50 self.xp.hover("red-square")
51@@ -176,12 +187,21 @@
52 self.xp.click(match)
53 self.flush_gtk()
54 self.assertTrue(self.button_clicked)
55+ self.window.destroy()
56
57 def test_right_click_image_match(self):
58 match = self.xp.find("red-square")
59 self.xp.right_click(match)
60 self.flush_gtk()
61 self.assertTrue(self.button_rclicked)
62+ self.window.destroy()
63+
64+ def test_double_click_image_match(self):
65+ match = self.xp.find("red-square")
66+ self.xp.double_click(match)
67+ self.flush_gtk()
68+ self.assertTrue(self.button_dclicked)
69+ self.window.destroy()
70
71 def test_hover_image_match(self):
72 match = self.xp.find("red-square")
73@@ -204,6 +224,7 @@
74 self.assertTrue(time.time() - started > SLEEP_DELAY)
75 self.flush_gtk()
76 self.assertTrue(self.button_clicked)
77+ self.window.destroy()
78
79 def test_right_click_waits(self):
80 self.window.hide()
81@@ -219,6 +240,23 @@
82 self.assertTrue(time.time() - started > SLEEP_DELAY)
83 self.flush_gtk()
84 self.assertTrue(self.button_rclicked)
85+ self.window.destroy()
86+
87+ def test_double_click_waits(self):
88+ self.window.hide()
89+ self.flush_gtk()
90+ def show_window():
91+ time.sleep(SLEEP_DELAY)
92+ self.window.show()
93+ self.flush_gtk()
94+ thread = threading.Thread(target=show_window)
95+ started = time.time()
96+ thread.start()
97+ self.xp.double_click("red-square")
98+ self.assertTrue(time.time() - started > SLEEP_DELAY)
99+ self.flush_gtk()
100+ self.assertTrue(self.button_dclicked)
101+ self.window.destroy()
102
103 def test_hover_waits(self):
104 self.window.hide()
105
106=== modified file 'xpresser/tests/test_xutils.py'
107--- xpresser/tests/test_xutils.py 2010-11-08 14:38:23 +0000
108+++ xpresser/tests/test_xutils.py 2011-12-13 23:58:23 +0000
109@@ -150,14 +150,16 @@
110 self.button_clicked = False
111 self.button_rclicked = False
112 self.button_hovered = False
113+ self.button_dclicked = False
114
115 def clicked(widget, event):
116- if event.button == 1:
117+ if event.button == 1 and event.type == gtk.gdk._2BUTTON_PRESS:
118+ self.button_dclicked = True
119+ elif event.button == 1 and event.type == gtk.gdk.BUTTON_PRESS:
120 self.button_clicked = True
121 elif event.button == 3:
122 self.button_rclicked = True
123- self.window.destroy()
124-
125+
126 def entered(widget):
127 self.button_hovered = True
128
129@@ -173,16 +175,25 @@
130 button_x, button_y = self.button.window.get_position()
131 button_width, button_height = self.button.window.get_size()
132 return (button_x + button_width//2, button_y + button_height//2)
133+ self.window.destroy()
134
135 def test_click(self):
136 xutils.click(*self.get_button_center())
137 self.flush_gtk()
138 self.assertTrue(self.button_clicked)
139+ self.window.destroy()
140
141 def test_right_click(self):
142 xutils.right_click(*self.get_button_center())
143 self.flush_gtk()
144 self.assertTrue(self.button_rclicked)
145+ self.window.destroy()
146+
147+ def test_double_click(self):
148+ xutils.double_click(*self.get_button_center())
149+ self.flush_gtk()
150+ self.assertTrue(self.button_dclicked)
151+ self.window.destroy()
152
153 def test_hover(self):
154 xutils.hover(*self.get_button_center())
155
156=== modified file 'xpresser/xp.py'
157--- xpresser/xp.py 2010-11-08 14:38:23 +0000
158+++ xpresser/xp.py 2011-12-13 23:58:23 +0000
159@@ -76,6 +76,16 @@
160 xp.right_click(x, y)
161 """
162 xutils.right_click(*self._compute_focus_point(args))
163+
164+ def double_click(self, *args):
165+ '''Double clicks over the position specified by arguments
166+
167+ The following examples show valid ways of specifying te position:
168+ xp.double_click("image-name")
169+ xp.double_click(image_match)
170+ xp.double_click(x, y)
171+ '''
172+ xutils.double_click(*self._compute_focus_point(args))
173
174 def hover(self, *args):
175 """Hover over the position specified by the provided arguments.
176
177=== modified file 'xpresser/xutils.py'
178--- xpresser/xutils.py 2010-11-04 22:14:59 +0000
179+++ xpresser/xutils.py 2011-12-13 23:58:23 +0000
180@@ -34,6 +34,9 @@
181 def right_click(x, y):
182 pyatspi.Registry.generateMouseEvent(x, y, pyatspi.MOUSE_B3C)
183
184+def double_click(x, y):
185+ pyatspi.Registry.generateMouseEvent(x, y, pyatspi.MOUSE_B1D)
186+
187 def hover(x, y):
188 pyatspi.Registry.generateMouseEvent(x, y, pyatspi.MOUSE_ABS)
189

Subscribers

People subscribed via source and target branches