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.""" 39 ubuntuuitoolkit.MainView)
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_scope(self, scope_name):
53 'QQuickLoader', scopeId=scope_name)
55 def get_scope_by_index(self, scope_index=0):
57 'QQuickLoader', objectName=(
"scopeLoader%i" % scope_index))
59 @autopilot_logging.log_action(logger.info)
63 :parameter scope_id: The id of the scope. 68 if scope_loader.isCurrent:
69 logger.info(
'The scope is already open.')
74 def _get_scope_loader(self, scope_id):
77 for l
in aux.get_children_by_type(
'QQuickLoader'):
78 if (l.scopeId == scope_id):
81 'No scope found with id {0}'.format(scope_id))
82 except dbus.StateNotFoundError:
84 'No scope found with id {0}'.format(scope_id))
86 def _get_scope_from_loader(self, loader):
87 return loader.wait_select_single(
'GenericScopeView')
89 def _open_scope_scrolling(self, scope_loader):
92 while not scope_loader.isCurrent:
96 scope_loader.isCurrent.wait_for(
True)
100 def _get_scroll_direction(self, scope_loader):
102 'QQuickLoader', isCurrent=
True)
103 if scope_loader.globalRect.x < current_scope_loader.globalRect.x:
105 elif scope_loader.globalRect.x > current_scope_loader.globalRect.x:
110 @autopilot_logging.log_action(logger.info)
111 def _scroll_to_left_scope(self):
113 dash_content = self.select_single(objectName=
"dashContent")
114 x, y, width, height = dash_content.globalRect
119 jump = (width / divisions) // rate * rate
121 stop_x = x + jump * (divisions - 1)
122 start_y = stop_y = y + 1
123 self.pointing_device.drag(start_x, start_y, stop_x, stop_y, rate)
126 @autopilot_logging.log_action(logger.info)
127 def _scroll_to_right_scope(self):
129 dash_content = self.select_single(objectName=
"dashContent")
130 x, y, width, height = dash_content.globalRect
135 jump = (width / divisions) // rate * rate
136 start_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)
142 def enter_search_query(self, query, keyboard):
145 current_header.select_single(objectName=
"search_button")
146 self.pointing_device.move(
147 search_button.globalRect.x + search_button.width / 2,
148 search_button.globalRect.y + search_button.height / 2)
149 self.pointing_device.click()
150 headersColumn = current_header.select_single(
151 objectName=
"headersColumn")
152 headersColumn.y.wait_for(0)
155 objectName=
"processingIndicator").visible.wait_for(
False)
157 def get_search_text_field(self):
159 return page_header.select_single(objectName=
'searchTextField')
161 def _get_current_page_header(self):
165 return i.select_single(objectName=
"scopePageHeader")
169 class ListViewWithPageHeader(ubuntuuitoolkit.QQuickFlickable):
171 margin_to_swipe_from_bottom = ubuntuuitoolkit.units.gu(4)
175 """Autopilot helper for generic scopes.""" 177 @autopilot_logging.log_action(logger.info)
179 """Open the preview of an application. 181 :parameter category: The name of the category where the application is. 182 :parameter app_name: The name of the application. 183 :return: The opened preview. 190 preview_list = self.wait_select_single(
191 'QQuickLoader', objectName=
'subPageLoader')
192 preview_list.subPageShown.wait_for(
True)
193 preview_list.x.wait_for(0)
194 self.get_root_instance().select_single(
195 objectName=
'processingIndicator').visible.wait_for(
False)
196 return preview_list.select_single(
197 Preview, objectName=
'preview')
199 @autopilot_logging.log_action(logger.debug)
201 """Click an item from the scope. 203 :parameter category: The name of the category where the item is. 204 :parameter title: The title of the item. 208 icon = category_element.wait_select_single(
209 'UCAbstractButton', title=title)
210 list_view = self.select_single(
211 ListViewWithPageHeader, objectName=
'categoryListView')
212 list_view.swipe_child_into_view(icon)
213 self.pointing_device.click_object(icon, press_duration=press_duration)
215 def _get_category_element(self, category):
217 return self.wait_select_single(
219 objectName=
'dashCategory{}'.format(category))
220 except dbus.StateNotFoundError:
222 'No category found with name {}'.format(category))
225 """Return the list of applications on a category. 227 :parameter category: The name of the category. 231 see_all = category_element.select_single(objectName=
'seeAll')
232 application_cards = category_element.select_many(
'UCAbstractButton')
234 application_cards = sorted(
235 (card
for card
in application_cards
236 if card.globalRect.y < see_all.globalRect.y),
237 key=
lambda card: (card.globalRect.y, card.globalRect.x))
240 for card
in application_cards:
241 if card.objectName
not in (
'cardToolCard',
'seeAll'):
242 result.append(card.title)
246 class Preview(ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase):
247 """Autopilot custom proxy object for generic previews.""" def _get_scope_loader(self, scope_id)
def __init__(self, app_proxy)
def click_scope_item(self, category, title, press_duration=0.10)
def _open_scope_scrolling(self, scope_loader)
def open_preview(self, category, app_name, press_duration=0.10)
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)