Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Add both side availability on Site Sync sites to Loader #2220

37 changes: 30 additions & 7 deletions openpype/modules/default_modules/sync_server/tray/delegates.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@
from openpype.lib import PypeLogger
from . import lib

from openpype.tools.utils.constants import (
LOCAL_PROVIDER_ROLE,
REMOTE_PROVIDER_ROLE,
LOCAL_PROGRESS_ROLE,
REMOTE_PROGRESS_ROLE,
LOCAL_DATE_ROLE,
REMOTE_DATE_ROLE,
LOCAL_FAILED_ROLE,
REMOTE_FAILED_ROLE,
EDIT_ICON_ROLE
)

log = PypeLogger().get_logger("SyncServer")


Expand All @@ -14,7 +26,7 @@ def paint(self, painter, option, index):

if option.widget.selectionModel().isSelected(index) or \
option.state & QtWidgets.QStyle.State_MouseOver:
edit_icon = index.data(lib.EditIconRole)
edit_icon = index.data(EDIT_ICON_ROLE)
if not edit_icon:
return

Expand All @@ -38,7 +50,7 @@ def createEditor(self, parent, option, index):
editor = PriorityLineEdit(
parent,
option.widget.selectionModel().selectedRows())
editor.setFocus(True)
editor.setFocus()
return editor

