Unity 8
 All Classes Functions
hud.py
1 # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2 #
3 # Unity Autopilot Test Suite
4 # Copyright (C) 2012-2013 Canonical
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #
19 
20 from collections import namedtuple
21 
22 from unity8 import get_grid_size
23 from unity8.shell.emulators import UnityEmulatorBase
24 from unity8.shell import DragMixin
25 from autopilot.input import Touch
26 
27 SwipeCoords = namedtuple('SwipeCoords', 'start_x end_x start_y end_y')
28 
29 
30 class Hud(UnityEmulatorBase, DragMixin):
31 
32  """An emulator that understands the Hud."""
33 
34  def show(self):
35  """Swipes open the Hud."""
36  self.touch = Touch.create()
37 
38  window = self.get_root_instance().wait_select_single('QQuickView')
39  hud_show_button = window.wait_select_single("HudButton")
40 
41  swipe_coords = self.get_button_swipe_coords(window, hud_show_button)
42 
43  self.touch.press(swipe_coords.start_x, swipe_coords.start_y)
44  self._drag(
45  swipe_coords.start_x,
46  swipe_coords.start_y,
47  swipe_coords.start_x,
48  swipe_coords.end_y
49  )
50  try:
51  hud_show_button.opacity.wait_for(1.0)
52  self.touch.release()
53  self.shown.wait_for(True)
54  except AssertionError:
55  raise
56  finally:
57  # XXX This ugly code is here just temporarily, waiting for uinput
58  # improvements to land on autopilot so we don't have to access
59  # device private internal attributes. --elopio - 2014-02-12
60  try:
61  pressed = self.touch._touch_finger is not None
62  except AttributeError:
63  pressed = self.touch.pressed
64  if pressed:
65  self.touch.release()
66 
67  def dismiss(self):
68  """Closes the open Hud."""
69  # Ensure that the Hud is actually open
70  self.shown.wait_for(True)
71  touch = Touch.create()
72  x, y = self.get_close_button_coords()
73  touch.tap(x, y)
74  self.y.wait_for(self.height)
75 
77  """Returns the coordinates of the Huds close button bar."""
78  rect = self.globalRect
79  x = int(rect[0] + rect[2] / 2)
80  y = rect[1] + get_grid_size()
81  return x, y
82 
83  def get_button_swipe_coords(self, main_view, hud_show_button):
84  """Returns the coords both start and end x,y for swiping to make the
85  'hud show' button appear.
86  """
87  start_x = int(main_view.x + (main_view.width / 2))
88  end_x = start_x
89  start_y = main_view.y + (main_view.height - 3)
90  end_y = main_view.y + int(
91  hud_show_button.y + (hud_show_button.height/2)
92  )
93 
94  return SwipeCoords(start_x, end_x, start_y, end_y)