2023-10-25 12:38:48 +00:00
|
|
|
import logging
|
2023-11-17 09:36:59 +00:00
|
|
|
import time
|
2023-10-13 15:55:44 +00:00
|
|
|
import typing
|
|
|
|
|
|
|
|
import allure
|
|
|
|
|
2023-11-17 09:36:59 +00:00
|
|
|
import configs.timeouts
|
2023-10-13 15:55:44 +00:00
|
|
|
import driver
|
2024-10-15 15:31:37 +00:00
|
|
|
from constants import CommunityData
|
2023-10-13 15:55:44 +00:00
|
|
|
from driver import objects_access
|
|
|
|
from gui.elements.button import Button
|
|
|
|
from gui.elements.object import QObject
|
|
|
|
from gui.elements.text_label import TextLabel
|
2024-07-09 10:05:39 +00:00
|
|
|
from gui.objects_map import settings_names
|
2023-10-13 15:55:44 +00:00
|
|
|
from gui.screens.community_settings import CommunitySettingsScreen
|
|
|
|
|
2023-12-01 13:58:22 +00:00
|
|
|
LOG = logging.getLogger(__name__)
|
2023-10-25 12:38:48 +00:00
|
|
|
|
2023-10-13 15:55:44 +00:00
|
|
|
|
|
|
|
class CommunitiesSettingsView(QObject):
|
|
|
|
|
|
|
|
def __init__(self):
|
2024-07-09 10:05:39 +00:00
|
|
|
super().__init__(settings_names.mainWindow_CommunitiesView)
|
|
|
|
self._community_item = QObject(settings_names.settingsContentBaseScrollView_listItem_StatusListItem)
|
|
|
|
self._community_template_image = QObject(settings_names.settings_iconOrImage_StatusSmartIdenticon)
|
|
|
|
self._community_template_name_members = QObject(settings_names.settings_StatusTextWithLoadingState)
|
|
|
|
self._community_template_description = TextLabel(settings_names.settings_statusListItemSubTitle)
|
|
|
|
self._community_template_button = Button(settings_names.settings_StatusFlatButton)
|
2023-10-13 15:55:44 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
@allure.step('Get communities')
|
2024-10-15 15:31:37 +00:00
|
|
|
def communities(self) -> typing.List[CommunityData]:
|
2023-12-12 14:05:33 +00:00
|
|
|
time.sleep(0.5)
|
2023-10-13 15:55:44 +00:00
|
|
|
_communities = []
|
|
|
|
for obj in driver.findAllObjects(self._community_item.real_name):
|
|
|
|
container = driver.objectMap.realName(obj)
|
|
|
|
self._community_template_image.real_name['container'] = container
|
2023-12-08 07:20:15 +00:00
|
|
|
self._community_template_name_members.real_name['container'] = container
|
2023-10-13 15:55:44 +00:00
|
|
|
self._community_template_description.real_name['container'] = container
|
|
|
|
|
2023-10-25 12:38:48 +00:00
|
|
|
description = self._community_template_description.text
|
2023-12-08 07:20:15 +00:00
|
|
|
name_members_labels = []
|
|
|
|
for item in driver.findAllObjects(self._community_template_name_members.real_name):
|
|
|
|
name_members_labels.append(item)
|
|
|
|
sorted(name_members_labels, key=lambda item: item.y)
|
|
|
|
name = str(name_members_labels[0].text)
|
|
|
|
members = str(name_members_labels[1].text)
|
2023-10-25 12:38:48 +00:00
|
|
|
image = self._community_template_image.image
|
|
|
|
|
2024-10-15 15:31:37 +00:00
|
|
|
_communities.append(CommunityData(name, description, members, image))
|
2023-10-13 15:55:44 +00:00
|
|
|
return _communities
|
|
|
|
|
|
|
|
def _get_community_item(self, name: str):
|
|
|
|
for obj in driver.findAllObjects(self._community_item.real_name):
|
|
|
|
for item in objects_access.walk_children(obj):
|
|
|
|
if getattr(item, 'text', '') == name:
|
|
|
|
return obj
|
|
|
|
raise LookupError(f'Community item: {name} not found')
|
|
|
|
|
|
|
|
@allure.step('Open community info')
|
2023-11-17 09:36:59 +00:00
|
|
|
def get_community_info(
|
2024-10-15 15:31:37 +00:00
|
|
|
self, name: str, timeout_msec: int = configs.timeouts.UI_LOAD_TIMEOUT_MSEC) -> CommunityData:
|
2023-11-17 09:36:59 +00:00
|
|
|
started_at = time.monotonic()
|
|
|
|
while True:
|
|
|
|
communities = self.communities
|
|
|
|
for community in communities:
|
|
|
|
if community.name == name:
|
|
|
|
return community
|
|
|
|
if time.monotonic() - started_at > timeout_msec:
|
|
|
|
raise LookupError(f'Community item: {name} not found in {communities}')
|
2023-10-13 15:55:44 +00:00
|
|
|
|
|
|
|
@allure.step('Open community overview settings')
|
|
|
|
def open_community_overview_settings(self, name: str):
|
|
|
|
driver.mouseClick(self._get_community_item(name))
|
|
|
|
return CommunitySettingsScreen().wait_until_appears()
|