@@ -22,6 +22,7 @@ import logging
22from unity8.shell import emulators
22from unity8.shell import emulators
24from autopilot import logging as autopilot_logging
24from autopilot import logging as autopilot_logging
25+from autopilot.introspection import dbus
27logger = logging.getLogger(__name__)
28logger = logging.getLogger(__name__)
@@ -67,49 +68,44 @@ class Dash(emulators.UnityEmulatorBase):
69 scope_id = "%s.scope" % scope_name
70 scope_id = "%s.scope" % scope_name
70− scope_index = self._get_scope_index(scope_id)
71+ scope_loader = self._get_scope_loader(scope_id)
71− if scope_index == self.dash_content_list.currentIndex:
72+ if scope_loader.isCurrent:
72 logger.info('The scope is already open.')
73 logger.info('The scope is already open.')
73− return self._get_scope_by_index(scope_index)
74+ return self._get_scope_from_loader(scope_loader)
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:
76+ return self._open_scope_scrolling(scope_loader)
78+ def _get_scope_loader(self, scope_id):
80+ return self.dash_content_list.select_single(
81+ 'QQuickLoader', scopeId=scope_id)
82+ except dbus.StateNotFoundError:
86 raise emulators.UnityEmulatorException(
83 raise emulators.UnityEmulatorException(
87 'No scope found with id {0}'.format(scope_id))
84 '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):
86 def _get_scope_from_loader(self, loader):
94 if loader.scopeId == 'applications.scope':
87 if loader.scopeId == 'applications.scope':
95 return loader.select_single(DashApps)
88 return loader.select_single(DashApps)
97 return loader.select_single(GenericScopeView)
90 return loader.select_single(GenericScopeView)
99− def _open_scope_scrolling(self, scope_index):
92+ def _open_scope_scrolling(self, scope_loader):
100− scroll = self._get_scroll_direction(scope_index)
93+ scroll = self._get_scroll_direction(scope_loader)
102− while scope_index != self.dash_content_list.currentIndex:
95+ while not scope_loader.isCurrent:
104− scope = self._get_scope_by_index(scope_index)
97+
98+ scope = self._get_scope_from_loader(scope_loader)
105 scope.moving.wait_for(False)
99 scope.moving.wait_for(False)
106 scope.isCurrent.wait_for(True)
100 scope.isCurrent.wait_for(True)
107 return scope
101 return scope
109− def _get_scroll_direction(self, scope_index):
103+ def _get_scroll_direction(self, scope_loader):
110− if scope_index < self.dash_content_list.currentIndex:
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:
111 return self._scroll_to_left_scope
107 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:
113 return self._scroll_to_right_scope
109 return self._scroll_to_right_scope
115 raise emulators.UnityEmulatorException('The scope is already open')
111 raise emulators.UnityEmulatorException('The scope is already open')