mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-25 05:14:40 +01:00
simplified PathWidget with usage of dict as widget
This commit is contained in:
parent
8d2f25d1c0
commit
0f05901ac7
1 changed files with 56 additions and 90 deletions
|
|
@ -2835,13 +2835,13 @@ class PathWidget(QtWidgets.QWidget, SettingObject):
|
|||
self.multiplatform = input_data.get("multiplatform", False)
|
||||
self.multipath = input_data.get("multipath", False)
|
||||
|
||||
self.input_fields = []
|
||||
self.input_field = None
|
||||
|
||||
layout = QtWidgets.QHBoxLayout(self)
|
||||
layout.setContentsMargins(0, 0, 0, 0)
|
||||
layout.setSpacing(5)
|
||||
|
||||
if not self._as_widget:
|
||||
if not self.as_widget:
|
||||
self.key = input_data["key"]
|
||||
if not label_widget:
|
||||
label = input_data["label"]
|
||||
|
|
@ -2882,45 +2882,49 @@ class PathWidget(QtWidgets.QWidget, SettingObject):
|
|||
)
|
||||
self.setFocusProxy(path_input)
|
||||
self.content_layout.addWidget(path_input)
|
||||
self.input_fields.append(path_input)
|
||||
self.input_field = path_input
|
||||
path_input.value_changed.connect(self._on_value_change)
|
||||
return
|
||||
|
||||
input_data_for_list = {
|
||||
"object_type": "path-input"
|
||||
}
|
||||
if not self.multiplatform:
|
||||
input_data_for_list["key"] = self.key
|
||||
item_schema = {
|
||||
"key": self.key,
|
||||
"object_type": "path-input"
|
||||
}
|
||||
input_widget = ListWidget(
|
||||
input_data_for_list, self, label_widget=self.label_widget
|
||||
item_schema, self, label_widget=self.label_widget
|
||||
)
|
||||
self.setFocusProxy(input_widget)
|
||||
self.content_layout.addWidget(input_widget)
|
||||
self.input_fields.append(input_widget)
|
||||
self.input_field = input_widget
|
||||
input_widget.value_changed.connect(self._on_value_change)
|
||||
return
|
||||
|
||||
proxy_widget = QtWidgets.QWidget(self.content_widget)
|
||||
proxy_layout = QtWidgets.QFormLayout(proxy_widget)
|
||||
item_schema = {
|
||||
"type": "dict",
|
||||
"show_borders": False,
|
||||
"children": []
|
||||
}
|
||||
for platform_key in self.platforms:
|
||||
platform_label = self.platform_labels_mapping[platform_key]
|
||||
label_widget = QtWidgets.QLabel(platform_label, proxy_widget)
|
||||
child_item = {
|
||||
"key": platform_key,
|
||||
"label": platform_label
|
||||
}
|
||||
if self.multipath:
|
||||
input_data_for_list["key"] = platform_key
|
||||
input_widget = ListWidget(
|
||||
input_data_for_list, self, label_widget=label_widget
|
||||
)
|
||||
child_item["type"] = "list"
|
||||
child_item["object_type"] = "path-input"
|
||||
else:
|
||||
input_data = {"key": platform_key}
|
||||
input_widget = PathInputWidget(
|
||||
input_data, self, label_widget=label_widget
|
||||
)
|
||||
proxy_layout.addRow(label_widget, input_widget)
|
||||
self.input_fields.append(input_widget)
|
||||
input_widget.value_changed.connect(self._on_value_change)
|
||||
child_item["type"] = "path-input"
|
||||
|
||||
self.setFocusProxy(self.input_fields[0])
|
||||
self.content_layout.addWidget(proxy_widget)
|
||||
item_schema["children"].append(child_item)
|
||||
|
||||
input_widget = DictWidget(
|
||||
item_schema, self, as_widget=True, label_widget=self.label_widget
|
||||
)
|
||||
self.content_layout.addWidget(input_widget)
|
||||
self.input_field = input_widget
|
||||
input_widget.value_changed.connect(self._on_value_change)
|
||||
|
||||
def update_default_values(self, parent_values):
|
||||
self._state = None
|
||||
|
|
@ -2960,11 +2964,8 @@ class PathWidget(QtWidgets.QWidget, SettingObject):
|
|||
self._has_studio_override = False
|
||||
self._had_studio_override = False
|
||||
|
||||
if not self.multiplatform:
|
||||
self.input_fields[0].update_default_values(value)
|
||||
else:
|
||||
for input_field in self.input_fields:
|
||||
input_field.update_default_values(value)
|
||||
# TODO handle invalid value type
|
||||
self.input_field.update_default_values(value)
|
||||
|
||||
def update_studio_values(self, parent_values):
|
||||
self._state = None
|
||||
|
|
@ -2989,11 +2990,8 @@ class PathWidget(QtWidgets.QWidget, SettingObject):
|
|||
self._had_studio_override = False
|
||||
value = self.default_value
|
||||
|
||||
if not self.multiplatform:
|
||||
self.input_fields[0].update_studio_values(value)
|
||||
else:
|
||||
for input_field in self.input_fields:
|
||||
input_field.update_studio_values(value)
|
||||
# TODO handle invalid value type
|
||||
self.input_field.update_studio_values(value)
|
||||
|
||||
def apply_overrides(self, parent_values):
|
||||
self._is_modified = False
|
||||
|
|
@ -3012,11 +3010,8 @@ class PathWidget(QtWidgets.QWidget, SettingObject):
|
|||
self._is_overriden = override_values is not NOT_SET
|
||||
self._was_overriden = bool(self._is_overriden)
|
||||
|
||||
if not self.multiplatform:
|
||||
self.input_fields[0].apply_overrides(parent_values)
|
||||
else:
|
||||
for input_field in self.input_fields:
|
||||
input_field.apply_overrides(override_values)
|
||||
# TODO handle invalid value type
|
||||
self.input_field.update_studio_values(override_values)
|
||||
|
||||
if not self._is_overriden:
|
||||
self._is_overriden = (
|
||||
|
|
@ -3029,12 +3024,13 @@ class PathWidget(QtWidgets.QWidget, SettingObject):
|
|||
|
||||
def set_value(self, value):
|
||||
if not self.multiplatform:
|
||||
self.input_fields[0].set_value(value)
|
||||
return self.input_field.set_value(value)
|
||||
|
||||
else:
|
||||
for input_field in self.input_fields:
|
||||
_value = value[input_field.key]
|
||||
input_field.set_value(_value)
|
||||
for _input_field in self.input_field.input_fields:
|
||||
_value = value.get(_input_field.key, NOT_SET)
|
||||
if _value is NOT_SET:
|
||||
continue
|
||||
_input_field.set_value(_value)
|
||||
|
||||
def _on_value_change(self, item=None):
|
||||
if self.ignore_value_changes:
|
||||
|
|
@ -3095,17 +3091,14 @@ class PathWidget(QtWidgets.QWidget, SettingObject):
|
|||
def remove_overrides(self):
|
||||
self._is_overriden = False
|
||||
self._is_modified = False
|
||||
for input_field in self.input_fields:
|
||||
input_field.remove_overrides()
|
||||
self.input_field.remove_overrides()
|
||||
|
||||
def reset_to_pype_default(self):
|
||||
for input_field in self.input_fields:
|
||||
input_field.reset_to_pype_default()
|
||||
self.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()
|
||||
self.input_field.set_studio_default()
|
||||
|
||||
if self.is_group:
|
||||
self._has_studio_override = True
|
||||
|
|
@ -3114,8 +3107,7 @@ class PathWidget(QtWidgets.QWidget, SettingObject):
|
|||
self._is_modified = False
|
||||
self._is_overriden = self._was_overriden
|
||||
|
||||
for input_field in self.input_fields:
|
||||
input_field.discard_changes()
|
||||
self.input_field.discard_changes()
|
||||
|
||||
self._is_modified = self.child_modified
|
||||
|
||||
|
|
@ -3124,51 +3116,29 @@ class PathWidget(QtWidgets.QWidget, SettingObject):
|
|||
|
||||
@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
|
||||
return (
|
||||
self.input_field.has_studio_override
|
||||
or self.input_field.child_has_studio_override
|
||||
)
|
||||
|
||||
@property
|
||||
def child_modified(self):
|
||||
for input_field in self.input_fields:
|
||||
if input_field.child_modified:
|
||||
return True
|
||||
return False
|
||||
return self.input_field.child_modified
|
||||
|
||||
@property
|
||||
def child_overriden(self):
|
||||
for input_field in self.input_fields:
|
||||
if input_field.child_overriden:
|
||||
return True
|
||||
return False
|
||||
return self.input_field.child_overriden
|
||||
|
||||
@property
|
||||
def child_invalid(self):
|
||||
for input_field in self.input_fields:
|
||||
if input_field.child_invalid:
|
||||
return True
|
||||
return False
|
||||
return self.input_field.child_invalid
|
||||
|
||||
def hierarchical_style_update(self):
|
||||
for input_field in self.input_fields:
|
||||
input_field.hierarchical_style_update()
|
||||
self.input_field.hierarchical_style_update()
|
||||
self.update_style()
|
||||
|
||||
def item_value(self):
|
||||
if not self.multiplatform and not self.multipath:
|
||||
return self.input_fields[0].item_value()
|
||||
|
||||
if not self.multiplatform:
|
||||
return self.input_fields[0].item_value()
|
||||
|
||||
output = {}
|
||||
for input_field in self.input_fields:
|
||||
output.update(input_field.config_value())
|
||||
return output
|
||||
return self.input_field.item_value()
|
||||
|
||||
def studio_overrides(self):
|
||||
if (
|
||||
|
|
@ -3178,18 +3148,14 @@ class PathWidget(QtWidgets.QWidget, SettingObject):
|
|||
):
|
||||
return NOT_SET, False
|
||||
|
||||
value = self.item_value()
|
||||
if not self.multiplatform:
|
||||
value = {self.key: value}
|
||||
value = {self.key: self.item_value()}
|
||||
return value, self.is_group
|
||||
|
||||
def overrides(self):
|
||||
if not self.is_overriden and not self.child_overriden:
|
||||
return NOT_SET, False
|
||||
|
||||
value = self.item_value()
|
||||
if not self.multiplatform:
|
||||
value = {self.key: value}
|
||||
value = {self.key: self.item_value()}
|
||||
return value, self.is_group
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue