Debian Codegraph @

tests/autopilot/lomiriuitoolkit/_custom_proxy_objects/_toolbar.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 Toolbar(_common.LomiriUIToolkitCustomProxyObjectBase):
29 """Toolbar Autopilot custom proxy object."""
30
31 @autopilot_logging.log_action(logger.info)
32 def open(self):
33 """Open the toolbar if it's not already opened.
34
35 :return: The toolbar.
36
37 """
38 self.animating.wait_for(False)
39 if not self.opened:
40 self._drag_to_open()
41 self.opened.wait_for(True)
42 self.animating.wait_for(False)
43
44 return self
45
46 def _drag_to_open(self):
47 x, y, _, _ = self.globalRect
48 line_x = x + self.width * 0.50
49 start_y = y + self.height - 1
50 stop_y = y
51
52 self.pointing_device.drag(line_x, start_y, line_x, stop_y)
53
54 @autopilot_logging.log_action(logger.info)
55 def close(self):
56 """Close the toolbar if it's opened."""
57 self.animating.wait_for(False)
58 if self.opened:
59 self._drag_to_close()
60 self.opened.wait_for(False)
61 self.animating.wait_for(False)
62
63 def _drag_to_close(self):
64 x, y, _, _ = self.globalRect
65 line_x = x + self.width * 0.50
66 start_y = y
67 stop_y = y + self.height - 1
68
69 self.pointing_device.drag(line_x, start_y, line_x, stop_y)
70
71 @autopilot_logging.log_action(logger.info)
72 def click_button(self, object_name):
73 """Click a button of the toolbar.
74
75 The toolbar should be opened before clicking the button, or an
76 exception will be raised. If the toolbar is closed for some reason
77 (e.g., timer finishes) after moving the mouse cursor and before
78 clicking the button, it is re-opened automatically by this function.
79
80 :parameter object_name: The QML objectName property of the button.
81 :raise ToolkitException: If there is no button with that object
82 name.
83
84 """
85 # ensure the toolbar is open
86 if not self.opened:
87 raise _common.ToolkitException(
88 'Toolbar must be opened before calling click_button().')
89 try:
90 button = self._get_button(object_name)
91 except dbus.StateNotFoundError:
92 raise _common.ToolkitException(
93 'Button with objectName "{0}" not found.'.format(object_name))
94 self.pointing_device.move_to_object(button)
95 # ensure the toolbar is still open (may have closed due to timeout)
96 self.open()
97 # click the button
98 self.pointing_device.click_object(button)
99
100 def _get_button(self, object_name):
101 return self.select_single(objectName=object_name)
102
103 @autopilot_logging.log_action(logger.info)
104 def click_back_button(self):
105 """Click the back button of the toolbar."""
106 self.click_button('back_toolbar_button')