@@ -12,70 +12,97 @@
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
14# GNU General Public License for more details.
16# You should have received a copy of the GNU General Public License
15# You should have received a copy of the GNU General Public License
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
16# along with this program. If not, see <http://www.gnu.org/licenses/>.
19−from autopilot import input
20−from unity8.shell import emulators
21−from unity8.shell.emulators import main_window
22import ubuntuuitoolkit
18import ubuntuuitoolkit
19+from autopilot import introspection
21+from unity8.shell import emulators
25−class IndicatorsMenu(emulators.UnityEmulatorBase):
24+class IndicatorPage(emulators.UnityEmulatorBase):
27 """Autopilot helper for the IndicatorPage component."""
26 """Autopilot helper for the IndicatorPage component."""
29− def open(self):
28+ # XXX Because of https://bugs.launchpad.net/autopilot-qt/+bug/1341671
30− widget = self.select_single(
29+ # we need to make sure it does not match in any selection.
31− 'IndicatorItem', objectName='indicator-sound-panelItem')
32− start_x, start_y = input.get_center_point(widget)
34− end_y = self.globalRect.y + self.openedHeight
35− self.pointing_device.drag(start_x, start_y, end_x, end_y)
36− self.fullyOpened.wait_for(True)
38− def open_rotation_indicator(self):
40− indicators_bar_flickable = self.select_single(
41− 'IndicatorsBar').select_single(
42− main_window.QQuickFlickable, objectName='flickable')
43− indicators_bar_flickable.swipe_to_x_end()
44− indicator_rotation_icon = self.select_single(
45− objectName='indicator-rotation-lock-panelItem')
46− self.pointing_device.click_object(indicator_rotation_icon)
47− self.fullyOpened.wait_for(True)
48− return DisplayIndicator(
50− 'IndicatorPage', objectName='indicator-rotation-lock-page'))
32+ def validate_dbus_object(cls, path, state):
53−class DisplayIndicator(emulators.UnityEmulatorBase):
55− def __init__(self, subject):
36+class DisplayIndicator(object):
56− self.__subject = subject
58− def __getattr__(self, name):
38+ def __init__(self, main_window):
59− return getattr(self.__subject, name)
39+ self._main_window = main_window
61− def lock_rotation(self):
41+ def open(self):
62− """Toggles the rotation lock indicator to locked.
42+ """Open the display indicator page.
64− Swipes open indicator-display and ensures that rotation lock is toggled
44+ :return: The custom proxy object for the display indicator page.
47+ # TODO open the indicator directly if it is displayed in the menu.
48+ # open any displayed indicator.
49+ self._main_window.open_indicator_page('indicator-datetime')
50+ self._make_indicator_icon_visible()
51+ indicator_rotation_icon = self._main_window.select_single(
52+ objectName='indicator-rotation-lock-panelItem')
53+ self._main_window.pointing_device.click_object(indicator_rotation_icon)
54+ indicators_menu = self._main_window.select_single('IndicatorsMenu')
55+ indicators_menu.fullyOpened.wait_for(True)
56+ return self._main_window.select_single(
57+ objectName='indicator-rotation-lock-page')
59+ def _make_indicator_icon_visible(self):
68− switcher = self.select_single(
60+ indicators_bar_flickable = self._main_window.select_single(
61+ 'IndicatorsBar').select_single(
69− ubuntuuitoolkit.CheckBox, objectName='switcher')
62+ ubuntuuitoolkit.QQuickFlickable, objectName='flickable')
70− switcher.check()
63+ self._swipe_flickable_to_x_end(indicators_bar_flickable)
72− def unlock_rotation(self):
65+ def _swipe_flickable_to_x_end(self, flickable):
73− """Toggles the rotation lock indicator to unlocked.
66+ # XXX this should be implemented as a general horizontal swiping in
67+ # the toolkit custom proxy object.
68+ if not flickable.atXEnd:
69+ while not flickable.atXEnd:
71+ flickable.globalRect.y +
72+ (flickable.globalRect.height // 2))
73+ # We can't start the swipe from the border because it would
75+ start_x = flickable.globalRect.x + 45
77+ flickable.globalRect.x + flickable.globalRect.width - 5)
78+ flickable.pointing_device.drag(
79+ start_x, start_y, stop_x, stop_y)
80+ flickable.dragging.wait_for(False)
81+ flickable.moving.wait_for(False)
84+class DisplayIndicatorPage(IndicatorPage):
86+ """Autopilot helper for the display indicator page."""
89+ def validate_dbus_object(cls, path, state):
90+ name = introspection.get_classname_from_path(path)
91+ if name == b'IndicatorPage':
92+ if state['objectName'][1] == 'indicator-rotation-lock-page':
75− Swipes open indicator-display and ensures that rotation lock is toggled
96+ def lock_rotation(self):
76− to 'Off'.
97+ """Toggles the rotation lock indicator to locked."""
98+ switcher = self._get_switcher()
78− """
101+ def _get_switcher(self):
79− switcher = self.select_single(
102+ return self.select_single(
80 ubuntuuitoolkit.CheckBox, objectName='switcher')
103 ubuntuuitoolkit.CheckBox, objectName='switcher')
105+ def unlock_rotation(self):
106+ """Toggles the rotation lock indicator to unlocked."""
107+ switcher = self._get_switcher()
81 switcher.uncheck()
108 switcher.uncheck()