~3v1n0/unity/overlay-border-scale

« back to all changes in this revision

Viewing changes to tests/autopilot/autopilot/emulators/unity/quicklist.py

  • Committer: Daniel van Vugt
  • Date: 2012-03-14 06:24:18 UTC
  • mfrom: (2108 unity)
  • mto: This revision was merged to the branch mainline in revision 2146.
  • Revision ID: daniel.van.vugt@canonical.com-20120314062418-nprucpbr0m7qky5e
MergedĀ latestĀ lp:unity

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
 
2
# Copyright 2012 Canonical
 
3
# Author: Thomi Richards
 
4
#
 
5
# This program is free software: you can redistribute it and/or modify it
 
6
# under the terms of the GNU General Public License version 3, as published
 
7
# by the Free Software Foundation.
 
8
#
 
9
 
 
10
import logging
 
11
from time import sleep
 
12
 
 
13
from autopilot.emulators.unity import UnityIntrospectionObject
 
14
from autopilot.emulators.X11 import Mouse
 
15
 
 
16
 
 
17
logger = logging.getLogger(__name__)
 
18
 
 
19
 
 
20
class Quicklist(UnityIntrospectionObject):
 
21
    """Represents a quicklist."""
 
22
 
 
23
    @property
 
24
    def items(self):
 
25
        """Individual items in the quicklist."""
 
26
        return self.get_children_by_type(QuicklistMenuItem)
 
27
 
 
28
    def get_quicklist_item_by_text(self, text):
 
29
        """Returns a QuicklistMenuItemLabel object with the given text, or None."""
 
30
        if not self.active:
 
31
            raise RuntimeError("Cannot get quicklist items. Quicklist is inactive!")
 
32
 
 
33
        matches = filter(lambda i: i.text == text,
 
34
            self.get_children_by_type(QuicklistMenuItemLabel))
 
35
 
 
36
        return matches[0] if matches else None
 
37
 
 
38
    def click_item(self, item):
 
39
        """Click one of the quicklist items."""
 
40
        if not isinstance(item, QuicklistMenuItem):
 
41
            raise TypeError("Item must be a subclass of QuicklistMenuItem")
 
42
 
 
43
        logger.debug("Clicking on quicklist item %r", item)
 
44
        mouse = Mouse()
 
45
        mouse.move(self.x + item.x + (item.width / 2),
 
46
                    self.y + item.y + (item.height / 2))
 
47
        sleep(0.25)
 
48
        mouse.click()
 
49
 
 
50
 
 
51
class QuicklistMenuItem(UnityIntrospectionObject):
 
52
    """Represents a single item in a quicklist."""
 
53
 
 
54
 
 
55
class QuicklistMenuItemLabel(QuicklistMenuItem):
 
56
    """Represents a text label inside a quicklist."""
 
57
 
 
58
 
 
59
class QuicklistMenuItemSeparator(QuicklistMenuItem):
 
60
    """Represents a separator in a quicklist."""