24 from autopilot
import logging
as autopilot_logging
25 from autopilot.introspection
import dbus
26 from testtools.matchers
import MatchesAny, Equals
27 from ubuntuuitoolkit
import emulators
as toolkit_emulators
30 logger = logging.getLogger(__name__)
34 """An emulator that understands the Dash."""
39 'QQuickListView', objectName=
'dashContentList')
41 def get_applications_grid(self):
42 get_grid = self.
get_scope(
'clickscope').wait_select_single(
43 'CardFilterGrid', objectName=
'local')
47 """Returns a 'Tile' icon that has the text 'text' from the application
50 :param text: String containing the text of the icon to search for.
54 resp_grid = app_grid.wait_select_single(
'ResponsiveGridView')
55 return resp_grid.select_single(
'Tile', text=text)
57 def get_scope(self, scope_name='clickscope'):
58 return self.dash_content_list.select_single(
59 'QQuickLoader', scopeId=scope_name)
61 @autopilot_logging.log_action(logger.info)
65 :parameter scope_id: The id of the scope.
70 if scope_loader.isCurrent:
71 logger.info(
'The scope is already open.')
76 def _get_scope_loader(self, scope_id):
78 return self.dash_content_list.select_single(
79 'QQuickLoader', scopeId=scope_id)
80 except dbus.StateNotFoundError:
82 'No scope found with id {0}'.format(scope_id))
84 def _get_scope_from_loader(self, loader):
85 return loader.get_children()[0]
87 def _open_scope_scrolling(self, scope_loader):
90 while not scope_loader.isCurrent:
92 self.dash_content_list.moving.wait_for(
False)
95 scope.isCurrent.wait_for(
True)
98 def _get_scroll_direction(self, scope_loader):
99 current_scope_loader = self.dash_content_list.select_single(
100 'QQuickLoader', isCurrent=
True)
101 if scope_loader.globalRect.x < current_scope_loader.globalRect.x:
103 elif scope_loader.globalRect.x > current_scope_loader.globalRect.x:
108 @autopilot_logging.log_action(logger.info)
109 def _scroll_to_left_scope(self):
110 original_index = self.dash_content_list.currentIndex
114 border = page_header.select_single(
'QQuickBorderImage')
115 start_x = border.width / 3
116 stop_x = border.width / 3 * 2
117 start_y = stop_y = border.globalRect.y + border.height / 2
118 self.pointing_device.drag(start_x, start_y, stop_x, stop_y)
119 self.dash_content_list.currentIndex.wait_for(original_index - 1)
121 def _get_page_header(self):
122 return self.select_single(
'PageHeader', objectName=
'pageHeader')
124 @autopilot_logging.log_action(logger.info)
125 def _scroll_to_right_scope(self):
126 original_index = self.dash_content_list.currentIndex
130 border = page_header.select_single(
'QQuickBorderImage')
131 start_x = border.width / 3 * 2
132 stop_x = border.width / 3
133 start_y = stop_y = border.globalRect.y + border.height / 2
134 self.pointing_device.drag(start_x, start_y, stop_x, stop_y)
135 self.dash_content_list.currentIndex.wait_for(original_index + 1)
137 def enter_search_query(self, query):
139 search_text_field.write(query)
140 search_text_field.state.wait_for(
'idle')
142 def _get_search_text_field(self):
144 search_container = page_header.select_single(
145 'QQuickItem', objectName=
'searchContainer')
146 search_container.state.wait_for(
147 MatchesAny(Equals(
'narrowActive'), Equals(
'active')))
148 return search_container.select_single(toolkit_emulators.TextField)
152 """Autopilot emulator for generic scopes."""
154 @autopilot_logging.log_action(logger.info)
156 """Open the preview of an application.
158 :parameter category: The name of the category where the application is.
159 :app_name: The name of the application.
160 :return: The opened preview.
164 icon = category_element.select_single(
'Card', title=app_name)
168 self.pointing_device.click_object(icon)
169 preview_list = self.get_root_instance().wait_select_single(
170 'PreviewListView', objectName=
'dashContentPreviewList')
171 preview_list.x.wait_for(0)
172 return preview_list.select_single(
173 Preview, objectName=
'preview{}'.format(preview_list.currentIndex))
175 def _get_category_element(self, category):
177 return self.wait_select_single(
178 'Base', objectName=
'dashCategory{}'.format(category))
179 except dbus.StateNotFoundError:
181 'No category found with name {}'.format(category))
185 """Autopilot emulator for the applications scope."""
188 """Return the list of applications on a category.
190 :parameter category: The name of the category.
194 application_cards = category_element.select_many(
'Card')
197 application_cards = sorted(
199 key=
lambda card: (card.globalRect.y, card.globalRect.x))
202 for card
in application_cards:
203 if card.objectName !=
'cardToolCard':
204 card_header = card.select_single(
'CardHeader')
205 result.append(card_header.title)
210 """Autopilot custom proxy object for generic previews."""
def _scroll_to_right_scope
def get_applications_grid
def _scroll_to_left_scope
def _get_category_element
def _get_scroll_direction
def _open_scope_scrolling
def _get_search_text_field
def _get_scope_from_loader