22 import ubuntuuitoolkit
23 from autopilot
import logging
as autopilot_logging
24 from autopilot.introspection
import dbus
29 logger = logging.getLogger(__name__)
34 """Autopilot helper for the Dash app."""
38 self.
main_view = self.app_proxy.select_single(
39 ubuntuuitoolkit.MainView)
40 self.
dash = self.main_view.select_single(Dash)
43 class Dash(ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase):
44 """A helper that understands the Dash."""
46 def __init__(self, *args):
47 super().__init__(*args)
49 'QQuickListView', objectName=
'dashContentList')
51 def get_applications_grid(self):
52 get_grid = self.
get_scope(
'clickscope').wait_select_single(
53 'CardGrid', objectName=
'local')
57 """Returns a 'Tile' icon that has the text 'text' from the application
60 :param text: String containing the text of the icon to search for.
64 resp_grid = app_grid.wait_select_single(
'ResponsiveGridView')
65 return resp_grid.select_single(
'Tile', text=text)
67 def get_scope(self, scope_name='clickscope'):
68 return self.dash_content_list.wait_select_single(
69 'QQuickLoader', scopeId=scope_name)
71 def get_scope_by_index(self, scope_index=0):
72 return self.dash_content_list.wait_select_single(
73 'QQuickLoader', objectName=(
"scopeLoader%i" % scope_index))
75 @autopilot_logging.log_action(logger.info)
79 :parameter scope_id: The id of the scope.
84 if scope_loader.isCurrent:
85 logger.info(
'The scope is already open.')
90 def _get_scope_loader(self, scope_id):
92 aux = self.dash_content_list.get_children_by_type(
'QQuickItem')[0]
93 for l
in aux.get_children_by_type(
'QQuickLoader'):
94 if (l.scopeId == scope_id):
97 'No scope found with id {0}'.format(scope_id))
98 except dbus.StateNotFoundError:
100 'No scope found with id {0}'.format(scope_id))
102 def _get_scope_from_loader(self, loader):
103 return loader.wait_select_single(
'GenericScopeView')
105 def _open_scope_scrolling(self, scope_loader):
108 while not scope_loader.isCurrent:
110 self.dash_content_list.moving.wait_for(
False)
112 scope_loader.isCurrent.wait_for(
True)
116 def _get_scroll_direction(self, scope_loader):
117 current_scope_loader = self.dash_content_list.select_single(
118 'QQuickLoader', isCurrent=
True)
119 if scope_loader.globalRect.x < current_scope_loader.globalRect.x:
121 elif scope_loader.globalRect.x > current_scope_loader.globalRect.x:
126 @autopilot_logging.log_action(logger.info)
127 def _scroll_to_left_scope(self):
128 original_index = self.dash_content_list.currentIndex
129 dash_content = self.select_single(objectName=
"dashContent")
130 x, y, width, height = dash_content.globalRect
135 jump = (width / divisions) // rate * rate
137 stop_x = x + jump * (divisions - 1)
138 start_y = stop_y = y + 1
139 self.pointing_device.drag(start_x, start_y, stop_x, stop_y, rate)
140 self.dash_content_list.currentIndex.wait_for(original_index - 1)
142 @autopilot_logging.log_action(logger.info)
143 def _scroll_to_right_scope(self):
144 original_index = self.dash_content_list.currentIndex
145 dash_content = self.select_single(objectName=
"dashContent")
146 x, y, width, height = dash_content.globalRect
151 jump = (width / divisions) // rate * rate
152 start_x = x + jump * (divisions - 1)
154 start_y = stop_y = y + 1
155 self.pointing_device.drag(start_x, start_y, stop_x, stop_y, rate)
156 self.dash_content_list.currentIndex.wait_for(original_index + 1)
158 def enter_search_query(self, query, keyboard):
161 current_header.select_single(objectName=
"search_action_button")
162 self.pointing_device.move(
163 search_button.globalRect.x + search_button.width / 2,
164 search_button.globalRect.y + search_button.height / 2)
165 self.pointing_device.click()
166 headerContainer = current_header.select_single(
167 objectName=
"headerContainer")
168 headerContainer.contentY.wait_for(0)
171 objectName=
"processingIndicator").visible.wait_for(
False)
173 def get_search_text_field(self):
175 return page_header.select_single(objectName=
'searchTextField')
177 def _get_current_page_header(self):
178 dashContentList = self.select_single(objectName=
"dashContentList")
179 all_headers = dashContentList.select_many(
"QQuickLoader")
180 for i
in all_headers:
182 return i.select_single(objectName=
"scopePageHeader")
186 class ListViewWithPageHeader(ubuntuuitoolkit.QQuickFlickable):
188 margin_to_swipe_from_bottom = ubuntuuitoolkit.units.gu(4)
192 """Autopilot helper for generic scopes."""
194 @autopilot_logging.log_action(logger.info)
196 """Open the preview of an application.
198 :parameter category: The name of the category where the application is.
199 :parameter app_name: The name of the application.
200 :return: The opened preview.
207 preview_list = self.wait_select_single(
208 'QQuickLoader', objectName=
'subPageLoader')
209 preview_list.subPageShown.wait_for(
True)
210 preview_list.x.wait_for(0)
211 self.get_root_instance().select_single(
212 objectName=
'processingIndicator').visible.wait_for(
False)
213 return preview_list.select_single(
214 Preview, objectName=
'preview{}'.format(
215 preview_list.initialIndex))
217 @autopilot_logging.log_action(logger.debug)
219 """Click an item from the scope.
221 :parameter category: The name of the category where the item is.
222 :parameter title: The title of the item.
226 icon = category_element.wait_select_single(
227 'UCAbstractButton', title=title)
228 list_view = self.select_single(
229 ListViewWithPageHeader, objectName=
'categoryListView')
230 list_view.swipe_child_into_view(icon)
231 self.pointing_device.click_object(icon, press_duration=press_duration)
233 def _get_category_element(self, category):
235 return self.wait_select_single(
237 objectName=
'dashCategory{}'.format(category))
238 except dbus.StateNotFoundError:
240 'No category found with name {}'.format(category))
243 """Return the list of applications on a category.
245 :parameter category: The name of the category.
249 see_all = category_element.select_single(objectName=
'seeAll')
250 application_cards = category_element.select_many(
'UCAbstractButton')
252 application_cards = sorted(
253 (card
for card
in application_cards
254 if card.globalRect.y < see_all.globalRect.y),
255 key=
lambda card: (card.globalRect.y, card.globalRect.x))
258 for card
in application_cards:
259 if card.objectName
not in (
'cardToolCard',
'seeAll'):
260 result.append(card.title)
264 class Preview(ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase):
265 """Autopilot custom proxy object for generic previews."""
def _get_scope_loader(self, scope_id)
def get_applications_grid(self)
def __init__(self, app_proxy)
def _open_scope_scrolling(self, scope_loader)
def get_application_icon(self, text)
def _get_scope_from_loader(self, loader)
def _scroll_to_right_scope(self)
def _get_category_element(self, category)
def get_applications(self, category)
def _scroll_to_left_scope(self)
def open_scope(self, scope_id)
def _get_scroll_direction(self, scope_loader)
def _get_current_page_header(self)