1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2
# Copyright 2012 Canonical
3
# Author: Thomi Richards
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.
11
from time import sleep
13
from autopilot.emulators.unity import UnityIntrospectionObject
14
from autopilot.emulators.X11 import Mouse
17
logger = logging.getLogger(__name__)
20
class Quicklist(UnityIntrospectionObject):
21
"""Represents a quicklist."""
25
"""Individual items in the quicklist."""
26
return self.get_children_by_type(QuicklistMenuItem)
28
def get_quicklist_item_by_text(self, text):
29
"""Returns a QuicklistMenuItemLabel object with the given text, or None."""
31
raise RuntimeError("Cannot get quicklist items. Quicklist is inactive!")
33
matches = filter(lambda i: i.text == text,
34
self.get_children_by_type(QuicklistMenuItemLabel))
36
return matches[0] if matches else None
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")
43
logger.debug("Clicking on quicklist item %r", item)
45
mouse.move(self.x + item.x + (item.width / 2),
46
self.y + item.y + (item.height / 2))
51
class QuicklistMenuItem(UnityIntrospectionObject):
52
"""Represents a single item in a quicklist."""
55
class QuicklistMenuItemLabel(QuicklistMenuItem):
56
"""Represents a text label inside a quicklist."""
59
class QuicklistMenuItemSeparator(QuicklistMenuItem):
60
"""Represents a separator in a quicklist."""