21 import ubuntuuitoolkit
25 from autopilot
import logging
as autopilot_logging
26 from autopilot.introspection
import dbus
27 from ubuntuuitoolkit
import emulators
as toolkit_emulators
30 logger = logging.getLogger(__name__)
35 """Autopilot helper for the Dash app."""
39 self.
main_view = self.app_proxy.select_single(
40 toolkit_emulators.MainView)
41 self.
dash = self.main_view.select_single(Dash)
45 """An emulator that understands the Dash."""
47 def __init__(self, *args):
48 super(Dash, self).__init__(*args)
50 'QQuickListView', objectName=
'dashContentList')
52 def get_applications_grid(self):
53 get_grid = self.
get_scope(
'clickscope').wait_select_single(
54 'CardGrid', objectName=
'local')
58 """Returns a 'Tile' icon that has the text 'text' from the application
61 :param text: String containing the text of the icon to search for.
65 resp_grid = app_grid.wait_select_single(
'ResponsiveGridView')
66 return resp_grid.select_single(
'Tile', text=text)
68 def get_scope(self, scope_name='clickscope'):
69 return self.dash_content_list.wait_select_single(
70 'QQuickLoader', scopeId=scope_name)
72 def get_scope_by_index(self, scope_index=0):
73 return self.dash_content_list.wait_select_single(
74 'QQuickLoader', objectName=(
"scopeLoader%i" % scope_index))
76 @autopilot_logging.log_action(logger.info)
80 :parameter scope_id: The id of the scope.
85 if scope_loader.isCurrent:
86 logger.info(
'The scope is already open.')
91 def _get_scope_loader(self, scope_id):
93 aux = self.dash_content_list.get_children_by_type(
'QQuickItem')[0]
94 for l
in aux.get_children_by_type(
'QQuickLoader'):
95 if (l.scopeId == scope_id):
98 'No scope found with id {0}'.format(scope_id))
99 except dbus.StateNotFoundError:
101 'No scope found with id {0}'.format(scope_id))
103 def _get_scope_from_loader(self, loader):
104 return loader.wait_select_single(
'GenericScopeView');
106 def _open_scope_scrolling(self, scope_loader):
109 while not scope_loader.isCurrent:
111 self.dash_content_list.moving.wait_for(
False)
113 scope_loader.isCurrent.wait_for(
True)
117 def _get_scroll_direction(self, scope_loader):
118 current_scope_loader = self.dash_content_list.select_single(
119 'QQuickLoader', isCurrent=
True)
120 if scope_loader.globalRect.x < current_scope_loader.globalRect.x:
122 elif scope_loader.globalRect.x > current_scope_loader.globalRect.x:
127 @autopilot_logging.log_action(logger.info)
128 def _scroll_to_left_scope(self):
129 original_index = self.dash_content_list.currentIndex
130 dash_content = self.select_single(objectName=
"dashContent")
131 x, y, width, height = dash_content.globalRect
136 jump = ( width / divisions ) // rate * rate
138 stop_x = x + jump * (divisions - 1)
139 start_y = stop_y = y + 1
140 self.pointing_device.drag(start_x, start_y, stop_x, stop_y, rate)
141 self.dash_content_list.currentIndex.wait_for(original_index - 1)
143 @autopilot_logging.log_action(logger.info)
144 def _scroll_to_right_scope(self):
145 original_index = self.dash_content_list.currentIndex
146 dash_content = self.select_single(objectName=
"dashContent")
147 x, y, width, height = dash_content.globalRect
152 jump = ( width / divisions ) // rate * rate
153 start_x = x + jump * (divisions - 1)
155 start_y = stop_y = y + 1
156 self.pointing_device.drag(start_x, start_y, stop_x, stop_y, rate)
157 self.dash_content_list.currentIndex.wait_for(original_index + 1)
159 def enter_search_query(self, query):
161 search_button = current_header.select_single(objectName=
"search_header_button")
162 self.pointing_device.move(search_button.globalRect.x + search_button.width / 2,
163 search_button.globalRect.y + search_button.height / 2)
164 self.pointing_device.click()
165 headerContainer = current_header.select_single(
166 objectName=
"headerContainer")
167 headerContainer.contentY.wait_for(0)
169 search_text_field.write(query)
170 self.select_single(objectName=
"processingIndicator").visible.wait_for(
False)
172 def _get_search_text_field(self):
174 return page_header.select_single(objectName=
'searchTextField')
176 def _get_current_page_header(self):
177 dashContentList = self.select_single(objectName=
"dashContentList")
178 all_headers = dashContentList.select_many(
"QQuickLoader")
179 for i
in all_headers:
181 return i.select_single(objectName=
"scopePageHeader")
185 class ListViewWithPageHeader(ubuntuuitoolkit.QQuickFlickable):
189 class GenericScopeView(emulators.UnityEmulatorBase):
190 """Autopilot emulator for generic scopes."""
192 @autopilot_logging.log_action(logger.info)
194 """Open the preview of an application.
196 :parameter category: The name of the category where the application is.
197 :parameter app_name: The name of the application.
198 :return: The opened preview.
205 preview_list = self.wait_select_single(
206 'QQuickLoader', objectName=
'subPageLoader')
207 preview_list.subPageShown.wait_for(
True)
208 preview_list.x.wait_for(0)
209 return preview_list.select_single(
210 Preview, objectName=
'preview{}'.format(preview_list.currentIndex))
212 @autopilot_logging.log_action(logger.debug)
214 """Click an item from the scope.
216 :parameter category: The name of the category where the item is.
217 :parameter title: The title of the item.
221 icon = category_element.wait_select_single(
'AbstractButton', title=title)
222 self.pointing_device.click_object(icon)
224 def _get_category_element(self, category):
226 return self.wait_select_single(
227 'DashCategoryBase', objectName=
'dashCategory{}'.format(category))
228 except dbus.StateNotFoundError:
230 'No category found with name {}'.format(category))
233 """Return the list of applications on a category.
235 :parameter category: The name of the category.
239 see_all = category_element.select_single(objectName=
'seeAll')
240 application_cards = category_element.select_many(
'AbstractButton')
242 application_cards = sorted(
243 (card
for card
in application_cards
244 if card.globalRect.y < see_all.globalRect.y),
245 key=
lambda card: (card.globalRect.y, card.globalRect.x))
248 for card
in application_cards:
249 if card.objectName
not in (
'cardToolCard',
'seeAll'):
250 result.append(card.title)
255 """Autopilot custom proxy object for generic previews."""
def get_application_icon(self, text)
def click_scope_item(self, category, title)
def _get_scope_loader(self, scope_id)
def get_applications(self, category)
def open_preview(self, category, app_name)
def _get_scope_from_loader(self, loader)
def _get_search_text_field(self)
def _get_category_element(self, category)
def get_applications_grid(self)
def _scroll_to_left_scope(self)
def __init__(self, app_proxy)
def _open_scope_scrolling(self, scope_loader)
def _scroll_to_right_scope(self)
def _get_current_page_header(self)
def open_scope(self, scope_id)
def _get_scroll_direction(self, scope_loader)