Unity 8
 All Classes Functions
main_window.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, 2014 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 import logging
21 
22 from autopilot import logging as autopilot_logging
23 from autopilot import input
24 
25 from unity8.shell import emulators
26 from unity8.shell.emulators.greeter import Greeter
27 from unity8.shell.emulators.hud import Hud
28 from unity8.shell.emulators.launcher import Launcher
29 
30 logger = logging.getLogger(__name__)
31 
32 
34  """An emulator class that makes it easy to interact with the shell"""
35 
36  def get_greeter(self):
37  return self.select_single(Greeter)
38 
39  def get_greeter_content_loader(self):
40  return self.wait_select_single(
41  "QQuickLoader",
42  objectName="greeterContentLoader"
43  )
44 
45  def get_login_loader(self):
46  return self.select_single("QQuickLoader", objectName="loginLoader")
47 
48  def get_login_list(self):
49  return self.select_single("LoginList")
50 
51  def get_hud(self):
52  return self.select_single(Hud)
53 
54  def get_hud_showable(self):
55  return self.select_single("Showable", objectName="hudShowable")
56 
57  def get_hud_show_button(self):
58  return self.select_single("HudButton")
59 
60  def get_hud_edge_drag_area(self):
61  return self.select_single(objectName="hudDragArea")
62 
63  def get_bottombar(self):
64  return self.select_single("Bottombar")
65 
66  def get_pinPadLoader(self):
67  return self.select_single(
68  "QQuickLoader",
69  objectName="pinPadLoader"
70  )
71 
72  def get_lockscreen(self):
73  return self.select_single("Lockscreen")
74 
75  def get_pinentryField(self):
76  return self.select_single(objectName="pinentryField")
77 
78  def _get_indicator_panel_item(self, indicator_name):
79  return self.select_single(
80  'IndicatorItem',
81  objectName=indicator_name+'-panelItem'
82  )
83 
84  def _get_indicator_page(self, indicator_name):
85  return self.select_single(
86  'IndicatorPage',
87  objectName=indicator_name+'-page'
88  )
89 
90  @autopilot_logging.log_action(logger.info)
91  def open_indicator_page(self, indicator_name):
92  """Swipe to open the indicator, wait until it's open.
93 
94  :returns: The indicator page.
95  """
96  widget = self._get_indicator_panel_item(indicator_name)
97  start_x, start_y = input.get_center_point(widget)
98  end_x = start_x
99  end_y = self.height
100  self.pointing_device.drag(start_x, start_y, end_x, end_y)
101  self.wait_select_single('IndicatorsMenu', fullyOpened=True)
102  return self._get_indicator_page(indicator_name)
103 
104  @autopilot_logging.log_action(logger.info)
105  def show_dash_swiping(self):
106  """Show the dash swiping from the left."""
107  x, y, width, height = self._get_shell().globalRect
108  start_x = x
109  end_x = x + width
110  start_y = end_y = y + height // 2
111 
112  self.pointing_device.drag(start_x, start_y, end_x, end_y)
113  self.get_current_focused_app_id().wait_for('unity8-dash')
114 
115  def _get_shell(self):
116  return self.select_single('Shell')
117 
119  """Return the id of the focused application."""
120  return self._get_shell().focusedApplicationId
121 
122  @autopilot_logging.log_action(logger.info)
124  """Open the dash clicking the dash icon on the launcher."""
125  launcher = self.open_launcher()
126  launcher.click_dash_icon()
127  self.get_current_focused_app_id().wait_for('unity8-dash')
128  launcher.shown.wait_for(False)
129 
130  @autopilot_logging.log_action(logger.info)
131  def open_launcher(self):
132  launcher = self._get_launcher()
133  launcher.show()
134  return launcher
135 
136  def _get_launcher(self):
137  return self.select_single(Launcher)
138 
139  def is_launcher_open(self):
140  return self._get_launcher().shown
141 
142  @autopilot_logging.log_action(logger.info)
143  def launch_application(self, application_name):
144  """Launch an application.
145 
146  :parameter application_name: The name of the application to launch.
147 
148  """
149  launcher = self.open_launcher()
150  launcher.click_application_launcher_icon(application_name)
151  self.get_current_focused_app_id().wait_for(application_name)
152  launcher.shown.wait_for(False)
153 
154  def enter_pin_code(self, code):
155  """Enter code 'code' into the single-pin lightdm pincode entry screen.
156 
157  :param code: must be a string of numeric characters.
158  :raises: TypeError if code is not a string.
159  :raises: ValueError if code contains non-numeric characters.
160 
161  """
162  if not isinstance(code, str):
163  raise TypeError(
164  "'code' parameter must be a string, not %r."
165  % type(code)
166  )
167  for num in code:
168  if not num.isdigit():
169  raise ValueError(
170  "'code' parameter contains non-numeric characters."
171  )
172  self.pointing_device.click_object(
173  self._get_pinpad_button(int(num)))
174 
175  def _get_pinpad_button(self, button_id):
176  return self.select_single(
177  'PinPadButton',
178  objectName='pinPadButton{}'.format(button_id)
179  )