~tpeeters/ubuntu-ui-toolkit/tabBar-selectionMode-fix

« back to all changes in this revision

Viewing changes to tests/autopilot/ubuntuuitoolkit/emulators.py

  • Committer: tpeeters
  • Date: 2013-11-20 09:36:13 UTC
  • mfrom: (831.1.10 ubuntu-ui-toolkit)
  • Revision ID: tim.peeters@canonical.com-20131120093613-hpd8s03bbeqtwp4s
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
426
426
 
427
427
 
428
428
class Empty(UbuntuUIToolkitEmulatorBase):
429
 
    """Base class to emulate swipe to delete"""
 
429
    """Base class to emulate swipe to delete."""
 
430
 
 
431
    def exists(self):
 
432
        try:
 
433
            return self.implicitHeight > 0
 
434
        except dbus.StateNotFoundError:
 
435
            return False
430
436
 
431
437
    def _get_confirm_button(self):
432
438
        return self.select_single(
433
439
            'QQuickItem', objectName='confirmRemovalDialog')
434
440
 
435
441
    def swipe_to_delete(self, direction='right'):
436
 
        """ Swipe the item in a specific direction """
 
442
        """Swipe the item in a specific direction."""
437
443
        if (self.removable):
438
 
            x, y, w, h = self.globalRect
439
 
            tx = x + (w / 8)
440
 
            ty = y + (h / 2)
441
 
 
442
 
            if (direction == 'right'):
443
 
                self.pointing_device.drag(tx, ty, w, ty)
444
 
            elif (direction == 'left'):
445
 
                self.pointing_device.drag(w - (w*0.1), ty, x, ty)
 
444
            self._drag_pointing_device_to_delete(direction)
 
445
            if self.confirmRemoval:
 
446
                self.waitingConfirmationForRemoval.wait_for(True)
446
447
            else:
447
 
                raise ToolkitEmulatorException(
448
 
                    'Invalid direction "{0}" used on swipe to delete function'
449
 
                    .format(direction))
450
 
 
451
 
            self.waitingConfirmationForRemoval.wait_for(True)
 
448
                self._wait_until_deleted()
452
449
        else:
453
450
            raise ToolkitEmulatorException(
454
451
                'The item "{0}" is not removable'.format(self.objectName))
455
452
 
 
453
    def _drag_pointing_device_to_delete(self, direction):
 
454
        x, y, w, h = self.globalRect
 
455
        tx = x + (w / 8)
 
456
        ty = y + (h / 2)
 
457
 
 
458
        if (direction == 'right'):
 
459
            self.pointing_device.drag(tx, ty, w, ty)
 
460
        elif (direction == 'left'):
 
461
            self.pointing_device.drag(w - (w*0.1), ty, x, ty)
 
462
        else:
 
463
            raise ToolkitEmulatorException(
 
464
                'Invalid direction "{0}" used on swipe to delete function'
 
465
                .format(direction))
 
466
 
 
467
    def _wait_until_deleted(self):
 
468
        try:
 
469
            # The item was hidden.
 
470
            self.implicitHeight.wait_for(0)
 
471
        except dbus.StateNotFoundError:
 
472
            # The item was destroyed.
 
473
            pass
 
474
 
456
475
    def confirm_removal(self):
457
 
        """ Comfirm item removal if this was already swiped """
 
476
        """Comfirm item removal if this was already swiped."""
458
477
        if (self.waitingConfirmationForRemoval):
459
478
            deleteButton = self._get_confirm_button()
460
479
            self.pointing_device.click_object(deleteButton)
461
 
            self.implicitHeight.wait_for(0)
 
480
            self._wait_until_deleted()
462
481
        else:
463
482
            raise ToolkitEmulatorException(
464
483
                'The item "{0}" is not waiting for removal confirmation'.