| 1 |
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- |
| 2 |
# Copyright 2013, 2014 Canonical Ltd. |
| 3 |
# |
| 4 |
# This program is free software: you can redistribute it and/or modify it |
| 5 |
# under the terms of the GNU General Public License version 3, as published |
| 6 |
# by the Free Software Foundation. |
| 7 |
|
| 8 |
from autopilot.introspection.dbus import StateNotFoundError |
| 9 |
import logging |
| 10 |
from lomiriuitoolkit import emulators as toolkit_emulators |
| 11 |
|
| 12 |
logger = logging.getLogger(__name__) |
| 13 |
|
| 14 |
|
| 15 |
class Toolbar(toolkit_emulators.Toolbar): |
| 16 |
"""An emulator class that makes it easy to interact with the tool bar""" |
| 17 |
|
| 18 |
def click_button(self, object_name): |
| 19 |
"""Click a button of the toolbar. |
| 20 |
|
| 21 |
The toolbar should be opened before clicking the button, or an |
| 22 |
exception will be raised. If the toolbar is closed for some reason |
| 23 |
(e.g., timer finishes) after moving the mouse cursor and before |
| 24 |
clicking the button, it is re-opened automatically by this function. |
| 25 |
|
| 26 |
Overriden from the toolkit because of bug http://pad.lv/1302706 |
| 27 |
TODO remove this method once that bug is fixed on the toolkit. |
| 28 |
--elopio - 2014-04-04 |
| 29 |
|
| 30 |
:parameter object_name: The QML objectName property of the button. |
| 31 |
:raise ToolkitEmulatorException: If there is no button with that object |
| 32 |
name. |
| 33 |
|
| 34 |
""" |
| 35 |
# ensure the toolbar is open |
| 36 |
if not self.opened: |
| 37 |
raise toolkit_emulators.ToolkitEmulatorException( |
| 38 |
'Toolbar must be opened before calling click_button().') |
| 39 |
try: |
| 40 |
button = self._get_button(object_name) |
| 41 |
except StateNotFoundError: |
| 42 |
raise toolkit_emulators.ToolkitEmulatorException( |
| 43 |
'Button with objectName "{0}" not found.'.format(object_name)) |
| 44 |
self.pointing_device.move_to_object(button) |
| 45 |
# ensure the toolbar is still open (may have closed due to timeout) |
| 46 |
self.open() |
| 47 |
# click the button |
| 48 |
self.pointing_device.click_object(button) |
| 49 |
|
| 50 |
def click_custom_button(self, object_name): |
| 51 |
try: |
| 52 |
button = self.select_single('Button', objectName=object_name) |
| 53 |
self.pointing_device.click_object(button) |
| 54 |
except StateNotFoundError: |
| 55 |
logger.error( |
| 56 |
'Button with objectName "{0}" not found.'.format(object_name) |
| 57 |
) |
| 58 |
raise |