Debian Codegraph @

tests/autopilot/lomiriuitoolkit/_custom_proxy_objects/_optionselector.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
18 import time
19
20 from autopilot.introspection import dbus
21
22 from lomiriuitoolkit._custom_proxy_objects import _common
23
24
25 class OptionSelector(_common.LomiriUIToolkitCustomProxyObjectBase):
26 """OptionSelector Autopilot custom proxy object"""
27
28 def get_option_count(self):
29 """Gets the number of items in the option selector"""
30 self.list_view = self.select_single("QQuickListView")
31 return self.list_view.count
32
33 def get_selected_index(self):
34 """Gets the current selected index of the QQuickListView"""
35 self.list_view = self.select_single("QQuickListView")
36 return self.list_view.currentIndex
37
38 def get_selected_text(self):
39 """gets the text of the currently selected item"""
40 option_selector_delegate = self.select_single(
41 'OptionSelectorDelegate', focus='True')
42 current_label = option_selector_delegate.select_single(
43 'UCLabel', visible='True')
44 return current_label.text
45
46 def get_current_label(self):
47 """gets the text of the currently selected item"""
48 option_selector_delegate = self.select_single(
49 'OptionSelectorDelegate', focus='True')
50 current_label = option_selector_delegate.select_single(
51 'UCLabel', visible='True')
52 return current_label
53
54 def _expand(self):
55 """Expand an optionselector if it's collapsed"""
56 # if just collapsed it can think that the item is expanded
57 # https://bugs.launchpad.net/lomiri-ui-toolkit/+bug/1240288
58 time.sleep(1)
59 if not self.expanded and not self.currentlyExpanded:
60 self.pointing_device.click_object(self.get_current_label())
61 self.currentlyExpanded.wait_for(True)
62 # selecting the same item too quickly after expand
63 # causes the wrong item to be selected
64 # https://bugs.launchpad.net/lomiri-ui-toolkit/+bug/1231939
65 time.sleep(1)
66
67 def select_option(self, *args, **kwargs):
68 """Select delegate in option selector
69
70 Example usage::
71 select_option(objectName="myOptionSelectorDelegate")
72 select_option('UCLabel', text="some_text_here")
73
74 :parameter kwargs: keywords used to find property(s) of delegate in
75 option selector
76
77 """
78
79 if args:
80 try:
81 select_object = self.select_single(
82 *args,
83 **kwargs
84 )
85 except dbus.StateNotFoundError:
86 raise _common.ToolkitException(
87 'OptionSelectorDelegate with args {} and kwargs {} not '
88 'found'.format(args, kwargs)
89 )
90
91 else:
92 try:
93 select_object = self.select_single(
94 'OptionSelectorDelegate',
95 **kwargs
96 )
97 except dbus.StateNotFoundError:
98 raise _common.ToolkitException(
99 'OptionSelectorDelegate with kwargs {} not found'.format(
100 kwargs)
101 )
102
103 self._expand()
104 self.pointing_device.click_object(select_object)