| 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 TabBar(_common.LomiriUIToolkitCustomProxyObjectBase): |
| 27 |
"""TabBar Autopilot custom proxy object.""" |
| 28 |
|
| 29 |
@autopilot_logging.log_action(logger.info) |
| 30 |
def switch_to_next_tab(self): |
| 31 |
"""Open the next tab.""" |
| 32 |
self._activate_tab_bar() |
| 33 |
logger.debug('Click the next tab bar button.') |
| 34 |
self.pointing_device.click_object(self._get_next_tab_button()) |
| 35 |
|
| 36 |
def _activate_tab_bar(self): |
| 37 |
# First move to the tab bar to avoid timing issues when we find it in |
| 38 |
# selection mode but it's deselected while we move to it. |
| 39 |
self.pointing_device.move_to_object(self) |
| 40 |
if self.selectionMode: |
| 41 |
logger.debug('Already in selection mode.') |
| 42 |
else: |
| 43 |
# Click the tab bar to switch to selection mode. |
| 44 |
logger.debug('Click the tab bar to enable selection mode.') |
| 45 |
self.pointing_device.click_object(self) |
| 46 |
|
| 47 |
def _get_next_tab_button(self): |
| 48 |
current_index = self._get_selected_button_index() |
| 49 |
next_index = (current_index + 1) % self._get_number_of_tab_buttons() |
| 50 |
return self._get_tab_button(next_index) |
| 51 |
|
| 52 |
def _get_selected_button_index(self): |
| 53 |
return self.select_single('QQuickPathView').selectedButtonIndex |
| 54 |
|
| 55 |
def _get_number_of_tab_buttons(self): |
| 56 |
return len(self._get_tab_buttons()) |
| 57 |
|
| 58 |
def _get_tab_buttons(self): |
| 59 |
# TabBar is only used before 1.3, when there was no UCAbstractButton |
| 60 |
return self.select_many('AbstractButton') |
| 61 |
|
| 62 |
def _get_tab_button(self, index): |
| 63 |
buttons = self._get_tab_buttons() |
| 64 |
for button in buttons: |
| 65 |
if button.buttonIndex == index: |
| 66 |
return button |
| 67 |
raise _common.ToolkitException( |
| 68 |
'There is no tab button with index {0}.'.format(index)) |