@@ -17,13 +17,24 @@
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
20−from unity8.shell.emulators import UnityEmulatorBase
20+import logging
22+from unity8.shell import emulators
23−class Dash(UnityEmulatorBase):
24+from autopilot import logging as autopilot_logging
27+logger = logging.getLogger(__name__)
30+class Dash(emulators.UnityEmulatorBase):
25 """An emulator that understands the Dash."""
31 """An emulator that understands the Dash."""
33+ def __init__(self, *args):
34+ super(Dash, self).__init__(*args)
35+ self.dash_content_list = self.wait_select_single(
36+ 'QQuickListView', objectName='dashContentList')
27 def get_home_applications_grid(self):
38 def get_home_applications_grid(self):
28 get_grid = self.get_scope('home').wait_select_single(
39 get_grid = self.get_scope('home').wait_select_single(
29 "GenericFilterGrid",
40 "GenericFilterGrid",
@@ -43,9 +54,96 @@ class Dash(UnityEmulatorBase):
43 return resp_grid.select_single('Tile', text=text)
54 return resp_grid.select_single('Tile', text=text)
45 def get_scope(self, scope_name='home'):
56 def get_scope(self, scope_name='home'):
46− dash_content = self.wait_select_single(
48− objectName='dashContentList'
50 scope_id = "%s.scope" % scope_name
57 scope_id = "%s.scope" % scope_name
58+ return self.dash_content_list.select_single(
51− return dash_content.select_single('QQuickLoader', scopeId=scope_id)
59+ 'QQuickLoader', scopeId=scope_id)
61+ @autopilot_logging.log_action(logger.info)
62+ def open_scope(self, scope_name):
63+ """Open a dash scope.
65+ :parameter scope_name: The name of the scope.
69+ scope_id = "%s.scope" % scope_name
70+ scope_index = self._get_scope_index(scope_id)
71+ if scope_index == self.dash_content_list.currentIndex:
72+ logger.info('The scope is already open.')
73+ return self._get_scope_by_index(scope_index)
75+ return self._open_scope_scrolling(scope_index)
77+ def _get_scope_index(self, scope_id):
78+ scope_loaders = self.dash_content_list.select_many('QQuickLoader')
79+ for index, loader in enumerate(scope_loaders):
81+ if loader.scopeId == scope_id:
83+ except AttributeError:
86+ raise emulators.UnityEmulatorException(
87+ 'No scope found with id {0}'.format(scope_id))
89+ def _get_scope_by_index(self, scope_index):
90+ scope_loaders = self.dash_content_list.select_many('QQuickLoader')
91+ return self._get_scope_from_loader(scope_loaders[scope_index])
93+ def _get_scope_from_loader(self, loader):
94+ if loader.scopeId == 'applications.scope':
95+ return loader.select_single(DashApps)
97+ return loader.select_single(GenericScopeView)
99+ def _open_scope_scrolling(self, scope_index):
100+ scroll = self._get_scroll_direction(scope_index)
102+ while scope_index != self.dash_content_list.currentIndex:
104+ scope = self._get_scope_by_index(scope_index)
105+ scope.moving.wait_for(False)
106+ scope.isCurrent.wait_for(True)
109+ def _get_scroll_direction(self, scope_index):
110+ if scope_index < self.dash_content_list.currentIndex:
111+ return self._scroll_to_left_scope
112+ elif scope_index > self.dash_content_list.currentIndex:
113+ return self._scroll_to_right_scope
115+ raise emulators.UnityEmulatorException('The scope is already open')
117+ @autopilot_logging.log_action(logger.info)
118+ def _scroll_to_left_scope(self):
119+ original_index = self.dash_content_list.currentIndex
120+ # Scroll on the dash bar, because some scopes have contents that can be
121+ # scrolled horizontally.
122+ panel = self.select_single('DashBar').select_single('Panel')
123+ start_x = panel.width / 3
124+ stop_x = panel.width / 3 * 2
125+ start_y = stop_y = panel.globalRect.y + panel.height / 2
126+ self.pointing_device.drag(start_x, start_y, stop_x, stop_y)
127+ self.dash_content_list.currentIndex.wait_for(original_index - 1)
128+ panel.opened.wait_for(False)
130+ @autopilot_logging.log_action(logger.info)
131+ def _scroll_to_right_scope(self):
132+ original_index = self.dash_content_list.currentIndex
133+ # Scroll on the dash bar panel, because some scopes have contents that
134+ # can be scrolled horizontally.
135+ panel = self.select_single('DashBar').select_single('Panel')
136+ start_x = panel.width / 3 * 2
137+ stop_x = panel.width / 3
138+ start_y = stop_y = panel.globalRect.y + panel.height / 2
139+ self.pointing_device.drag(start_x, start_y, stop_x, stop_y)
140+ self.dash_content_list.currentIndex.wait_for(original_index + 1)
141+ panel.opened.wait_for(False)
144+class GenericScopeView(emulators.UnityEmulatorBase):
145+ """Autopilot emulators for generic scopes."""
148+class DashApps(emulators.UnityEmulatorBase):
149+ """Autopilot emulators for the applications scope."""