~azzar1/unity/fix-trash-li-blocking

« back to all changes in this revision

Viewing changes to tests/autopilot/autopilot/emulators/unity/hud.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
from autopilot.keybindings import KeybindingsHelper
 
11
from autopilot.emulators.unity import UnityIntrospectionObject
 
12
 
 
13
 
 
14
class HudView(UnityIntrospectionObject):
 
15
    """Proxy object for the hud view child of the controller."""
 
16
 
 
17
 
 
18
class HudController(UnityIntrospectionObject, KeybindingsHelper):
 
19
    """Proxy object for the Unity Hud Controller."""
 
20
 
 
21
    def ensure_hidden(self):
 
22
        """Hides the hud if it's not already hidden."""
 
23
        if self.is_visible():
 
24
            self.toggle_reveal()
 
25
 
 
26
    def ensure_visible(self):
 
27
        """Shows the hud if it's not already showing."""
 
28
        if not self.is_visible():
 
29
            self.toggle_reveal()
 
30
 
 
31
    def is_visible(self):
 
32
        return self.visible
 
33
 
 
34
    def toggle_reveal(self, tap_delay=0.1):
 
35
        """Tap the 'Alt' key to toggle the hud visibility."""
 
36
        self.keybinding("hud/reveal", tap_delay)
 
37
 
 
38
    def _get_view(self):
 
39
        views = self.get_children_by_type(HudView)
 
40
        return views[0] if views else None
 
41
 
 
42
    @property
 
43
    def selected_button(self):
 
44
        view = self._get_view()
 
45
        if view:
 
46
            return view.selected_button
 
47
        else:
 
48
            return 0
 
49
 
 
50
    @property
 
51
    def num_buttons(self):
 
52
        view = self._get_view()
 
53
        if view:
 
54
            return view.num_buttons
 
55
        else:
 
56
            return 0