@@ -0,0 +1,52 @@
1+from unity8.shell.emulators import Unity8EmulatorBase
2+from autopilot.input import Touch
3+
4+class Hud(Unity8EmulatorBase):
5+
6+ """An emulator that understands the Hud."""
7+
8+ def show(self):
9+ """Swipes open the Hud."""
10+ # Todo: assumes the hud is ready and able to be swiped open. Need to
11+ # check if it's availble before even attempting.
12+ touch = Touch.create()
13+
14+ window = self.get_root_instance().select_single('QQuickView')
15+ hud_show_button = window.select_single("HudButton")
16+
17+ start_x = int(window.x + (window.width / 2))
18+ end_x = start_x
19+ # start_y = window.y + (window.height - 3)
20+ start_y = window.y + window.height
21+ end_y = int(hud_show_button.y + (hud_show_button.height/2))
22+
23+ touch.press(start_x, start_y)
24+ touch._finger_move(end_x, end_y)
25+ try:
26+ hud_show_button.opacity.wait_for(1.0)
27+ touch.release()
28+ self.shown.wait_for(True)
29+ except AssertionError:
30+ raise
31+ finally:
32+ if touch._touch_finger is not None:
33+ touch.release()
34+
35+ def dismiss(self):
36+ """Closes the open Hud."""
37+ # Ensure that the Hud is actually open
38+ self.shown.wait_for(True)
39+ touch = Touch.create()
40+ x, y = self.get_close_button_coords()
41+ touch.tap(x, y)
42+
43+ # TODO: Should grid_size be passed in or should we have a get_grid_size in
44+ # unity8.__init__ that reads it from the env.
45+ # Yeah I think so as it doesn't seem to make sense when passing it in.
46+ # Plus as above shows, we don't always have it.
47+ def get_close_button_coords(self, grid_size):
48+ """Returns the coordinates of the Huds close button bar."""
49+ rect = self.globalRect
50+ x = int(rect[0] + rect[2] / 2)
51+ y = rect[1] + grid_size
52+ return x, y