mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-25 05:14:40 +01:00
Merge pull request #4116 from pypeclub/feature/OP-4409_Publisher-optional-switch-on-validators-breaks-name-in-UI
Publisher: Hide unknown publish values
This commit is contained in:
commit
3c36679c0f
3 changed files with 105 additions and 15 deletions
|
|
@ -105,11 +105,14 @@ class AbtractAttrDef(object):
|
|||
How to force to set `key` attribute?
|
||||
|
||||
Args:
|
||||
key(str): Under which key will be attribute value stored.
|
||||
label(str): Attribute label.
|
||||
tooltip(str): Attribute tooltip.
|
||||
is_label_horizontal(bool): UI specific argument. Specify if label is
|
||||
key (str): Under which key will be attribute value stored.
|
||||
default (Any): Default value of an attribute.
|
||||
label (str): Attribute label.
|
||||
tooltip (str): Attribute tooltip.
|
||||
is_label_horizontal (bool): UI specific argument. Specify if label is
|
||||
next to value input or ahead.
|
||||
hidden (bool): Will be item hidden (for UI purposes).
|
||||
disabled (bool): Item will be visible but disabled (for UI purposes).
|
||||
"""
|
||||
|
||||
type_attributes = []
|
||||
|
|
@ -117,16 +120,29 @@ class AbtractAttrDef(object):
|
|||
is_value_def = True
|
||||
|
||||
def __init__(
|
||||
self, key, default, label=None, tooltip=None, is_label_horizontal=None
|
||||
self,
|
||||
key,
|
||||
default,
|
||||
label=None,
|
||||
tooltip=None,
|
||||
is_label_horizontal=None,
|
||||
hidden=False,
|
||||
disabled=False
|
||||
):
|
||||
if is_label_horizontal is None:
|
||||
is_label_horizontal = True
|
||||
|
||||
if hidden is None:
|
||||
hidden = False
|
||||
|
||||
self.key = key
|
||||
self.label = label
|
||||
self.tooltip = tooltip
|
||||
self.default = default
|
||||
self.is_label_horizontal = is_label_horizontal
|
||||
self._id = uuid.uuid4()
|
||||
self.hidden = hidden
|
||||
self.disabled = disabled
|
||||
self._id = uuid.uuid4().hex
|
||||
|
||||
self.__init__class__ = AbtractAttrDef
|
||||
|
||||
|
|
@ -173,7 +189,9 @@ class AbtractAttrDef(object):
|
|||
"label": self.label,
|
||||
"tooltip": self.tooltip,
|
||||
"default": self.default,
|
||||
"is_label_horizontal": self.is_label_horizontal
|
||||
"is_label_horizontal": self.is_label_horizontal,
|
||||
"hidden": self.hidden,
|
||||
"disabled": self.disabled
|
||||
}
|
||||
for attr in self.type_attributes:
|
||||
data[attr] = getattr(self, attr)
|
||||
|
|
@ -235,6 +253,26 @@ class UnknownDef(AbtractAttrDef):
|
|||
return value
|
||||
|
||||
|
||||
class HiddenDef(AbtractAttrDef):
|
||||
"""Hidden value of Any type.
|
||||
|
||||
This attribute can be used for UI purposes to pass values related
|
||||
to other attributes (e.g. in multi-page UIs).
|
||||
|
||||
Keep in mind the value should be possible to parse by json parser.
|
||||
"""
|
||||
|
||||
type = "hidden"
|
||||
|
||||
def __init__(self, key, default=None, **kwargs):
|
||||
kwargs["default"] = default
|
||||
kwargs["hidden"] = True
|
||||
super(UnknownDef, self).__init__(key, **kwargs)
|
||||
|
||||
def convert_value(self, value):
|
||||
return value
|
||||
|
||||
|
||||
class NumberDef(AbtractAttrDef):
|
||||
"""Number definition.
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ from Qt import QtWidgets, QtCore
|
|||
from openpype.lib.attribute_definitions import (
|
||||
AbtractAttrDef,
|
||||
UnknownDef,
|
||||
HiddenDef,
|
||||
NumberDef,
|
||||
TextDef,
|
||||
EnumDef,
|
||||
|
|
@ -22,6 +23,16 @@ from .files_widget import FilesWidget
|
|||
|
||||
|
||||
def create_widget_for_attr_def(attr_def, parent=None):
|
||||
widget = _create_widget_for_attr_def(attr_def, parent)
|
||||
if attr_def.hidden:
|
||||
widget.setVisible(False)
|
||||
|
||||
if attr_def.disabled:
|
||||
widget.setEnabled(False)
|
||||
return widget
|
||||
|
||||
|
||||
def _create_widget_for_attr_def(attr_def, parent=None):
|
||||
if not isinstance(attr_def, AbtractAttrDef):
|
||||
raise TypeError("Unexpected type \"{}\" expected \"{}\"".format(
|
||||
str(type(attr_def)), AbtractAttrDef
|
||||
|
|
@ -42,6 +53,9 @@ def create_widget_for_attr_def(attr_def, parent=None):
|
|||
if isinstance(attr_def, UnknownDef):
|
||||
return UnknownAttrWidget(attr_def, parent)
|
||||
|
||||
if isinstance(attr_def, HiddenDef):
|
||||
return HiddenAttrWidget(attr_def, parent)
|
||||
|
||||
if isinstance(attr_def, FileDef):
|
||||
return FileAttrWidget(attr_def, parent)
|
||||
|
||||
|
|
@ -115,6 +129,10 @@ class AttributeDefinitionsWidget(QtWidgets.QWidget):
|
|||
|
||||
self._current_keys.add(attr_def.key)
|
||||
widget = create_widget_for_attr_def(attr_def, self)
|
||||
self._widgets.append(widget)
|
||||
|
||||
if attr_def.hidden:
|
||||
continue
|
||||
|
||||
expand_cols = 2
|
||||
if attr_def.is_value_def and attr_def.is_label_horizontal:
|
||||
|
|
@ -133,7 +151,6 @@ class AttributeDefinitionsWidget(QtWidgets.QWidget):
|
|||
layout.addWidget(
|
||||
widget, row, col_num, 1, expand_cols
|
||||
)
|
||||
self._widgets.append(widget)
|
||||
row += 1
|
||||
|
||||
def set_value(self, value):
|
||||
|
|
@ -459,6 +476,29 @@ class UnknownAttrWidget(_BaseAttrDefWidget):
|
|||
self._input_widget.setText(str_value)
|
||||
|
||||
|
||||
class HiddenAttrWidget(_BaseAttrDefWidget):
|
||||
def _ui_init(self):
|
||||
self.setVisible(False)
|
||||
self._value = None
|
||||
self._multivalue = False
|
||||
|
||||
def setVisible(self, visible):
|
||||
if visible:
|
||||
visible = False
|
||||
super(HiddenAttrWidget, self).setVisible(visible)
|
||||
|
||||
def current_value(self):
|
||||
if self._multivalue:
|
||||
raise ValueError("{} can't output for multivalue.".format(
|
||||
self.__class__.__name__
|
||||
))
|
||||
return self._value
|
||||
|
||||
def set_value(self, value, multivalue=False):
|
||||
self._value = copy.deepcopy(value)
|
||||
self._multivalue = multivalue
|
||||
|
||||
|
||||
class FileAttrWidget(_BaseAttrDefWidget):
|
||||
def _ui_init(self):
|
||||
input_widget = FilesWidget(
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import collections
|
|||
from Qt import QtWidgets, QtCore, QtGui
|
||||
import qtawesome
|
||||
|
||||
from openpype.lib.attribute_definitions import UnknownDef
|
||||
from openpype.tools.attribute_defs import create_widget_for_attr_def
|
||||
from openpype.tools import resources
|
||||
from openpype.tools.flickcharm import FlickCharm
|
||||
|
|
@ -1303,6 +1304,13 @@ class CreatorAttrsWidget(QtWidgets.QWidget):
|
|||
else:
|
||||
widget.set_value(values, True)
|
||||
|
||||
widget.value_changed.connect(self._input_value_changed)
|
||||
self._attr_def_id_to_instances[attr_def.id] = attr_instances
|
||||
self._attr_def_id_to_attr_def[attr_def.id] = attr_def
|
||||
|
||||
if attr_def.hidden:
|
||||
continue
|
||||
|
||||
expand_cols = 2
|
||||
if attr_def.is_value_def and attr_def.is_label_horizontal:
|
||||
expand_cols = 1
|
||||
|
|
@ -1321,13 +1329,8 @@ class CreatorAttrsWidget(QtWidgets.QWidget):
|
|||
content_layout.addWidget(
|
||||
widget, row, col_num, 1, expand_cols
|
||||
)
|
||||
|
||||
row += 1
|
||||
|
||||
widget.value_changed.connect(self._input_value_changed)
|
||||
self._attr_def_id_to_instances[attr_def.id] = attr_instances
|
||||
self._attr_def_id_to_attr_def[attr_def.id] = attr_def
|
||||
|
||||
self._scroll_area.setWidget(content_widget)
|
||||
self._content_widget = content_widget
|
||||
|
||||
|
|
@ -1421,8 +1424,17 @@ class PublishPluginAttrsWidget(QtWidgets.QWidget):
|
|||
widget = create_widget_for_attr_def(
|
||||
attr_def, content_widget
|
||||
)
|
||||
label = attr_def.label or attr_def.key
|
||||
content_layout.addRow(label, widget)
|
||||
hidden_widget = attr_def.hidden
|
||||
# Hide unknown values of publish plugins
|
||||
# - The keys in most of cases does not represent what would
|
||||
# label represent
|
||||
if isinstance(attr_def, UnknownDef):
|
||||
widget.setVisible(False)
|
||||
hidden_widget = True
|
||||
|
||||
if not hidden_widget:
|
||||
label = attr_def.label or attr_def.key
|
||||
content_layout.addRow(label, widget)
|
||||
|
||||
widget.value_changed.connect(self._input_value_changed)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue