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 return self.dash_content_list.wait_select_single(
94 'QQuickLoader', scopeId=scope_id)
95 except dbus.StateNotFoundError:
97 'No scope found with id {0}'.format(scope_id))
99 def _get_scope_from_loader(self, loader):
100 return loader.wait_select_single(
'GenericScopeView');
102 def _open_scope_scrolling(self, scope_loader):
105 while not scope_loader.isCurrent:
107 self.dash_content_list.moving.wait_for(
False)
109 scope_loader.isCurrent.wait_for(
True)
113 def _get_scroll_direction(self, scope_loader):
114 current_scope_loader = self.dash_content_list.select_single(
115 'QQuickLoader', isCurrent=
True)
116 if scope_loader.globalRect.x < current_scope_loader.globalRect.x:
118 elif scope_loader.globalRect.x > current_scope_loader.globalRect.x:
123 @autopilot_logging.log_action(logger.info)
124 def _scroll_to_left_scope(self):
125 original_index = self.dash_content_list.currentIndex
126 dash_content = self.select_single(objectName=
"dashContent")
127 x, y, width, height = dash_content.globalRect
128 start_x = x + width / 3
129 stop_x = x + width / 3 * 2
130 start_y = stop_y = y + 1
131 self.pointing_device.drag(start_x, start_y, stop_x, stop_y)
132 self.dash_content_list.currentIndex.wait_for(original_index - 1)
134 @autopilot_logging.log_action(logger.info)
135 def _scroll_to_right_scope(self):
136 original_index = self.dash_content_list.currentIndex
137 dash_content = self.select_single(objectName=
"dashContent")
138 x, y, width, height = dash_content.globalRect
139 start_x = x + width / 3 * 2
140 stop_x = x + width / 3
141 start_y = stop_y = y + 1
142 self.pointing_device.drag(start_x, start_y, stop_x, stop_y)
143 self.dash_content_list.currentIndex.wait_for(original_index + 1)
145 def enter_search_query(self, query):
147 search_button = current_header.select_single(objectName=
"search_header_button")
148 self.pointing_device.move(search_button.globalRect.x + search_button.width / 2,
149 search_button.globalRect.y + search_button.height / 2)
150 self.pointing_device.click()
151 headerContainer = current_header.select_single(
152 objectName=
"headerContainer")
153 headerContainer.contentY.wait_for(0)
155 search_text_field.write(query)
156 self.select_single(objectName=
"processingIndicator").visible.wait_for(
False)
158 def _get_search_text_field(self):
160 return page_header.select_single(objectName=
'searchTextField')
162 def _get_current_page_header(self):
163 dashContentList = self.select_single(objectName=
"dashContentList")
164 all_headers = dashContentList.select_many(
"QQuickLoader")
165 for i
in all_headers:
167 return i.select_single(objectName=
"scopePageHeader")
171 class ListViewWithPageHeader(ubuntuuitoolkit.QQuickFlickable):
175 class GenericScopeView(emulators.UnityEmulatorBase):
176 """Autopilot emulator for generic scopes."""
178 @autopilot_logging.log_action(logger.info)
180 """Open the preview of an application.
182 :parameter category: The name of the category where the application is.
183 :parameter app_name: The name of the application.
184 :return: The opened preview.
191 preview_list = self.wait_select_single(
192 'QQuickLoader', objectName=
'subPageLoader')
193 preview_list.subPageShown.wait_for(
True)
194 preview_list.x.wait_for(0)
195 return preview_list.select_single(
196 Preview, objectName=
'preview{}'.format(preview_list.currentIndex))
198 @autopilot_logging.log_action(logger.debug)
200 """Click an item from the scope.
202 :parameter category: The name of the category where the item is.
203 :parameter title: The title of the item.
207 icon = category_element.select_single(
'AbstractButton', title=title)
208 self.pointing_device.click_object(icon)
210 def _get_category_element(self, category):
212 return self.wait_select_single(
213 'DashCategoryBase', objectName=
'dashCategory{}'.format(category))
214 except dbus.StateNotFoundError:
216 'No category found with name {}'.format(category))
219 """Return the list of applications on a category.
221 :parameter category: The name of the category.
225 see_all = category_element.select_single(objectName=
'seeAll')
226 application_cards = category_element.select_many(
'AbstractButton')
228 application_cards = sorted(
229 (card
for card
in application_cards
230 if card.globalRect.y < see_all.globalRect.y),
231 key=
lambda card: (card.globalRect.y, card.globalRect.x))
234 for card
in application_cards:
235 if card.objectName
not in (
'cardToolCard',
'seeAll'):
236 result.append(card.title)
241 """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 _get_current_page_header
def _open_scope_scrolling
def _get_search_text_field
def _get_scope_from_loader