Debian Codegraph @

tests/autopilot/lomiriuitoolkit/_custom_proxy_objects/listitems.py

raw
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 autopilot.introspection import dbus
21
22 from lomiriuitoolkit._custom_proxy_objects import _common
23
24
25 logger = logging.getLogger(__name__)
26
27
28 class Empty(_common.LomiriUIToolkitCustomProxyObjectBase):
29 """Base class to emulate swipe to delete."""
30
31 def exists(self):
32 try:
33 return self.implicitHeight > 0
34 except dbus.StateNotFoundError:
35 return False
36
37 def _get_confirm_button(self):
38 return self.select_single(
39 'QQuickItem', objectName='confirmRemovalDialog')
40
41 @autopilot_logging.log_action(logger.info)
42 def swipe_to_delete(self, direction='deprecated'):
43 """Swipe the item in from left to right in order to delete it.
44
45 :param direction: deprecated. The only direction that will cause a
46 delete is left to right. Do not pass any argument to this method,
47 because it will be removed in future versions.
48
49 """
50 if direction != 'deprecated':
51 logger.warn(
52 'The direction argument is deprecated. Now the Lomiri SDK '
53 'only deletes list items when swiping from left to right. '
54 'Call swipe_to_delete without arguments.')
55 else:
56 direction = 'right'
57 if self.removable:
58 self._swipe_to_delete_removable_item(direction)
59 else:
60 raise _common.ToolkitException(
61 'The item "{0}" is not removable'.format(self.objectName))
62
63 def _swipe_to_delete_removable_item(self, direction):
64 if direction == 'left':
65 raise _common.ToolkitException(
66 'Only swiping to the right will cause the item to be deleted.')
67 elif direction != 'right':
68 raise _common.ToolkitException(
69 'Invalid direction "{0}" used on swipe to delete function'
70 .format(direction))
71
72 self._drag_pointing_device_to_delete()
73 if self.confirmRemoval:
74 self.waitingConfirmationForRemoval.wait_for(True)
75 else:
76 self._wait_until_deleted()
77
78 def _drag_pointing_device_to_delete(self):
79 x, y, width, height = self.globalRect
80 start_x = x + (width * 0.2)
81 stop_x = x + (width * 0.8)
82 start_y = stop_y = y + (height // 2)
83
84 self.pointing_device.drag(start_x, start_y, stop_x, stop_y)
85
86 def _wait_until_deleted(self):
87 try:
88 # The item was hidden.
89 self.implicitHeight.wait_for(0)
90 except dbus.StateNotFoundError:
91 # The item was destroyed.
92 pass
93
94 @autopilot_logging.log_action(logger.info)
95 def confirm_removal(self):
96 """Comfirm item removal if this was already swiped."""
97 if self.waitingConfirmationForRemoval:
98 deleteButton = self._get_confirm_button()
99 self.pointing_device.click_object(deleteButton)
100 self._wait_until_deleted()
101 else:
102 raise _common.ToolkitException(
103 'The item "{0}" is not waiting for removal confirmation'.
104 format(self.objectName))
105
106
107 class Base(Empty):
108 pass
109
110
111 class Expandable(Empty):
112
113 @autopilot_logging.log_action(logger.info)
114 def expand(self):
115 """Expand an expandable list item.
116
117 If the item is already expanded, no action will be executed.
118 If you want to check if the item is expanded, you can use the
119 ``expanded`` property.
120
121 """
122 if not self.expanded:
123 self._click_always_visible_section()
124 self.expanded.wait_for(True)
125 self.height.wait_for(self.expandedHeight)
126 else:
127 logger.debug('The item is already expanded.')
128
129 @autopilot_logging.log_action(logger.debug)
130 def _click_always_visible_section(self):
131 self.pointing_device.move(
132 self.globalRect.x + self.globalRect.width // 2,
133 self.globalRect.y + self.collapsedHeight // 2)
134 self.pointing_device.click()
135
136 @autopilot_logging.log_action(logger.info)
137 def collapse(self):
138 """Collapse an expandable list item.
139
140 If the item is already collapsed, no action will be executed.
141 If you want to check if the item is expanded, you can use the
142 ``expanded`` property.
143
144 """
145 if self.expanded:
146 self._click_always_visible_section()
147 self.expanded.wait_for(False)
148 self.height.wait_for(self.collapsedHeight)
149 else:
150 logger.debug('The item is already collapsed.')
151
152
153 class Standard(Empty):
154 pass
155
156
157 class ItemSelector(Empty):
158 pass
159
160
161 class SingleControl(Empty):
162 pass
163
164
165 class MultiValue(Base):
166 pass
167
168
169 class SingleValue(Base):
170 pass
171
172
173 class Subtitled(Base):
174 pass