mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-26 05:42:15 +01:00
* initial commitof ayon loader * tweaks in ayon utils * implemented product type filtering * products have icons and proper style * fix refresh of products * added enable grouping checkbox * added icons and sorting of grouped items * fix version delegate * add splitter between context and product type filtering * fix products filtering by name * implemented 'filter_repre_contexts_by_loader' * implemented base of action items * implemented folder underline colors * changed version items to dictionary * use 'product_id' instead of 'subset_id' * base implementation of info widget * require less to trigger action * set selection of version ids in controller * added representation widget and related logic changes * implemented actions in representations widget * handle load error * use versions for subset loader * fix representations widget * implemente "in scene" logic properly * use ayon loader in host tools * fix used function to get tasks * show actions per representation name * center window * add window flag to loader window * added 'ThumbnailPainterWidget' to tool utils * implemented thumbnails model * implement thumbnail widget * fix FolderItem args docstring * bypass bug in ayon_api * fix sorting of folders * added refresh button * added expected selection and go to current context * added information if project item is library project * added more filtering options to projects widget * added missing information abou is library to model items * remove select project item on selection change * filter out non library projects * set current context project to project combobox * change window title * fix hero version queries * move current project to the top * fix reset * change icon for library projects * added libraries separator to project widget * show libraries separator in loader * ise single line expression * library loader tool is loader tool in AYON mode * fixes in grouping model * implemented grouping logic * use loader in tray action * better initial sizes * moved 'ActionItem' to abstract * filter loaders by tool name based on current context project * formatting fixes * separate abstract classes into frontend and backend abstractions * added docstrings to abstractions * implemented 'to_data' and 'from_data' for action item options * added more docstrings * first filter representation contexts and then create action items * implemented 'refresh' method * do not reset controller in '_on_first_show' Method '_on_show_timer' will take about the reset. * 'ThumbnailPainterWidget' have more options of bg painting * do not use checkerboard in loader thumbnail * fix condition Co-authored-by: Roy Nieterau <roy_nieterau@hotmail.com> --------- Co-authored-by: Roy Nieterau <roy_nieterau@hotmail.com>
118 lines
4 KiB
Python
118 lines
4 KiB
Python
import collections
|
|
|
|
import ayon_api
|
|
|
|
from openpype.client.server.thumbnails import AYONThumbnailCache
|
|
|
|
from .cache import NestedCacheItem
|
|
|
|
|
|
class ThumbnailsModel:
|
|
entity_cache_lifetime = 240 # In seconds
|
|
|
|
def __init__(self):
|
|
self._thumbnail_cache = AYONThumbnailCache()
|
|
self._paths_cache = collections.defaultdict(dict)
|
|
self._folders_cache = NestedCacheItem(
|
|
levels=2, lifetime=self.entity_cache_lifetime)
|
|
self._versions_cache = NestedCacheItem(
|
|
levels=2, lifetime=self.entity_cache_lifetime)
|
|
|
|
def reset(self):
|
|
self._paths_cache = collections.defaultdict(dict)
|
|
self._folders_cache.reset()
|
|
self._versions_cache.reset()
|
|
|
|
def get_thumbnail_path(self, project_name, thumbnail_id):
|
|
return self._get_thumbnail_path(project_name, thumbnail_id)
|
|
|
|
def get_folder_thumbnail_ids(self, project_name, folder_ids):
|
|
project_cache = self._folders_cache[project_name]
|
|
output = {}
|
|
missing_cache = set()
|
|
for folder_id in folder_ids:
|
|
cache = project_cache[folder_id]
|
|
if cache.is_valid:
|
|
output[folder_id] = cache.get_data()
|
|
else:
|
|
missing_cache.add(folder_id)
|
|
self._query_folder_thumbnail_ids(project_name, missing_cache)
|
|
for folder_id in missing_cache:
|
|
cache = project_cache[folder_id]
|
|
output[folder_id] = cache.get_data()
|
|
return output
|
|
|
|
def get_version_thumbnail_ids(self, project_name, version_ids):
|
|
project_cache = self._versions_cache[project_name]
|
|
output = {}
|
|
missing_cache = set()
|
|
for version_id in version_ids:
|
|
cache = project_cache[version_id]
|
|
if cache.is_valid:
|
|
output[version_id] = cache.get_data()
|
|
else:
|
|
missing_cache.add(version_id)
|
|
self._query_version_thumbnail_ids(project_name, missing_cache)
|
|
for version_id in missing_cache:
|
|
cache = project_cache[version_id]
|
|
output[version_id] = cache.get_data()
|
|
return output
|
|
|
|
def _get_thumbnail_path(self, project_name, thumbnail_id):
|
|
if not thumbnail_id:
|
|
return None
|
|
|
|
project_cache = self._paths_cache[project_name]
|
|
if thumbnail_id in project_cache:
|
|
return project_cache[thumbnail_id]
|
|
|
|
filepath = self._thumbnail_cache.get_thumbnail_filepath(
|
|
project_name, thumbnail_id
|
|
)
|
|
if filepath is not None:
|
|
project_cache[thumbnail_id] = filepath
|
|
return filepath
|
|
|
|
# 'ayon_api' had a bug, public function
|
|
# 'get_thumbnail_by_id' did not return output of
|
|
# 'ServerAPI' method.
|
|
con = ayon_api.get_server_api_connection()
|
|
result = con.get_thumbnail_by_id(project_name, thumbnail_id)
|
|
if result is None:
|
|
pass
|
|
|
|
elif result.is_valid:
|
|
filepath = self._thumbnail_cache.store_thumbnail(
|
|
project_name,
|
|
thumbnail_id,
|
|
result.content,
|
|
result.content_type
|
|
)
|
|
project_cache[thumbnail_id] = filepath
|
|
return filepath
|
|
|
|
def _query_folder_thumbnail_ids(self, project_name, folder_ids):
|
|
if not project_name or not folder_ids:
|
|
return
|
|
|
|
folders = ayon_api.get_folders(
|
|
project_name,
|
|
folder_ids=folder_ids,
|
|
fields=["id", "thumbnailId"]
|
|
)
|
|
project_cache = self._folders_cache[project_name]
|
|
for folder in folders:
|
|
project_cache[folder["id"]] = folder["thumbnailId"]
|
|
|
|
def _query_version_thumbnail_ids(self, project_name, version_ids):
|
|
if not project_name or not version_ids:
|
|
return
|
|
|
|
versions = ayon_api.get_versions(
|
|
project_name,
|
|
version_ids=version_ids,
|
|
fields=["id", "thumbnailId"]
|
|
)
|
|
project_cache = self._versions_cache[project_name]
|
|
for version in versions:
|
|
project_cache[version["id"]] = version["thumbnailId"]
|