Debian Codegraph @

tests/autopilot/lomiriuitoolkit/_custom_proxy_objects/_actionbar.py

raw
1 # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2 #
3 # Copyright (C) 2015 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 from lomiriuitoolkit._custom_proxy_objects import _common
22 from lomiriuitoolkit._custom_proxy_objects import _flickable
23
24
25 logger = logging.getLogger(__name__)
26
27
28 class ActionBar(_common.LomiriUIToolkitCustomProxyObjectBase):
29 """ActionBar Autopilot custom proxy object."""
30
31 def __init__(self, *args):
32 super().__init__(*args)
33 # listview will only be set for a scrolling ActionBar.
34 try:
35 self.listview = self.select_single(objectName='actions_listview')
36 except dbus.StateNotFoundError:
37 self.listview = None
38
39 def _open_overflow(self):
40 """Click the overflow button and return the overflow panel"""
41 actions_overflow_button = self.select_single(
42 objectName='overflow_action_button')
43
44 if not actions_overflow_button.visible:
45 raise _common.ToolkitException('No actions in overflow')
46
47 # open the popover
48 self.pointing_device.click_object(actions_overflow_button)
49
50 # the popover is not a child of the ActionBar, so use the popover
51 # object to find the requested button
52 try:
53 popover = self.get_root_instance().select_single(
54 objectName='actions_overflow_panel')
55 except dbus.StateNotFoundError:
56 raise _common.ToolkitException(
57 'Failed to select overflow panel')
58
59 return popover
60
61 def _overflow_bar_click_action_button(self, action_object_name):
62 try:
63 object_name = action_object_name + "_button"
64 button = self.select_single(objectName=object_name)
65 # In an animating header, the button is disabled until the header
66 # animation is done. Wait for that:
67 button.enabled.wait_for(True)
68 self.pointing_device.click_object(button)
69 except dbus.StateNotFoundError:
70 # the button is not in the ActionBar, but it may be in the overflow
71 try:
72 popover = self._open_overflow()
73 popover.click_action_button(action_object_name)
74 except _common.ToolkitException:
75 raise _common.ToolkitException(
76 'Button not found')
77
78 def _scrolling_bar_click_action_button(self, action_object_name):
79 buttonName = action_object_name + "_button"
80 try:
81 self.listview.click_element(buttonName)
82 except _flickable.CannotSwipeMoreToolkitException:
83 # The button was found, but is not inside the ListView. This
84 # happens because at the beginning and end of the ListView
85 # there are list items visible inside the extra margins. But
86 # the buttons are present otherwise a different error message
87 # wass given.
88 button = self.listview.select_single(objectName=buttonName)
89 self.pointing_device.click_object(button)
90 except _common.ToolkitException:
91 raise _common.ToolkitException('Button not found')
92
93 @autopilot_logging.log_action(logger.info)
94 def click_action_button(self, action_object_name):
95 """Click an action button of the action bar.
96
97 :parameter object_name: The QML objectName property of the action
98 :raise ToolkitException: If there is no action button with that object
99 name.
100
101 """
102 if self.styleName == "ActionBarStyle":
103 return self._overflow_bar_click_action_button(action_object_name)
104 elif self.styleName == "ScrollingActionBarStyle":
105 return self._scrolling_bar_click_action_button(action_object_name)
106 else:
107 raise _common.ToolkitException(
108 'Unsupported style name ' + self.styleName + ' for ActionBar.')