88
88
:return: The toolbar.
91
toolbar = self.get_toolbar()
92
toolbar.animating.wait_for(False)
93
if not toolbar.opened:
94
self._drag_to_open_toolbar()
95
toolbar.opened.wait_for(True)
96
toolbar.animating.wait_for(False)
100
def _drag_to_open_toolbar(self):
101
x, y, _, _ = self.globalRect
102
line_x = x + self.width * 0.50
103
start_y = y + self.height - 1
104
stop_y = y + self.height - self.get_toolbar().height
106
self.pointing_device.drag(line_x, start_y, line_x, stop_y)
91
return self.get_toolbar().open()
108
93
def close_toolbar(self):
109
94
"""Close the toolbar if it's opened."""
110
toolbar = self.get_toolbar()
111
toolbar.animating.wait_for(False)
113
self._drag_to_close_toolbar()
114
toolbar.opened.wait_for(False)
115
toolbar.animating.wait_for(False)
117
def _drag_to_close_toolbar(self):
118
x, y, _, _ = self.globalRect
119
line_x = x + self.width * 0.50
120
start_y = y + self.height - self.get_toolbar().height
121
stop_y = y + self.height - 1
123
self.pointing_device.drag(line_x, start_y, line_x, stop_y)
95
self.get_toolbar().close()
125
97
def get_tabs(self):
126
98
"""Return the Tabs emulator of the MainView.
244
216
class Toolbar(UbuntuUIToolkitEmulatorBase):
245
217
"""Toolbar Autopilot emulator."""
220
"""Open the toolbar if it's not already opened.
222
:return: The toolbar.
225
self.animating.wait_for(False)
228
self.opened.wait_for(True)
229
self.animating.wait_for(False)
233
def _drag_to_open(self):
234
x, y, _, _ = self.globalRect
235
line_x = x + self.width * 0.50
236
start_y = y + self.height - 1
239
self.pointing_device.drag(line_x, start_y, line_x, stop_y)
242
"""Close the toolbar if it's opened."""
243
self.animating.wait_for(False)
245
self._drag_to_close()
246
self.opened.wait_for(False)
247
self.animating.wait_for(False)
249
def _drag_to_close(self):
250
x, y, _, _ = self.globalRect
251
line_x = x + self.width * 0.50
253
stop_y = y + self.height - 1
255
self.pointing_device.drag(line_x, start_y, line_x, stop_y)
247
257
def click_button(self, object_name):
248
258
"""Click a button of the toolbar.
260
The toolbar should be opened before clicking the button, or an
261
exception will be raised. If the toolbar is closed for some reason
262
(e.g., timer finishes) after moving the mouse cursor and before
263
clicking the button, it is re-opened automatically by this function.
250
265
:parameter object_name: The QML objectName property of the button.
251
266
:raise ToolkitEmulatorException: If there is no button with that object
257
272
except dbus.StateNotFoundError:
258
273
raise ToolkitEmulatorException(
259
274
'Button with objectName "{0}" not found.'.format(object_name))
275
# ensure the toolbar is open
277
raise ToolkitEmulatorException(
278
'Toolbar must be opened before calling click_button().')
279
self.pointing_device.move_to_object(button)
280
# ensure the toolbar is still open (may have closed due to timeout)
260
283
self.pointing_device.click_object(button)
262
285
def _get_button(self, object_name):
405
428
class Empty(UbuntuUIToolkitEmulatorBase):
406
"""Base class to emulate swipe to delete"""
429
"""Base class to emulate swipe to delete."""
433
return self.implicitHeight > 0
434
except dbus.StateNotFoundError:
408
437
def _get_confirm_button(self):
409
438
return self.select_single(
410
439
'QQuickItem', objectName='confirmRemovalDialog')
412
441
def swipe_to_delete(self, direction='right'):
413
""" Swipe the item in a specific direction """
442
"""Swipe the item in a specific direction."""
414
443
if (self.removable):
415
x, y, w, h = self.globalRect
419
if (direction == 'right'):
420
self.pointing_device.drag(tx, ty, w, ty)
421
elif (direction == 'left'):
422
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)
424
raise ToolkitEmulatorException(
425
'Invalid direction "{0}" used on swipe to delete function'
428
self.waitingConfirmationForRemoval.wait_for(True)
448
self._wait_until_deleted()
430
450
raise ToolkitEmulatorException(
431
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.
433
475
def confirm_removal(self):
434
""" Comfirm item removal if this was already swiped """
476
"""Comfirm item removal if this was already swiped."""
435
477
if (self.waitingConfirmationForRemoval):
436
478
deleteButton = self._get_confirm_button()
437
479
self.pointing_device.click_object(deleteButton)
438
self.implicitHeight.wait_for(0)
480
self._wait_until_deleted()
440
482
raise ToolkitEmulatorException(
441
483
'The item "{0}" is not waiting for removal confirmation'.