~zsombi/ubuntu-ui-toolkit/layouts-visibility

« back to all changes in this revision

Viewing changes to tests/autopilot/ubuntuuitoolkit/_custom_proxy_objects/_common.py

  • Committer: Zsombor Egri
  • Date: 2014-05-20 19:36:40 UTC
  • mfrom: (1040.2.22 staging)
  • Revision ID: zsombor.egri@canonical.com-20140520193640-32gmzl12uozw8k4z
staging merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Common helpers for Ubuntu UI Toolkit Autopilot custom proxy objects."""
18
18
 
 
19
import logging
19
20
from distutils import version
20
21
 
21
22
import autopilot
22
 
from autopilot import platform, input
 
23
from autopilot import (
 
24
    input,
 
25
    logging as autopilot_logging,
 
26
    platform
 
27
)
23
28
from autopilot.introspection import dbus
24
29
 
25
30
 
 
31
logger = logging.getLogger(__name__)
 
32
 
 
33
 
26
34
class ToolkitException(Exception):
27
35
    """Exception raised when there is an error with the emulator."""
28
36
 
67
75
        check_autopilot_version()
68
76
        super(UbuntuUIToolkitCustomProxyObjectBase, self).__init__(*args)
69
77
        self.pointing_device = get_pointing_device()
 
78
 
 
79
    def is_flickable(self):
 
80
        """Check if the object is flickable.
 
81
 
 
82
        If the object has a flicking attribute, we consider it as a flickable.
 
83
 
 
84
        :return: True if the object is flickable. False otherwise.
 
85
 
 
86
        """
 
87
        try:
 
88
            self.flicking
 
89
            return True
 
90
        except AttributeError:
 
91
            return False
 
92
 
 
93
    @autopilot_logging.log_action(logger.info)
 
94
    def swipe_into_view(self):
 
95
        """Make the object visible.
 
96
 
 
97
        Currently it works only when the object needs to be swiped vertically.
 
98
        TODO implement horizontal swiping. --elopio - 2014-03-21
 
99
 
 
100
        """
 
101
        flickable_parent = self._get_flickable_parent()
 
102
        flickable_parent.swipe_child_into_view(self)
 
103
 
 
104
    def _get_flickable_parent(self):
 
105
        parent = self.get_parent()
 
106
        root = self.get_root_instance()
 
107
        while parent.id != root.id:
 
108
            if parent.is_flickable():
 
109
                return parent
 
110
            parent = parent.get_parent()
 
111
        raise ToolkitException(
 
112
            "The element is not contained in a Flickable so it can't be "
 
113
            "swiped into view.")