mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-26 05:42:15 +01:00
removed DictInvisible
This commit is contained in:
parent
0ea6c30c6d
commit
f4e442cb33
1 changed files with 1 additions and 294 deletions
|
|
@ -2835,299 +2835,6 @@ class DictWidget(QtWidgets.QWidget, SettingObject):
|
|||
return self._override_values(True)
|
||||
|
||||
|
||||
class DictInvisible(QtWidgets.QWidget, SettingObject):
|
||||
# TODO is not overridable by itself
|
||||
value_changed = QtCore.Signal(object)
|
||||
allow_actions = False
|
||||
expand_in_grid = True
|
||||
valid_value_types = (dict, type(NOT_SET))
|
||||
|
||||
def __init__(
|
||||
self, input_data, parent,
|
||||
as_widget=False, label_widget=None, parent_widget=None
|
||||
):
|
||||
if parent_widget is None:
|
||||
parent_widget = parent
|
||||
super(DictInvisible, self).__init__(parent_widget)
|
||||
self.setObjectName("DictInvisible")
|
||||
|
||||
self.initial_attributes(input_data, parent, as_widget)
|
||||
|
||||
if self._is_group:
|
||||
raise TypeError("DictInvisible can't be marked as group input.")
|
||||
|
||||
self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
|
||||
|
||||
layout = QtWidgets.QGridLayout(self)
|
||||
layout.setContentsMargins(0, 0, 0, 0)
|
||||
layout.setSpacing(5)
|
||||
|
||||
self.content_layout = layout
|
||||
|
||||
self.input_fields = []
|
||||
|
||||
self.key = input_data["key"]
|
||||
|
||||
for child_data in input_data.get("children", []):
|
||||
self.add_children_gui(child_data)
|
||||
|
||||
any_visible = False
|
||||
for input_field in self.input_fields:
|
||||
if not input_field.hidden_by_role:
|
||||
any_visible = True
|
||||
break
|
||||
|
||||
if not any_visible:
|
||||
self.hide()
|
||||
|
||||
def add_children_gui(self, child_configuration):
|
||||
item_type = child_configuration["type"]
|
||||
klass = TypeToKlass.types.get(item_type)
|
||||
|
||||
row = self.content_layout.rowCount()
|
||||
if not getattr(klass, "is_input_type", False):
|
||||
item = klass(child_configuration, self)
|
||||
self.content_layout.addWidget(item, row, 0, 1, 2)
|
||||
return item
|
||||
|
||||
label_widget = None
|
||||
if not klass.expand_in_grid:
|
||||
label = child_configuration.get("label")
|
||||
if label is not None:
|
||||
label_widget = GridLabelWidget(label, self)
|
||||
self.content_layout.addWidget(label_widget, row, 0, 1, 1)
|
||||
|
||||
item = klass(child_configuration, self, label_widget=label_widget)
|
||||
item.value_changed.connect(self._on_value_change)
|
||||
|
||||
if label_widget:
|
||||
if item.hidden_by_role:
|
||||
label_widget.hide()
|
||||
label_widget.input_field = item
|
||||
self.content_layout.addWidget(item, row, 1, 1, 1)
|
||||
else:
|
||||
self.content_layout.addWidget(item, row, 0, 1, 2)
|
||||
|
||||
self.input_fields.append(item)
|
||||
return item
|
||||
|
||||
def update_style(self, *args, **kwargs):
|
||||
return
|
||||
|
||||
@property
|
||||
def child_has_studio_override(self):
|
||||
for input_field in self.input_fields:
|
||||
if (
|
||||
input_field.has_studio_override
|
||||
or input_field.child_has_studio_override
|
||||
):
|
||||
return True
|
||||
return False
|
||||
|
||||
@property
|
||||
def child_modified(self):
|
||||
for input_field in self.input_fields:
|
||||
if input_field.child_modified:
|
||||
return True
|
||||
return False
|
||||
|
||||
@property
|
||||
def child_overriden(self):
|
||||
for input_field in self.input_fields:
|
||||
if input_field.is_overriden or input_field.child_overriden:
|
||||
return True
|
||||
return False
|
||||
|
||||
@property
|
||||
def child_invalid(self):
|
||||
for input_field in self.input_fields:
|
||||
if input_field.child_invalid:
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_invalid(self):
|
||||
output = []
|
||||
for input_field in self.input_fields:
|
||||
output.extend(input_field.get_invalid())
|
||||
return output
|
||||
|
||||
def item_value(self):
|
||||
output = {}
|
||||
for input_field in self.input_fields:
|
||||
# TODO maybe merge instead of update should be used
|
||||
# NOTE merge is custom function which merges 2 dicts
|
||||
output.update(input_field.config_value())
|
||||
return output
|
||||
|
||||
def _on_value_change(self, item=None):
|
||||
if self.ignore_value_changes:
|
||||
return
|
||||
|
||||
if self.is_group and not self.any_parent_as_widget:
|
||||
if self.is_overidable:
|
||||
self._is_overriden = True
|
||||
else:
|
||||
self._has_studio_override = True
|
||||
self.hierarchical_style_update()
|
||||
|
||||
self.value_changed.emit(self)
|
||||
|
||||
def hierarchical_style_update(self):
|
||||
for input_field in self.input_fields:
|
||||
input_field.hierarchical_style_update()
|
||||
self.update_style()
|
||||
|
||||
def remove_overrides(self):
|
||||
self._is_overriden = False
|
||||
self._is_modified = False
|
||||
for input_field in self.input_fields:
|
||||
input_field.remove_overrides()
|
||||
|
||||
def reset_to_pype_default(self):
|
||||
for input_field in self.input_fields:
|
||||
input_field.reset_to_pype_default()
|
||||
self._has_studio_override = False
|
||||
|
||||
def set_studio_default(self):
|
||||
for input_field in self.input_fields:
|
||||
input_field.set_studio_default()
|
||||
|
||||
if self.is_group:
|
||||
self._has_studio_override = True
|
||||
|
||||
def discard_changes(self):
|
||||
self._is_modified = False
|
||||
self._is_overriden = self._was_overriden
|
||||
self._has_studio_override = self._had_studio_override
|
||||
|
||||
for input_field in self.input_fields:
|
||||
input_field.discard_changes()
|
||||
|
||||
self._is_modified = self.child_modified
|
||||
if not self.is_overidable and self.as_widget:
|
||||
if self.has_studio_override:
|
||||
self._is_modified = self.studio_value != self.item_value()
|
||||
else:
|
||||
self._is_modified = self.default_value != self.item_value()
|
||||
|
||||
self._state = None
|
||||
self._is_overriden = self._was_overriden
|
||||
|
||||
def set_as_overriden(self):
|
||||
if self.is_overriden:
|
||||
return
|
||||
|
||||
if self.is_group:
|
||||
self._is_overriden = True
|
||||
return
|
||||
|
||||
for item in self.input_fields:
|
||||
item.set_as_overriden()
|
||||
|
||||
def update_default_values(self, parent_values):
|
||||
value = NOT_SET
|
||||
if self.as_widget:
|
||||
value = parent_values
|
||||
elif parent_values is not NOT_SET:
|
||||
value = parent_values.get(self.key, NOT_SET)
|
||||
|
||||
try:
|
||||
self.validate_value(value)
|
||||
except InvalidValueType as exc:
|
||||
value = NOT_SET
|
||||
self.log.warning(exc.msg)
|
||||
|
||||
for item in self.input_fields:
|
||||
item.update_default_values(value)
|
||||
|
||||
def update_studio_values(self, parent_values):
|
||||
value = NOT_SET
|
||||
if parent_values is not NOT_SET:
|
||||
value = parent_values.get(self.key, NOT_SET)
|
||||
|
||||
try:
|
||||
self.validate_value(value)
|
||||
except InvalidValueType as exc:
|
||||
value = NOT_SET
|
||||
self.log.warning(exc.msg)
|
||||
|
||||
for item in self.input_fields:
|
||||
item.update_studio_values(value)
|
||||
|
||||
def apply_overrides(self, parent_values):
|
||||
# Make sure this is set to False
|
||||
self._state = None
|
||||
self._child_state = None
|
||||
|
||||
metadata = {}
|
||||
groups = tuple()
|
||||
override_values = NOT_SET
|
||||
if parent_values is not NOT_SET:
|
||||
metadata = parent_values.get(METADATA_KEY) or metadata
|
||||
groups = metadata.get("groups") or groups
|
||||
override_values = parent_values.get(self.key, override_values)
|
||||
|
||||
self._is_overriden = self.key in groups
|
||||
|
||||
try:
|
||||
self.validate_value(override_values)
|
||||
except InvalidValueType as exc:
|
||||
override_values = NOT_SET
|
||||
self.log.warning(exc.msg)
|
||||
|
||||
for item in self.input_fields:
|
||||
item.apply_overrides(override_values)
|
||||
|
||||
if not self._is_overriden:
|
||||
self._is_overriden = (
|
||||
self.is_group
|
||||
and self.is_overidable
|
||||
and self.child_overriden
|
||||
)
|
||||
self._was_overriden = bool(self._is_overriden)
|
||||
|
||||
def _override_values(self, project_overrides):
|
||||
values = {}
|
||||
groups = []
|
||||
for input_field in self.input_fields:
|
||||
if project_overrides:
|
||||
value, is_group = input_field.overrides()
|
||||
else:
|
||||
value, is_group = input_field.studio_overrides()
|
||||
if value is NOT_SET:
|
||||
continue
|
||||
|
||||
if METADATA_KEY in value and METADATA_KEY in values:
|
||||
new_metadata = value.pop(METADATA_KEY)
|
||||
values[METADATA_KEY] = self.merge_metadata(
|
||||
values[METADATA_KEY], new_metadata
|
||||
)
|
||||
|
||||
values.update(value)
|
||||
if is_group:
|
||||
groups.extend(value.keys())
|
||||
|
||||
if groups:
|
||||
if METADATA_KEY not in values:
|
||||
values[METADATA_KEY] = {}
|
||||
values[METADATA_KEY]["groups"] = groups
|
||||
return {self.key: values}, self.is_group
|
||||
|
||||
def studio_overrides(self):
|
||||
if (
|
||||
not (self.as_widget or self.any_parent_as_widget)
|
||||
and not self.has_studio_override
|
||||
and not self.child_has_studio_override
|
||||
):
|
||||
return NOT_SET, False
|
||||
return self._override_values(False)
|
||||
|
||||
def overrides(self):
|
||||
if not self.is_overriden and not self.child_overriden:
|
||||
return NOT_SET, False
|
||||
return self._override_values(True)
|
||||
|
||||
|
||||
class PathWidget(QtWidgets.QWidget, SettingObject):
|
||||
value_changed = QtCore.Signal(object)
|
||||
platforms = ("windows", "darwin", "linux")
|
||||
|
|
@ -3768,7 +3475,7 @@ TypeToKlass.types["dict-modifiable"] = ModifiableDict
|
|||
# DEPRECATED - remove when removed from schemas
|
||||
TypeToKlass.types["dict-item"] = DictWidget
|
||||
TypeToKlass.types["dict"] = DictWidget
|
||||
TypeToKlass.types["dict-invisible"] = DictInvisible
|
||||
TypeToKlass.types["dict-invisible"] = DictWidget
|
||||
TypeToKlass.types["path-widget"] = PathWidget
|
||||
TypeToKlass.types["form"] = DictFormWidget
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue