Debian Codegraph @

tests/autopilot/lomiri_gallery_app/emulators/picker_screen.py

raw
1 # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2 # Copyright 2012-2015 Canonical Ltd.
3 #
4 # This program is free software: you can redistribute it and/or modify it
5 # under the terms of the GNU General Public License version 3, as published
6 # by the Free Software Foundation.
7
8 from lomiriuitoolkit import emulators as toolkit_emulators
9 from lomiri_gallery_app.emulators.gallery_utils import GalleryAppException
10
11
12 class PickerScreen(toolkit_emulators.MainView):
13
14 def pick_button(self):
15 return self.select_single(objectName="pickButton_button")
16
17 def get_photos_tab_button(self):
18 """Returns the photos tab."""
19 return self.select_single("AbstractButton", buttonIndex=3)
20
21 def events_view(self):
22 return self.select_single("OrganicView", objectName="eventSelectView")
23
24 def first_media_in_events_view(self):
25 events_view = self.events_view()
26 return events_view.select_many("OrganicItemInteraction",
27 objectName="eventsViewPhoto")[0]
28
29 def grid_view(self):
30 return self.select_single("MediaGrid")
31
32 def first_media_in_grid_view(self):
33 grid_view = self.grid_view()
34 return grid_view.select_many("OrganicItemInteraction")[0]
35
36 def go_to_photos(self):
37 """
38 Switch to the photos tab on picker screen
39 Return the Page object representing the photos
40 """
41 self.switch_to_tab('photosTab')
42 return self.select_single(Page, objectName='photosPage')
43
44 def click_pick_button(self):
45 """Click on the pick button"""
46 self.pointing_device.click_object(self.pick_button())
47
48
49 class Page(PickerScreen):
50 """Class to represent photos page view from picker screen"""
51
52 def _get_named_photo_element(self, photo_name):
53 """
54 Return the ShapeItem container object for the named photo.
55 This object can be clicked to enable the photo to be selected.
56 """
57 elements = self.grid_view().select_many('QQuickImage')
58 for element in elements:
59 element.status.wait_for(1)
60 src = element.source.split('?')[0]
61 if str(src).endswith(photo_name):
62 return element.get_parent()
63 raise GalleryAppException(
64 'Photo with image name {} could not be found'.format(photo_name))
65
66 def select_named_photo(self, photo_name):
67 """Select the named photo from the picker view."""
68 photo_element = self._get_named_photo_element(photo_name)
69 checkbox = photo_element.select_single(objectName="selectionCheckbox")
70 self.pointing_device.click_object(checkbox)