@@ -22,35 +22,34 @@ from collections import namedtuple
2222from unity8 import get_grid_size
2323from unity8.shell.emulators import UnityEmulatorBase
2424from autopilot.input import Touch
25−
25+from time import sleep
2626
2727SwipeCoords = namedtuple('SwipeCoords', 'start_x end_x start_y end_y')
2828
29−
3029class Hud(UnityEmulatorBase):
3130
3231 """An emulator that understands the Hud."""
3332
3433 def show(self):
3534 """Swipes open the Hud."""
36− touch = Touch.create()
35+ self.touch = Touch.create()
3736
3837 window = self.get_root_instance().select_single('QQuickView')
3938 hud_show_button = window.select_single("HudButton")
4039
4140 swipe_coords = self.get_button_swipe_coords(window, hud_show_button)
4241
43− touch.press(swipe_coords.start_x, swipe_coords.start_y)
44− touch._finger_move(swipe_coords.end_x, swipe_coords.end_y)
42+ self.touch.press(swipe_coords.start_x, swipe_coords.start_y)
43+ self._drag(swipe_coords.start_x, swipe_coords.start_y, swipe_coords.start_x, swipe_coords.end_y)
4544 try:
4645 hud_show_button.opacity.wait_for(1.0)
47− touch.release()
46+ self.touch.release()
4847 self.shown.wait_for(True)
4948 except AssertionError:
5049 raise
5150 finally:
52− if touch._touch_finger is not None:
53− touch.release()
51+ if self.touch._touch_finger is not None:
52+ self.touch.release()
5453
5554 def dismiss(self):
5655 """Closes the open Hud."""
@@ -78,3 +77,15 @@ class Hud(UnityEmulatorBase):
7877 end_y = main_view.y + int(hud_show_button.y + (hud_show_button.height/2))
7978
8079 return SwipeCoords(start_x, end_x, start_y, end_y)
80+
81+ def _drag(self, x1, y1, x2, y2):
82+ cur_x = x1
83+ cur_y = y1
84+ dx = 1.0 * (x2 - x1) / 100
85+ dy = 1.0 * (y2 - y1) / 100
86+ for i in range(0, 100):
87+ self.touch._finger_move(int(cur_x), int(cur_y))
88+ sleep(0.002)
89+ cur_x += dx
90+ cur_y += dy
91+ self.touch._finger_move(int(x2), int(y2))