def setModelData(self, editor, model, index):
Expand Down Expand Up @@ -71,19 +83,30 @@ class ImageDelegate(QtWidgets.QStyledItemDelegate):
Prints icon of site and progress of synchronization
"""

def __init__(self, parent=None):
def __init__(self, parent=None, side=None):
super(ImageDelegate, self).__init__(parent)
self.icons = {}
self.side = side

def paint(self, painter, option, index):
super(ImageDelegate, self).paint(painter, option, index)
option = QtWidgets.QStyleOptionViewItem(option)
option.showDecorationSelected = True

provider = index.data(lib.ProviderRole)
value = index.data(lib.ProgressRole)
date_value = index.data(lib.DateRole)
is_failed = index.data(lib.FailedRole)
if not self.side:
log.warning("No side provided, delegate won't work")
return

if self.side == 'local':
provider = index.data(LOCAL_PROVIDER_ROLE)
value = index.data(LOCAL_PROGRESS_ROLE)
date_value = index.data(LOCAL_DATE_ROLE)
is_failed = index.data(LOCAL_FAILED_ROLE)
else:
provider = index.data(REMOTE_PROVIDER_ROLE)
value = index.data(REMOTE_PROGRESS_ROLE)
date_value = index.data(REMOTE_DATE_ROLE)
is_failed = index.data(REMOTE_FAILED_ROLE)

if not self.icons.get(provider):
resource_path = os.path.dirname(__file__)
Expand Down
15 changes: 3 additions & 12 deletions openpype/modules/default_modules/sync_server/tray/lib.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from Qt import QtCore
import attr
import abc
import six
Expand All @@ -19,14 +18,6 @@

DUMMY_PROJECT = "No project configured"

ProviderRole = QtCore.Qt.UserRole + 2
ProgressRole = QtCore.Qt.UserRole + 4
DateRole = QtCore.Qt.UserRole + 6
FailedRole = QtCore.Qt.UserRole + 8
HeaderNameRole = QtCore.Qt.UserRole + 10
FullItemRole = QtCore.Qt.UserRole + 12
EditIconRole = QtCore.Qt.UserRole + 14


@six.add_metaclass(abc.ABCMeta)
class AbstractColumnFilter:
Expand Down Expand Up @@ -161,7 +152,7 @@ def translate_provider_for_icon(sync_server, project, site):
return sync_server.get_provider_for_site(site=site)


def get_item_by_id(model, object_id):
def get_value_from_id_by_role(model, object_id, role):
"""Return value from item with 'object_id' with 'role'."""
index = model.get_index(object_id)
item = model.data(index, FullItemRole)
return item
return model.data(index, role)
175 changes: 76 additions & 99 deletions openpype/modules/default_modules/sync_server/tray/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,23 @@

from . import lib

from openpype.tools.utils.constants import (
LOCAL_PROVIDER_ROLE,
REMOTE_PROVIDER_ROLE,
LOCAL_PROGRESS_ROLE,
REMOTE_PROGRESS_ROLE,
HEADER_NAME_ROLE,
EDIT_ICON_ROLE,
LOCAL_DATE_ROLE,
REMOTE_DATE_ROLE,
LOCAL_FAILED_ROLE,
REMOTE_FAILED_ROLE,
STATUS_ROLE,
PATH_ROLE,
ERROR_ROLE,
TRIES_ROLE
)


log = PypeLogger().get_logger("SyncServer")

Expand Down Expand Up @@ -68,10 +85,68 @@ def headerData(self, section, orientation, role=Qt.DisplayRole):
if orientation == Qt.Horizontal:
return self.COLUMN_LABELS[section][1]

if role == lib.HeaderNameRole:
if role == HEADER_NAME_ROLE:
if orientation == Qt.Horizontal:
return self.COLUMN_LABELS[section][0] # return name

def data(self, index, role):
item = self._data[index.row()]

header_value = self._header[index.column()]
if role == LOCAL_PROVIDER_ROLE:
return item.local_provider

if role == REMOTE_PROVIDER_ROLE:
return item.remote_provider

if role == LOCAL_PROGRESS_ROLE:
return item.local_progress

if role == REMOTE_PROGRESS_ROLE:
return item.remote_progress

if role == LOCAL_DATE_ROLE:
if item.created_dt:
return pretty_timestamp(item.created_dt)

if role == REMOTE_DATE_ROLE:
if item.sync_dt:
return pretty_timestamp(item.sync_dt)

if role == LOCAL_FAILED_ROLE:
return item.status == lib.STATUS[2] and \
item.local_progress < 1

if role == REMOTE_FAILED_ROLE:
return item.status == lib.STATUS[2] and \
item.remote_progress < 1

if role in (Qt.DisplayRole, Qt.EditRole):
# because of ImageDelegate
if header_value in ['remote_site', 'local_site']:
return ""

return attr.asdict(item)[self._header[index.column()]]

if role == EDIT_ICON_ROLE:
if self.can_edit and header_value in self.EDITABLE_COLUMNS:
return self.edit_icon

if role == PATH_ROLE:
return item.path

if role == ERROR_ROLE:
return item.error

if role == TRIES_ROLE:
return item.tries

if role == STATUS_ROLE:
return item.status

if role == Qt.UserRole:
return item._id

@property
def can_edit(self):
"""Returns true if some site is user local site, eg. could edit"""
Expand Down Expand Up @@ -456,55 +531,6 @@ def __init__(self, sync_server, header, project=None, parent=None):
self.timer.timeout.connect(self.tick)
self.timer.start(self.REFRESH_SEC)

def data(self, index, role):
item = self._data[index.row()]

if role == lib.FullItemRole:
return item

header_value = self._header[index.column()]
if role == lib.ProviderRole:
if header_value == 'local_site':
return item.local_provider
if header_value == 'remote_site':
return item.remote_provider

if role == lib.ProgressRole:
if header_value == 'local_site':
return item.local_progress
if header_value == 'remote_site':
return item.remote_progress

if role == lib.DateRole:
if header_value == 'local_site':
if item.created_dt:
return pretty_timestamp(item.created_dt)
if header_value == 'remote_site':
if item.sync_dt:
return pretty_timestamp(item.sync_dt)

if role == lib.FailedRole:
if header_value == 'local_site':
return item.status == lib.STATUS[2] and \
item.local_progress < 1
if header_value == 'remote_site':
return item.status == lib.STATUS[2] and \
item.remote_progress < 1

if role in (Qt.DisplayRole, Qt.EditRole):
# because of ImageDelegate
if header_value in ['remote_site', 'local_site']:
return ""

return attr.asdict(item)[self._header[index.column()]]

if role == lib.EditIconRole:
if self.can_edit and header_value in self.EDITABLE_COLUMNS:
return self.edit_icon

if role == Qt.UserRole:
return item._id

def add_page_records(self, local_site, remote_site, representations):
"""
Process all records from 'representation' and add them to storage.
Expand Down Expand Up @@ -985,55 +1011,6 @@ def __init__(self, sync_server, header, _id,
self.timer.timeout.connect(self.tick)
self.timer.start(SyncRepresentationSummaryModel.REFRESH_SEC)

def data(self, index, role):
item = self._data[index.row()]

if role == lib.FullItemRole:
return item

header_value = self._header[index.column()]
if role == lib.ProviderRole:
if header_value == 'local_site':
return item.local_provider
if header_value == 'remote_site':
return item.remote_provider

if role == lib.ProgressRole:
if header_value == 'local_site':
return item.local_progress
if header_value == 'remote_site':
return item.remote_progress

if role == lib.DateRole:
if header_value == 'local_site':
if item.created_dt:
return pretty_timestamp(item.created_dt)
if header_value == 'remote_site':
if item.sync_dt:
return pretty_timestamp(item.sync_dt)

if role == lib.FailedRole:
if header_value == 'local_site':
return item.status == lib.STATUS[2] and \
item.local_progress < 1
if header_value == 'remote_site':
return item.status == lib.STATUS[2] and \
item.remote_progress < 1

if role in (Qt.DisplayRole, Qt.EditRole):
# because of ImageDelegate
if header_value in ['remote_site', 'local_site']:
return ""

return attr.asdict(item)[self._header[index.column()]]

if role == lib.EditIconRole:
if self.can_edit and header_value in self.EDITABLE_COLUMNS:
return self.edit_icon

if role == Qt.UserRole:
return item._id

def add_page_records(self, local_site, remote_site, representations):
"""
Process all records from 'representation' and add them to storage.
Expand Down
Loading