Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: loader support product type filter profiles #792

Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions client/ayon_core/tools/loader/abstract.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from abc import ABC, abstractmethod
from typing import List

from ayon_core.lib.attribute_definitions import (
AbstractAttrDef,
Expand Down Expand Up @@ -346,6 +347,16 @@ def from_data(cls, data):
return cls(**data)


class ProductTypesFilter:
"""Product types filter.

Defines the filtering for product types.
"""
def __init__(self, product_types: List[str], is_include: bool):
self.product_types: List[str] = product_types
self.is_include: bool = is_include


class _BaseLoaderController(ABC):
"""Base loader controller abstraction.

Expand Down Expand Up @@ -1006,3 +1017,16 @@ def get_representations_sync_status(
"""

pass

@abstractmethod
def get_product_types_filter(self, project_name):
"""Return product type filter for project name (and current context).
BigRoy marked this conversation as resolved.
Show resolved Hide resolved

Args:
project_name (str): Project name.

Returns:
ProductTypesFilter: Product type filter for current context
"""

pass
52 changes: 50 additions & 2 deletions client/ayon_core/tools/loader/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

import ayon_api

from ayon_core.lib import NestedCacheItem, CacheItem
from ayon_core.settings import get_current_project_settings
from ayon_core.pipeline import get_current_host_name
from ayon_core.pipeline.context_tools import get_current_task_entity
from ayon_core.lib import NestedCacheItem, CacheItem, filter_profiles
from ayon_core.lib.events import QueuedEventSystem
from ayon_core.pipeline import Anatomy, get_current_context
from ayon_core.host import ILoadHost
Expand All @@ -13,7 +16,11 @@
ThumbnailsModel,
)

from .abstract import BackendLoaderController, FrontendLoaderController
from .abstract import (
BackendLoaderController,
FrontendLoaderController,
ProductTypesFilter
)
from .models import (
SelectionModel,
ProductsModel,
Expand Down Expand Up @@ -425,3 +432,44 @@ def _create_event_system(self):

def _emit_event(self, topic, data=None):
self._event_system.emit(topic, data or {}, "controller")

def get_product_types_filter(self, project_name):
output = ProductTypesFilter(
is_include=False,
product_types=[]
)
# Without host is not determined context
if self._host is None:
return output

context = self.get_current_context()
if (
not all(context.values())
or context["project_name"] != project_name
):
return output
settings = get_current_project_settings()
profiles = (
settings
["core"]
["tools"]
["loader"]
["product_type_filter_profiles"]
)
if not profiles:
return output
task_entity = get_current_task_entity(fields={"taskType"})
host_name = getattr(self._host, "name", get_current_host_name())
profile = filter_profiles(
profiles,
{
"hosts": host_name,
"task_types": (task_entity or {}).get("taskType")
}
)
if profile:
output = ProductTypesFilter(
is_include=profile["is_include"],
product_types=profile["filter_product_types"]
)
return output
25 changes: 25 additions & 0 deletions client/ayon_core/tools/loader/ui/product_types_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,21 @@ def refresh(self, project_name):
self._refreshing = False
self.refreshed.emit()

def reset_product_types_filter(self):

BigRoy marked this conversation as resolved.
Show resolved Hide resolved
project_name = self._controller.get_selected_project_name()
product_types_filter = (
self._controller.get_product_types_filter(project_name)
)
if product_types_filter.is_include:
self.change_state_for_all(False)
else:
self.change_state_for_all(True)
self.change_states(
product_types_filter.is_include,
product_types_filter.product_types
)

def setData(self, index, value, role=None):
checkstate_changed = False
if role is None:
Expand Down Expand Up @@ -151,6 +166,7 @@ def __init__(self, controller, parent):
)

self._controller = controller
self._refresh_product_types_filter = False

self._product_types_model = product_types_model
self._product_types_proxy_model = product_types_proxy_model
Expand All @@ -162,7 +178,16 @@ def _on_project_change(self, event):
project_name = event["project_name"]
self._product_types_model.refresh(project_name)

def showEvent(self, event):
self._refresh_product_types_filter = True
super().showEvent(event)

def _on_refresh_finished(self):

BigRoy marked this conversation as resolved.
Show resolved Hide resolved
# Apply product types filter on first show
if self._refresh_product_types_filter:
BigRoy marked this conversation as resolved.
Show resolved Hide resolved
self._product_types_model.reset_product_types_filter()

self.filter_changed.emit()

def _on_filter_change(self):
Expand Down
11 changes: 2 additions & 9 deletions server/settings/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ def _product_types_enum():
"editorial",
"gizmo",
"image",
"imagesequence",
"layout",
"look",
"matchmove",
Expand All @@ -212,7 +213,6 @@ def _product_types_enum():
"setdress",
"take",
"usd",
"usdShade",
"vdbcache",
"vrayproxy",
"workfile",
Expand Down Expand Up @@ -499,14 +499,7 @@ class GlobalToolsModel(BaseSettingsModel):
"workfile_lock_profiles": []
},
"loader": {
"product_type_filter_profiles": [
{
"hosts": [],
"task_types": [],
"is_include": True,
"filter_product_types": []
}
]
"product_type_filter_profiles": []
},
"publish": {
"template_name_profiles": [
Expand Down
Loading