Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Settings actions process fix #1457

Merged
merged 4 commits into from
May 4, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
103 changes: 62 additions & 41 deletions openpype/settings/entities/base_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,25 +457,16 @@ def value(self):
pass

@property
def can_discard_changes(self):
"""Result defines if `discard_changes` will be processed.

Also can be used as validation before the method is called.
"""
def _can_discard_changes(self):
"""Defines if `discard_changes` will be processed."""
return self.has_unsaved_changes

@property
def can_add_to_studio_default(self):
"""Result defines if `add_to_studio_default` will be processed.

Also can be used as validation before the method is called.
"""
def _can_add_to_studio_default(self):
"""Defines if `add_to_studio_default` will be processed."""
if self._override_state is not OverrideState.STUDIO:
return False

if self.is_dynamic_item or self.is_in_dynamic_item:
return False

# Skip if entity is under group
if self.group_item:
return False
Expand All @@ -487,30 +478,18 @@ def can_add_to_studio_default(self):
return True

@property
def can_remove_from_studio_default(self):
"""Result defines if `remove_from_studio_default` can be triggered.

This can be also used as validation before the method is called.
"""
def _can_remove_from_studio_default(self):
"""Defines if `remove_from_studio_default` can be processed."""
if self._override_state is not OverrideState.STUDIO:
return False

if self.is_dynamic_item or self.is_in_dynamic_item:
return False

if not self.has_studio_override:
return False
return True

@property
def can_add_to_project_override(self):
"""Result defines if `add_to_project_override` can be triggered.

Also can be used as validation before the method is called.
"""
if self.is_dynamic_item or self.is_in_dynamic_item:
return False

def _can_add_to_project_override(self):
"""Defines if `add_to_project_override` can be processed."""
# Show only when project overrides are set
if self._override_state is not OverrideState.PROJECT:
return False
Expand All @@ -525,24 +504,66 @@ def can_add_to_project_override(self):
return True

@property
def can_remove_from_project_override(self):
"""Result defines if `remove_from_project_override` can be triggered.
def _can_remove_from_project_override(self):
"""Defines if `remove_from_project_override` can be processed."""
if self._override_state is not OverrideState.PROJECT:
return False

# Dynamic items can't have these actions
if self.is_dynamic_item or self.is_in_dynamic_item:
return False

if not self.has_project_override:
return False
return True

@property
def can_trigger_discard_changes(self):
"""Defines if can trigger `discard_changes`.

Also can be used as validation before the method is called.
"""
return self._can_discard_changes

@property
def can_trigger_add_to_studio_default(self):
"""Defines if can trigger `add_to_studio_default`.

This can be also used as validation before the method is called.
Also can be used as validation before the method is called.
"""
if self.is_dynamic_item or self.is_in_dynamic_item:
return False
return self._can_add_to_studio_default

if self._override_state is not OverrideState.PROJECT:
@property
def can_trigger_remove_from_studio_default(self):
"""Defines if can trigger `remove_from_studio_default`.

Also can be used as validation before the method is called.
"""
if self.is_dynamic_item or self.is_in_dynamic_item:
return False
return self._can_remove_from_studio_default

# Dynamic items can't have these actions
@property
def can_trigger_add_to_project_override(self):
"""Defines if can trigger `add_to_project_override`.

Also can be used as validation before the method is called.
"""
if self.is_dynamic_item or self.is_in_dynamic_item:
return False
return self._can_add_to_project_override

if not self.has_project_override:
@property
def can_trigger_remove_from_project_override(self):
"""Defines if can trigger `remove_from_project_override`.

Also can be used as validation before the method is called.
"""
if self.is_dynamic_item or self.is_in_dynamic_item:
return False
return True
return self._can_remove_from_project_override

def discard_changes(self, on_change_trigger=None):
"""Discard changes on entity and it's children.
Expand All @@ -568,7 +589,7 @@ def discard_changes(self, on_change_trigger=None):
"""
initialized = False
if on_change_trigger is None:
if not self.can_discard_changes:
if not self.can_trigger_discard_changes:
return

initialized = True
Expand All @@ -588,7 +609,7 @@ def _discard_changes(self, on_change_trigger):
def add_to_studio_default(self, on_change_trigger=None):
initialized = False
if on_change_trigger is None:
if not self.can_add_to_studio_default:
if not self.can_trigger_add_to_studio_default:
return

initialized = True
Expand Down Expand Up @@ -625,7 +646,7 @@ def remove_from_studio_default(self, on_change_trigger=None):
"""
initialized = False
if on_change_trigger is None:
if not self.can_remove_from_studio_default:
if not self.can_trigger_remove_from_studio_default:
return

initialized = True
Expand All @@ -649,7 +670,7 @@ def _remove_from_studio_default(self, on_change_trigger):
def add_to_project_override(self, on_change_trigger=None):
initialized = False
if on_change_trigger is None:
if not self.can_add_to_project_override:
if not self.can_trigger_add_to_project_override:
return

