def test_swipe_to_show_more_right_with_right_margin(self): """Calling swipe to show more right will use the margin in the drag.""" qquickflickable = self.main_view.select_single( ubuntuuitoolkit.QQuickFlickable, objectName='flickable') qquickflickable.margin_to_swipe_from_right = units.gu(6) containers = qquickflickable._get_containers() rightmost = _flickable._get_visible_container_rightmost(containers) with mock.patch.object(qquickflickable.pointing_device, 'drag') as mock_drag: try: qquickflickable.swipe_to_show_more_right() except ubuntuuitoolkit.ToolkitException: # An exception will be raised because the drag was faked. pass mock_drag.assert_called_with(rightmost - units.gu(6), mock.ANY, mock.ANY, mock.ANY, rate=mock.ANY)
def test_gu(self): pixels = units.gu(self.WIDTH_IN_GU) self.assertEquals(pixels, self.expected_pixels)
class QQuickFlickable(Scrollable): # Swiping from below can open the deprecated toolbar or trigger the bottom # edge gesture. Use this margin to start a swipe that will not be that # close to the bottom edge. margin_to_swipe_from_bottom = units.gu(2) # Swiping from above can open the indicators or resize the window. Use this # margin to start a swipe that will not be that close to the top edge. margin_to_swipe_from_top = units.gu(2) # Swiping from left and right can show the launcher or open app switcher. margin_to_swipe_from_left = units.gu(3) margin_to_swipe_from_right = units.gu(3) @autopilot_logging.log_action(logger.info) def swipe_child_into_view(self, child): """Make the child visible. """ containers = self._get_containers() if not self._is_child_visible(child, containers): self._swipe_non_visible_child_into_view(child, containers) else: logger.debug('The element is already visible.') @autopilot_logging.log_action(logger.info) def _swipe_non_visible_child_into_view(self, child, containers): while not self._is_child_in_visible_y_range(child, containers): # Check the direction of the swipe based on the position of the # child relative to the immediate flickable container. if child.globalRect.y < self.globalRect.y: self.swipe_to_show_more_above(containers) else: self.swipe_to_show_more_below(containers) while not self._is_child_in_visible_x_range(child, containers): if child.globalRect.x < self.globalRect.x: self.swipe_to_show_more_left(containers) else: self.swipe_to_show_more_right(containers) @autopilot_logging.log_action(logger.info) def swipe_to_show_more_above(self, containers=None): if self.atYBeginning: raise CannotSwipeMoreToolkitException( "We are already at the top of the container.") else: self._swipe_to_show_more('above', containers) @autopilot_logging.log_action(logger.info) def swipe_to_show_more_below(self, containers=None): if self.atYEnd: raise CannotSwipeMoreToolkitException( "We are already at the bottom of the container.") else: self._swipe_to_show_more('below', containers) @autopilot_logging.log_action(logger.info) def swipe_to_show_more_left(self, containers=None): if self.atXBeginning: raise CannotSwipeMoreToolkitException( "We are already at the left of the container.") else: self._swipe_to_show_more('left', containers) @autopilot_logging.log_action(logger.info) def swipe_to_show_more_right(self, containers=None): if self.atXEnd: raise CannotSwipeMoreToolkitException( "We are already at the right of the container.") else: self._swipe_to_show_more('right', containers) def _swipe_to_show_more(self, direction, containers=None): if containers is None: containers = self._get_containers() start_x = stop_x = self.globalRect.x + (self.globalRect.width // 2) start_y = stop_y = self.globalRect.y + (self.globalRect.height // 2) top = _get_visible_container_top(containers) bottom = _get_visible_container_bottom(containers) leftmost = _get_visible_container_leftmost(containers) rightmost = _get_visible_container_rightmost(containers) # Make the drag range be a multiple of the drag "rate" value. # Workarounds https://bugs.launchpad.net/mir/+bug/1399690 rate = self._slow_drag_rate() # The swipes are not done from right at the top and bottom because # they could trigger edge gestures or resize windows. if direction == 'below': start_y = bottom - self.margin_to_swipe_from_bottom stop_y = start_y + (top - start_y) / rate * rate elif direction == 'above': start_y = top + self.margin_to_swipe_from_top stop_y = start_y + (bottom - start_y) / rate * rate elif direction == 'left': start_x = leftmost + self.margin_to_swipe_from_left stop_x = start_x + (rightmost - start_x) / rate * rate elif direction == 'right': start_x = rightmost - self.margin_to_swipe_from_right stop_x = start_x + (leftmost - start_x) / rate * rate else: raise _common.ToolkitException( 'Invalid direction {}.'.format(direction)) self._slow_drag(start_x, stop_x, start_y, stop_y, rate) self.dragging.wait_for(False) self.moving.wait_for(False) @autopilot_logging.log_action(logger.info) def swipe_to_top(self): if not self.atYBeginning: containers = self._get_containers() while not self.atYBeginning: self.swipe_to_show_more_above(containers) @autopilot_logging.log_action(logger.info) def swipe_to_bottom(self): if not self.atYEnd: containers = self._get_containers() while not self.atYEnd: self.swipe_to_show_more_below(containers) @autopilot_logging.log_action(logger.info) def swipe_to_leftmost(self): if not self.atXBeginning: containers = self._get_containers() while not self.atXBeginning: self.swipe_to_show_more_left(containers) def swipe_to_rightmost(self): if not self.atXEnd: containers = self._get_containers() while not self.atXEnd: self.swipe_to_show_more_right(containers) @autopilot_logging.log_action(logger.info) def pull_to_refresh(self): """Pulls the flickable down and triggers a refresh on it. :raises ubuntuuitoolkit.ToolkitException: If the flickable has no pull to release functionality. """ try: pull_to_refresh = self.select_single(PullToRefresh) except autopilot.exceptions.StateNotFoundError: raise _common.ToolkitException( 'The flickable has no pull to refresh functionality.') self.swipe_to_top() self._swipe_to_middle() pull_to_refresh.wait_for_refresh() @autopilot_logging.log_action(logger.info) def _swipe_to_middle(self): start_x = stop_x = self.globalRect.x + (self.globalRect.width // 2) # Start just a little under the top. containers = self._get_containers() top = _get_visible_container_top(containers) + 5 bottom = _get_visible_container_bottom(containers) start_y = top stop_y = (self.globalRect.y + bottom) // 2 self._slow_drag(start_x, stop_x, start_y, stop_y) self.dragging.wait_for(False) self.moving.wait_for(False) @autopilot_logging.log_action(logger.info) def _cancel_pull_to_refresh(self): """Swipe down the list and then swipe it up to cancel the refresh.""" # This method is kept private because it's not for the test writers to # call. It's to test pull to refresh. --elopio - 2014-05-22 self.swipe_to_top() start_x = stop_x = self.globalRect.x + (self.globalRect.width // 2) # Start just a little under the top. containers = self._get_containers() top = _get_visible_container_top(containers) + 5 bottom = _get_visible_container_bottom(containers) start_y = top stop_y = (self.globalRect.y + bottom) // 2 self.pointing_device.move(start_x, start_y) self.pointing_device.press() self.pointing_device.move(stop_x, stop_y) self.pointing_device.move(start_x, start_y) self.pointing_device.release()