| 1 |
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*- |
| 2 |
# Copyright 2012 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 lomiri_gallery_app.emulators.gallery_utils import( |
| 9 |
GalleryAppException, |
| 10 |
GalleryUtils |
| 11 |
) |
| 12 |
|
| 13 |
|
| 14 |
class EventsView(GalleryUtils): |
| 15 |
|
| 16 |
def __init__(self, app): |
| 17 |
super(EventsView, self).__init__(self) |
| 18 |
self.app = app |
| 19 |
|
| 20 |
def get_event(self, event_number=0): |
| 21 |
"""Return an event in the event view based on index number |
| 22 |
|
| 23 |
:param event_number: the index number of the organicEventItem to get |
| 24 |
""" |
| 25 |
return self.app.select_single( |
| 26 |
'OrganicMediaList', |
| 27 |
objectName='organicEventItem{}'.format(int(event_number)) |
| 28 |
) |
| 29 |
|
| 30 |
def number_of_events(self): |
| 31 |
"""Return the number of events in the model behind the event view""" |
| 32 |
return self.app.select_single('EventsOverview')._eventCount |
| 33 |
|
| 34 |
def number_of_photos_in_events(self): |
| 35 |
"""Return the number of photos in events""" |
| 36 |
|
| 37 |
overview = self.app.select_single('EventsOverview') |
| 38 |
photo_delegates = overview.select_many( |
| 39 |
"QQuickItem", |
| 40 |
objectName="eventPhoto" |
| 41 |
) |
| 42 |
return len(photo_delegates) |
| 43 |
|
| 44 |
def number_of_photos_in_event(self, event): |
| 45 |
"""Return the number of photo delgated in an event""" |
| 46 |
photo_delegates = event.select_many(objectName='eventPhoto') |
| 47 |
return len(photo_delegates) |
| 48 |
|
| 49 |
def get_share_peer_picker(self): |
| 50 |
"""Returns the photo viewer share picker.""" |
| 51 |
return self.app.wait_select_single(objectName="sharePickerEvents", |
| 52 |
visible=True) |
| 53 |
|
| 54 |
def _get_image_in_event_view(self, image_name): |
| 55 |
"""Return the photo of the gallery based on image name. |
| 56 |
|
| 57 |
:param image_name: the name of the photo in the event to return""" |
| 58 |
events = self.app.select_many('OrganicMediaList') |
| 59 |
for event in events: |
| 60 |
photos = event.select_many( |
| 61 |
'QQuickItem', |
| 62 |
objectName='eventPhoto' |
| 63 |
) |
| 64 |
for photo in photos: |
| 65 |
images = photo.select_many('QQuickImage') |
| 66 |
for image in images: |
| 67 |
image.status.wait_for(1) |
| 68 |
src = image.source.split('?')[0] |
| 69 |
if str(src).endswith(image_name): |
| 70 |
return image |
| 71 |
raise GalleryAppException( |
| 72 |
'Photo with image name {} could not be found'.format(image_name)) |
| 73 |
|
| 74 |
def _get_item_in_event_view(self, image_name, event_index_num=0): |
| 75 |
"""Return the item of the gallery based on image name. |
| 76 |
|
| 77 |
:param image_name: the name of the photo in the event to return""" |
| 78 |
event = self.get_event(event_index_num) |
| 79 |
photos = event.select_many( |
| 80 |
'QQuickItem', |
| 81 |
objectName='eventPhoto' |
| 82 |
) |
| 83 |
for photo in photos: |
| 84 |
images = photo.select_many('QQuickImage') |
| 85 |
for image in images: |
| 86 |
src = image.source.split('?')[0] |
| 87 |
if str(src).endswith(image_name): |
| 88 |
return photo |
| 89 |
raise GalleryAppException( |
| 90 |
'Photo with image name {} could not be found'.format(image_name)) |
| 91 |
|
| 92 |
def click_photo(self, photo_name): |
| 93 |
"""Click photo with name and event |
| 94 |
|
| 95 |
:param photo_name: name of file to click |
| 96 |
""" |
| 97 |
photo = self._get_image_in_event_view(photo_name) |
| 98 |
self.pointing_device.click_object(photo) |
| 99 |
|
| 100 |
def select_photo(self, photo_name, event_index_num=0): |
| 101 |
"""Select photo with name and event |
| 102 |
|
| 103 |
:param photo_name: name of file to click |
| 104 |
:param event_index_num: index of event to click |
| 105 |
""" |
| 106 |
photo = self._get_item_in_event_view(photo_name, event_index_num) |
| 107 |
checkbox = photo.select_single(objectName="selectionCheckbox") |
| 108 |
self.pointing_device.click_object(checkbox) |