428
428
class Empty(UbuntuUIToolkitEmulatorBase):
429
"""Base class to emulate swipe to delete"""
429
"""Base class to emulate swipe to delete."""
433
return self.implicitHeight > 0
434
except dbus.StateNotFoundError:
431
437
def _get_confirm_button(self):
432
438
return self.select_single(
433
439
'QQuickItem', objectName='confirmRemovalDialog')
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
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)
447
raise ToolkitEmulatorException(
448
'Invalid direction "{0}" used on swipe to delete function'
451
self.waitingConfirmationForRemoval.wait_for(True)
448
self._wait_until_deleted()
453
450
raise ToolkitEmulatorException(
454
451
'The item "{0}" is not removable'.format(self.objectName))
453
def _drag_pointing_device_to_delete(self, direction):
454
x, y, w, h = self.globalRect
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)
463
raise ToolkitEmulatorException(
464
'Invalid direction "{0}" used on swipe to delete function'
467
def _wait_until_deleted(self):
469
# The item was hidden.
470
self.implicitHeight.wait_for(0)
471
except dbus.StateNotFoundError:
472
# The item was destroyed.
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()
463
482
raise ToolkitEmulatorException(
464
483
'The item "{0}" is not waiting for removal confirmation'.