mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
define context change reason enum
This commit is contained in:
parent
ab363bf77e
commit
1e7c9db988
4 changed files with 26 additions and 9 deletions
|
|
@ -1,3 +1,4 @@
|
|||
from .constants import ContextChangeReason
|
||||
from .host import (
|
||||
HostBase,
|
||||
)
|
||||
|
|
@ -15,6 +16,8 @@ from .dirmap import HostDirmap
|
|||
|
||||
|
||||
__all__ = (
|
||||
"ContextChangeReason",
|
||||
|
||||
"HostBase",
|
||||
|
||||
"IWorkfileHost",
|
||||
|
|
|
|||
15
client/ayon_core/host/constants.py
Normal file
15
client/ayon_core/host/constants.py
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
from enum import Enum
|
||||
|
||||
|
||||
class StrEnum(str, Enum):
|
||||
"""A string-based Enum class that allows for string comparison."""
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.value
|
||||
|
||||
|
||||
class ContextChangeReason(StrEnum):
|
||||
"""Reasons for context change in the host."""
|
||||
undefined = "undefined"
|
||||
workfile_open = "workfile.opened"
|
||||
workfile_save = "workfile.saved"
|
||||
|
|
@ -12,6 +12,8 @@ import ayon_api
|
|||
|
||||
from ayon_core.lib import emit_event
|
||||
|
||||
from .constants import ContextChangeReason
|
||||
|
||||
if typing.TYPE_CHECKING:
|
||||
from ayon_core.pipeline import Anatomy
|
||||
|
||||
|
|
@ -28,7 +30,7 @@ class ContextChangeData:
|
|||
project_entity: dict[str, Any]
|
||||
folder_entity: dict[str, Any]
|
||||
task_entity: dict[str, Any]
|
||||
reason: Optional[str]
|
||||
reason: ContextChangeReason
|
||||
anatomy: Anatomy
|
||||
|
||||
|
||||
|
|
@ -172,7 +174,7 @@ class HostBase(ABC):
|
|||
folder_entity: dict[str, Any],
|
||||
task_entity: dict[str, Any],
|
||||
*,
|
||||
reason: Optional[str] = None,
|
||||
reason: ContextChangeReason = ContextChangeReason.undefined,
|
||||
project_entity: Optional[dict[str, Any]] = None,
|
||||
anatomy: Optional[Anatomy] = None,
|
||||
) -> "HostContextData":
|
||||
|
|
@ -190,7 +192,7 @@ class HostBase(ABC):
|
|||
Args:
|
||||
folder_entity (Optional[dict[str, Any]]): Folder entity.
|
||||
task_entity (Optional[dict[str, Any]]): Task entity.
|
||||
reason (Optional[str]): Reason for context change.
|
||||
reason (ContextChangeReason): Reason for context change.
|
||||
project_entity (Optional[dict[str, Any]]): Project entity data.
|
||||
anatomy (Optional[Anatomy]): Anatomy instance for the project.
|
||||
|
||||
|
|
|
|||
|
|
@ -14,15 +14,12 @@ import ayon_api
|
|||
import arrow
|
||||
|
||||
from ayon_core.lib import emit_event
|
||||
from ayon_core.host.constants import ContextChangeReason
|
||||
|
||||
if typing.TYPE_CHECKING:
|
||||
from ayon_core.pipeline import Anatomy
|
||||
|
||||
|
||||
WORKFILE_OPEN_REASON = "workfile.opened"
|
||||
WORKFILE_SAVE_REASON = "workfile.saved"
|
||||
|
||||
|
||||
def deprecated(reason):
|
||||
def decorator(func):
|
||||
message = f"Call to deprecated function {func.__name__} ({reason})."
|
||||
|
|
@ -388,9 +385,9 @@ class IWorkfileHost:
|
|||
self.set_current_context(
|
||||
folder_entity,
|
||||
task_entity,
|
||||
reason=WORKFILE_SAVE_REASON,
|
||||
project_entity=project_entity,
|
||||
anatomy=anatomy,
|
||||
reason=ContextChangeReason.workfile_save,
|
||||
)
|
||||
|
||||
self.save_workfile(filepath)
|
||||
|
|
@ -458,9 +455,9 @@ class IWorkfileHost:
|
|||
self.set_current_context(
|
||||
folder_entity,
|
||||
task_entity,
|
||||
reason=WORKFILE_OPEN_REASON,
|
||||
project_entity=project_entity,
|
||||
anatomy=anatomy,
|
||||
reason=ContextChangeReason.workfile_open,
|
||||
)
|
||||
|
||||
self.open_workfile(filepath)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue