~phablet-team/camera-app/trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
# Copyright 2014, 2015 Canonical
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 3, as published
# by the Free Software Foundation.

import logging

import ubuntuuitoolkit
from autopilot import logging as autopilot_logging


logger = logging.getLogger(__name__)


class Panel(ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase):
    """Panel Autopilot emulator."""

    @autopilot_logging.log_action(logger.info)
    def open(self):
        """Open the panel if it's not already opened.

        :return: The panel.

        """
        self.ready.wait_for(True)
        self.animating.wait_for(False)
        if not self.opened:
            self._drag_to_open()
            self.opened.wait_for(True)
            self.animating.wait_for(False)

        return self

    def _drag_to_open(self):
        x, y, _, _ = self.globalRect
        center_x = x + self.width * 0.50
        center_y = y + self.height * 0.50

        view_switcher = self.get_root_instance().wait_select_single(
            objectName="viewSwitcher")

        # FIXME: a rate higher than 1 does not always make panel move
        if view_switcher.state == "PORTRAIT":
            self.pointing_device.drag(center_x, y + self.height - 1,
                                      center_x, y, rate=1,
                                      time_between_events=0.0001)
        elif view_switcher.state == "LANDSCAPE":
            self.pointing_device.drag(0, center_y,
                                      self.height - 1, center_y, rate=1,
                                      time_between_events=0.0001)
        elif view_switcher.state == "INVERTED_LANDSCAPE":
            self.pointing_device.drag(x + self.height - 1, center_y,
                                      x, center_y, rate=1,
                                      time_between_events=0.0001)
        else:
            self.pointing_device.drag(center_x, y + self.height - 1,
                                      center_x, y, rate=1,
                                      time_between_events=0.0001)

    @autopilot_logging.log_action(logger.info)
    def close(self):
        """Close the panel if it's opened."""
        self.ready.wait_for(True)
        self.animating.wait_for(False)
        if self.opened:
            self._drag_to_close()
            self.opened.wait_for(False)
            self.animating.wait_for(False)

    def _drag_to_close(self):
        x, y, _, _ = self.globalRect
        center_y = y + self.height * 0.50

        view_switcher = self.get_root_instance().wait_select_single(
            objectName="viewSwitcher")

        # FIXME: a rate higher than 1 does not always make panel move
        if view_switcher.state == "PORTRAIT":
            self.pointing_device.drag(x, y,
                                      x, y + self.height - 1, rate=1,
                                      time_between_events=0.0001)
        elif view_switcher.state == "LANDSCAPE":
            self.pointing_device.drag(self.height - 1, center_y,
                                      0, center_y, rate=1,
                                      time_between_events=0.0001)
        elif view_switcher.state == "INVERTED_LANDSCAPE":
            self.pointing_device.drag(x, center_y,
                                      x + self.height - 1, center_y, rate=1,
                                      time_between_events=0.0001)
        else:
            self.pointing_device.drag(x, y,
                                      x, y + self.height - 1, rate=1,
                                      time_between_events=0.0001)