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 @autopilot_logging.log_action(logger.info)
76 :parameter scope_id: The id of the scope.
81 if scope_loader.isCurrent:
82 logger.info(
'The scope is already open.')
87 def _get_scope_loader(self, scope_id):
89 return self.dash_content_list.wait_select_single(
90 'QQuickLoader', scopeId=scope_id)
91 except dbus.StateNotFoundError:
93 'No scope found with id {0}'.format(scope_id))
95 def _get_scope_from_loader(self, loader):
96 return loader.wait_select_single(
'GenericScopeView');
98 def _open_scope_scrolling(self, scope_loader):
101 while not scope_loader.isCurrent:
103 self.dash_content_list.moving.wait_for(
False)
105 scope_loader.isCurrent.wait_for(
True)
109 def _get_scroll_direction(self, scope_loader):
110 current_scope_loader = self.dash_content_list.select_single(
111 'QQuickLoader', isCurrent=
True)
112 if scope_loader.globalRect.x < current_scope_loader.globalRect.x:
114 elif scope_loader.globalRect.x > current_scope_loader.globalRect.x:
119 @autopilot_logging.log_action(logger.info)
120 def _scroll_to_left_scope(self):
121 original_index = self.dash_content_list.currentIndex
122 dash_content = self.select_single(objectName=
"dashContent")
123 x, y, width, height = dash_content.globalRect
124 start_x = x + width / 3
125 stop_x = x + width / 3 * 2
126 start_y = stop_y = y + 1
127 self.pointing_device.drag(start_x, start_y, stop_x, stop_y)
128 self.dash_content_list.currentIndex.wait_for(original_index - 1)
130 @autopilot_logging.log_action(logger.info)
131 def _scroll_to_right_scope(self):
132 original_index = self.dash_content_list.currentIndex
133 dash_content = self.select_single(objectName=
"dashContent")
134 x, y, width, height = dash_content.globalRect
135 start_x = x + width / 3 * 2
136 stop_x = x + width / 3
137 start_y = stop_y = y + 1
138 self.pointing_device.drag(start_x, start_y, stop_x, stop_y)
139 self.dash_content_list.currentIndex.wait_for(original_index + 1)
141 def enter_search_query(self, query):
143 search_button = current_header.select_single(objectName=
"search_header_button")
144 self.pointing_device.move(search_button.globalRect.x + search_button.width / 2,
145 search_button.globalRect.y + search_button.height / 2)
146 self.pointing_device.click()
147 headerContainer = current_header.select_single(
148 objectName=
"headerContainer")
149 headerContainer.contentY.wait_for(0)
151 search_text_field.write(query)
152 self.select_single(objectName=
"processingIndicator").visible.wait_for(
False)
154 def _get_search_text_field(self):
156 return page_header.select_single(objectName=
'searchTextField')
158 def _get_current_page_header(self):
159 dashContentList = self.select_single(objectName=
"dashContentList")
160 all_headers = dashContentList.select_many(
"QQuickLoader")
161 for i
in all_headers:
163 return i.select_single(objectName=
"scopePageHeader")
167 class ListViewWithPageHeader(ubuntuuitoolkit.QQuickFlickable):
171 class GenericScopeView(emulators.UnityEmulatorBase):
172 """Autopilot emulator for generic scopes."""
174 @autopilot_logging.log_action(logger.info)
176 """Open the preview of an application.
178 :parameter category: The name of the category where the application is.
179 :parameter app_name: The name of the application.
180 :return: The opened preview.
187 preview_list = self.wait_select_single(
188 'QQuickLoader', objectName=
'subPageLoader')
189 preview_list.subPageShown.wait_for(
True)
190 preview_list.x.wait_for(0)
191 return preview_list.select_single(
192 Preview, objectName=
'preview{}'.format(preview_list.currentIndex))
194 @autopilot_logging.log_action(logger.debug)
196 """Click an item from the scope.
198 :parameter category: The name of the category where the item is.
199 :parameter title: The title of the item.
203 icon = category_element.select_single(
'AbstractButton', title=title)
204 self.pointing_device.click_object(icon)
206 def _get_category_element(self, category):
208 return self.wait_select_single(
209 'Base', objectName=
'dashCategory{}'.format(category))
210 except dbus.StateNotFoundError:
212 'No category found with name {}'.format(category))
215 """Return the list of applications on a category.
217 :parameter category: The name of the category.
221 see_all = category_element.select_single(objectName=
'seeAll')
222 application_cards = category_element.select_many(
'AbstractButton')
224 application_cards = sorted(
225 (card
for card
in application_cards
226 if card.globalRect.y < see_all.globalRect.y),
227 key=
lambda card: (card.globalRect.y, card.globalRect.x))
230 for card
in application_cards:
231 if card.objectName
not in (
'cardToolCard',
'seeAll'):
232 result.append(card.title)
237 """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