@@ -22,6 +22,7 @@ import logging
2222from unity8.shell import emulators
2323
2424from autopilot import logging as autopilot_logging
25+from autopilot.introspection import dbus
2526
2627
2728logger = logging.getLogger(__name__)
@@ -67,49 +68,44 @@ class Dash(emulators.UnityEmulatorBase):
6768
6869 """
6970 scope_id = "%s.scope" % scope_name
70− scope_index = self._get_scope_index(scope_id)
71− if scope_index == self.dash_content_list.currentIndex:
71+ scope_loader = self._get_scope_loader(scope_id)
72+ if scope_loader.isCurrent:
7273 logger.info('The scope is already open.')
73− return self._get_scope_by_index(scope_index)
74− else:
75− return self._open_scope_scrolling(scope_index)
76−
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):
80− try:
81− if loader.scopeId == scope_id:
82− return index
83− except AttributeError:
84− pass
74+ return self._get_scope_from_loader(scope_loader)
8575 else:
76+ return self._open_scope_scrolling(scope_loader)
77+
78+ def _get_scope_loader(self, scope_id):
79+ try:
80+ return self.dash_content_list.select_single(
81+ 'QQuickLoader', scopeId=scope_id)
82+ except dbus.StateNotFoundError:
8683 raise emulators.UnityEmulatorException(
8784 'No scope found with id {0}'.format(scope_id))
8885
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])
92−
9386 def _get_scope_from_loader(self, loader):
9487 if loader.scopeId == 'applications.scope':
9588 return loader.select_single(DashApps)
9689 else:
9790 return loader.select_single(GenericScopeView)
9891
99− def _open_scope_scrolling(self, scope_index):
100− scroll = self._get_scroll_direction(scope_index)
92+ def _open_scope_scrolling(self, scope_loader):
93+ scroll = self._get_scroll_direction(scope_loader)
10194
102− while scope_index != self.dash_content_list.currentIndex:
95+ while not scope_loader.isCurrent:
10396 scroll()
104− scope = self._get_scope_by_index(scope_index)
97+
98+ scope = self._get_scope_from_loader(scope_loader)
10599 scope.moving.wait_for(False)
106100 scope.isCurrent.wait_for(True)
107101 return scope
108102
109− def _get_scroll_direction(self, scope_index):
110− if scope_index < self.dash_content_list.currentIndex:
103+ def _get_scroll_direction(self, scope_loader):
104+ current_scope_loader = self.dash_content_list.select_single(
105+ 'QQuickLoader', isCurrent=True)
106+ if scope_loader.globalRect.x < current_scope_loader.globalRect.x:
111107 return self._scroll_to_left_scope
112− elif scope_index > self.dash_content_list.currentIndex:
108+ elif scope_loader.globalRect.x > current_scope_loader.globalRect.x:
113109 return self._scroll_to_right_scope
114110 else:
115111 raise emulators.UnityEmulatorException('The scope is already open')