initialized = True
Expand Down Expand Up @@ -689,7 +710,7 @@ def remove_from_project_override(self, on_change_trigger=None):

initialized = False
if on_change_trigger is None:
if not self.can_remove_from_project_override:
if not self.can_trigger_remove_from_project_override:
return
initialized = True
on_change_trigger = []
Expand Down
6 changes: 3 additions & 3 deletions openpype/settings/entities/dict_mutable_keys_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ def update_project_value(self, value):
self.had_project_override = value is not NOT_SET

def _discard_changes(self, on_change_trigger):
if not self.can_discard_changes:
if not self._can_discard_changes:
return

self.set_override_state(self._override_state)
Expand All @@ -533,7 +533,7 @@ def _add_to_studio_default(self, _on_change_trigger):
self.on_change()

def _remove_from_studio_default(self, on_change_trigger):
if not self.can_remove_from_studio_default:
if not self._can_remove_from_studio_default:
return

value = self._default_value
Expand Down Expand Up @@ -574,7 +574,7 @@ def _add_to_project_override(self, _on_change_trigger):
self.on_change()

def _remove_from_project_override(self, on_change_trigger):
if not self.can_remove_from_project_override:
if not self._can_remove_from_project_override:
return

if self._has_studio_override:
Expand Down
6 changes: 3 additions & 3 deletions openpype/settings/entities/input_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def set_override_state(self, state):
self._current_value = copy.deepcopy(value)

def _discard_changes(self, on_change_trigger=None):
if not self.can_discard_changes:
if not self._can_discard_changes:
return

self._value_is_modified = False
Expand Down Expand Up @@ -289,7 +289,7 @@ def _add_to_studio_default(self, _on_change_trigger):
self.on_change()

def _remove_from_studio_default(self, on_change_trigger):
if not self.can_remove_from_studio_default:
if not self._can_remove_from_studio_default:
return

value = self._default_value
Expand All @@ -307,7 +307,7 @@ def _add_to_project_override(self, _on_change_trigger):
self.on_change()

def _remove_from_project_override(self, on_change_trigger):
if not self.can_remove_from_project_override:
if not self._can_remove_from_project_override:
return

self._has_project_override = False
Expand Down
3 changes: 2 additions & 1 deletion openpype/settings/entities/item_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,5 @@ def update_project_value(self, value):

def reset_callbacks(self):
super(ListStrictEntity, self).reset_callbacks()
self.child_obj.reset_callbacks()
for child_obj in self.children:
child_obj.reset_callbacks()
6 changes: 3 additions & 3 deletions openpype/settings/entities/list_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def _settings_value(self):
return output

def _discard_changes(self, on_change_trigger):
if not self.can_discard_changes:
if not self._can_discard_changes:
return

not_set = object()
Expand Down Expand Up @@ -405,7 +405,7 @@ def _add_to_studio_default(self, _on_change_trigger):
self.on_change()

def _remove_from_studio_default(self, on_change_trigger):
if not self.can_remove_from_studio_default:
if not self._can_remove_from_studio_default:
return

value = self._default_value
Expand Down Expand Up @@ -433,7 +433,7 @@ def _add_to_project_override(self, _on_change_trigger):
self.on_change()

def _remove_from_project_override(self, on_change_trigger):
if not self.can_remove_from_project_override:
if not self._can_remove_from_project_override:
return

if self._has_studio_override:
Expand Down
10 changes: 5 additions & 5 deletions openpype/tools/settings/settings/widgets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def _on_entity_change(self):
def _discard_changes_action(self, menu, actions_mapping):
# TODO use better condition as unsaved changes may be caused due to
# changes in schema.
if not self.entity.can_discard_changes:
if not self.entity.can_trigger_discard_changes:
return

def discard_changes():
Expand All @@ -86,15 +86,15 @@ def discard_changes():
def _add_to_studio_default(self, menu, actions_mapping):
"""Set values as studio overrides."""
# Skip if not in studio overrides
if not self.entity.can_add_to_studio_default:
if not self.entity.can_trigger_add_to_studio_default:
return

action = QtWidgets.QAction("Add to studio default")
actions_mapping[action] = self.entity.add_to_studio_default
menu.addAction(action)

def _remove_from_studio_default_action(self, menu, actions_mapping):
if not self.entity.can_remove_from_studio_default:
if not self.entity.can_trigger_remove_from_studio_default:
return

def remove_from_studio_default():
Expand All @@ -106,15 +106,15 @@ def remove_from_studio_default():
menu.addAction(action)

def _add_to_project_override_action(self, menu, actions_mapping):
if not self.entity.can_add_to_project_override:
if not self.entity.can_trigger_add_to_project_override:
return

action = QtWidgets.QAction("Add to project project override")
actions_mapping[action] = self.entity.add_to_project_override
menu.addAction(action)

def _remove_from_project_override_action(self, menu, actions_mapping):
if not self.entity.can_remove_from_project_override:
if not self.entity.can_trigger_remove_from_project_override:
return

def remove_from_project_override():
Expand Down