| 1 |
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- |
| 2 |
# |
| 3 |
# Copyright (C) 2012, 2013, 2014 Canonical Ltd. |
| 4 |
# |
| 5 |
# This program is free software; you can redistribute it and/or modify |
| 6 |
# it under the terms of the GNU Lesser General Public License as published by |
| 7 |
# the Free Software Foundation; version 3. |
| 8 |
# |
| 9 |
# This program is distributed in the hope that it will be useful, |
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
# GNU Lesser General Public License for more details. |
| 13 |
# |
| 14 |
# You should have received a copy of the GNU Lesser General Public License |
| 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
|
| 17 |
import logging |
| 18 |
|
| 19 |
from autopilot import logging as autopilot_logging |
| 20 |
from lomiriuitoolkit._custom_proxy_objects import _common |
| 21 |
|
| 22 |
|
| 23 |
logger = logging.getLogger(__name__) |
| 24 |
|
| 25 |
|
| 26 |
class UCListItem(_common.LomiriUIToolkitCustomProxyObjectBase): |
| 27 |
"""Base class to emulate swipe for leading and trailing actions.""" |
| 28 |
|
| 29 |
@autopilot_logging.log_action(logger.info) |
| 30 |
def _swipe_in_panel(self, panel_item): |
| 31 |
""" Swipe in panel (leading/trailing)""" |
| 32 |
x, y, width, height = self.globalRect |
| 33 |
if panel_item == 'leading': |
| 34 |
start_x = x + (width * 0.2) |
| 35 |
stop_x = x + (width * 0.8) |
| 36 |
elif panel_item == 'trailing': |
| 37 |
start_x = x + (width * 0.8) |
| 38 |
stop_x = x + (width * 0.2) |
| 39 |
else: |
| 40 |
raise _common.ToolkitException( |
| 41 |
'No {0} panel found in a ListItem'.format(panel_item)) |
| 42 |
start_y = stop_y = y + (height // 2) |
| 43 |
self.pointing_device.drag(start_x, start_y, stop_x, stop_y) |
| 44 |
# wait till animation finishes |
| 45 |
self.contentMoving.wait_for(False) |
| 46 |
|
| 47 |
def _click_on_panel_action(self, panel_item, action_object, wait_function): |
| 48 |
self._swipe_in_panel(panel_item) |
| 49 |
try: |
| 50 |
button_name = 'actionbutton_' + action_object |
| 51 |
action_button = self.select_single(objectName=button_name) |
| 52 |
except: |
| 53 |
raise _common.ToolkitException( |
| 54 |
'The requested action not found on {0} side'. |
| 55 |
format(panel_item)) |
| 56 |
|
| 57 |
self.pointing_device.click_object(action_button) |
| 58 |
if wait_function is None: |
| 59 |
# wait till animation finishes |
| 60 |
self.contentMoving.wait_for(False) |
| 61 |
else: |
| 62 |
wait_function() |
| 63 |
|
| 64 |
@autopilot_logging.log_action(logger.info) |
| 65 |
def trigger_leading_action(self, action_objectName, wait_function=None): |
| 66 |
"""Swipe the item in from left to right to open leading actions |
| 67 |
and click on the button representing the requested action. |
| 68 |
|
| 69 |
parameters: action_objectName - object name of the action to be |
| 70 |
triggered. |
| 71 |
wait_function - a custom wait function to wait till the |
| 72 |
action is triggered |
| 73 |
""" |
| 74 |
self._click_on_panel_action('leading', action_objectName, |
| 75 |
wait_function) |
| 76 |
|
| 77 |
@autopilot_logging.log_action(logger.info) |
| 78 |
def trigger_trailing_action(self, action_objectName, wait_function=None): |
| 79 |
"""Swipe the item in from right to left to open trailing actions |
| 80 |
and click on the button representing the requested action. |
| 81 |
|
| 82 |
parameters: action_objectName - object name of the action to be |
| 83 |
triggered. |
| 84 |
wait_function - a custom wait function to wait till the |
| 85 |
action is triggered |
| 86 |
""" |
| 87 |
self._click_on_panel_action('trailing', action_objectName, |
| 88 |
wait_function) |
| 89 |
|
| 90 |
@autopilot_logging.log_action(logger.info) |
| 91 |
def toggle_selected(self): |
| 92 |
"""Toggles selected state of the ListItem. """ |
| 93 |
toggle = self.select_single(objectName='listitem_select') |
| 94 |
self.pointing_device.click_object(toggle) |