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