mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 08:24:53 +01:00
added 'is_mandatory' to instance
This commit is contained in:
parent
e86bf9c787
commit
b3d87eac82
1 changed files with 34 additions and 0 deletions
|
|
@ -507,6 +507,7 @@ class CreatedInstance:
|
||||||
if transient_data is None:
|
if transient_data is None:
|
||||||
transient_data = {}
|
transient_data = {}
|
||||||
self._transient_data = transient_data
|
self._transient_data = transient_data
|
||||||
|
self._is_mandatory = False
|
||||||
|
|
||||||
# Create a copy of passed data to avoid changing them on the fly
|
# Create a copy of passed data to avoid changing them on the fly
|
||||||
data = copy.deepcopy(data or {})
|
data = copy.deepcopy(data or {})
|
||||||
|
|
@ -605,6 +606,12 @@ class CreatedInstance:
|
||||||
if key in self._data and self._data[key] == value:
|
if key in self._data and self._data[key] == value:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if self.is_mandatory and key == "active" and value is not True:
|
||||||
|
raise ImmutableKeyError(
|
||||||
|
key,
|
||||||
|
"Instance is mandatory and can't be disabled."
|
||||||
|
)
|
||||||
|
|
||||||
self._data[key] = value
|
self._data[key] = value
|
||||||
self._create_context.instance_values_changed(
|
self._create_context.instance_values_changed(
|
||||||
self.id, {key: value}
|
self.id, {key: value}
|
||||||
|
|
@ -718,6 +725,33 @@ class CreatedInstance:
|
||||||
|
|
||||||
return self._transient_data
|
return self._transient_data
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_mandatory(self) -> bool:
|
||||||
|
"""Check if instance is mandatory.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
bool: True if instance is mandatory, False otherwise.
|
||||||
|
|
||||||
|
"""
|
||||||
|
return self._is_mandatory
|
||||||
|
|
||||||
|
def set_mandatory(self, value: bool) -> None:
|
||||||
|
"""Set instance as mandatory or not.
|
||||||
|
|
||||||
|
Mandatory instance can't be disabled in UI.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
value (bool): True if instance should be mandatory, False
|
||||||
|
otherwise.
|
||||||
|
|
||||||
|
"""
|
||||||
|
if value is self._is_mandatory:
|
||||||
|
return
|
||||||
|
self._is_mandatory = value
|
||||||
|
if value is True:
|
||||||
|
self["active"] = True
|
||||||
|
self._create_context.instance_state_changed(self.id)
|
||||||
|
|
||||||
def changes(self):
|
def changes(self):
|
||||||
"""Calculate and return changes."""
|
"""Calculate and return changes."""
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue