mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 12:54:40 +01:00
added host to the context
This commit is contained in:
parent
d0cb16a155
commit
8da213c566
1 changed files with 22 additions and 1 deletions
|
|
@ -11,12 +11,14 @@ from dataclasses import dataclass
|
|||
import ayon_api
|
||||
|
||||
from ayon_core import AYON_CORE_ROOT
|
||||
from ayon_core.host import AbstractHost
|
||||
from ayon_core.lib import StrEnum, Logger, AbstractAttrDef
|
||||
from ayon_core.addon import AddonsManager, IPluginPaths
|
||||
from ayon_core.settings import get_studio_settings, get_project_settings
|
||||
from ayon_core.pipeline import Anatomy
|
||||
from ayon_core.pipeline import Anatomy, registered_host
|
||||
from ayon_core.pipeline.plugin_discover import discover_plugins
|
||||
|
||||
_PLACEHOLDER = object()
|
||||
|
||||
class EntityType(StrEnum):
|
||||
"""Selected entity type."""
|
||||
|
|
@ -411,6 +413,11 @@ class LoaderActionPlugin(ABC):
|
|||
"""
|
||||
return self.__class__.__name__
|
||||
|
||||
@property
|
||||
def host_name(self) -> Optional[str]:
|
||||
"""Name of the current host."""
|
||||
return self._context.get_host_name()
|
||||
|
||||
@abstractmethod
|
||||
def get_action_items(
|
||||
self, selection: LoaderActionSelection
|
||||
|
|
@ -457,11 +464,14 @@ class LoaderActionsContext:
|
|||
self,
|
||||
studio_settings: Optional[dict[str, Any]] = None,
|
||||
addons_manager: Optional[AddonsManager] = None,
|
||||
host: Optional[AbstractHost] = _PLACEHOLDER,
|
||||
) -> None:
|
||||
self._log = Logger.get_logger(self.__class__.__name__)
|
||||
|
||||
self._addons_manager = addons_manager
|
||||
self._host = host
|
||||
|
||||
# Attributes that are re-cached on reset
|
||||
self._studio_settings = studio_settings
|
||||
self._plugins = None
|
||||
|
||||
|
|
@ -478,6 +488,17 @@ class LoaderActionsContext:
|
|||
)
|
||||
return self._addons_manager
|
||||
|
||||
def get_host(self) -> Optional[AbstractHost]:
|
||||
if self._host is _PLACEHOLDER:
|
||||
self._host = registered_host()
|
||||
return self._host
|
||||
|
||||
def get_host_name(self) -> Optional[str]:
|
||||
host = self.get_host()
|
||||
if host is None:
|
||||
return None
|
||||
return host.name
|
||||
|
||||
def get_studio_settings(self) -> dict[str, Any]:
|
||||
if self._studio_settings is None:
|
||||
self._studio_settings = get_studio_settings()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue