Merge pull request #4052 from pypeclub/feature/attribute_defs_dialog

General/TVPaint: Attribute defs dialog
This commit is contained in:
Jakub Trllo 2022-11-04 21:36:12 +01:00 committed by GitHub
commit d4ae2ac60c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 131 additions and 58 deletions

View file

@ -1,4 +1,4 @@
import qargparse
from openpype.lib.attribute_definitions import BoolDef
from openpype.hosts.tvpaint.api import plugin
from openpype.hosts.tvpaint.api.lib import execute_george_through_file
@ -27,26 +27,28 @@ class ImportImage(plugin.Loader):
"preload": True
}
options = [
qargparse.Boolean(
"stretch",
label="Stretch to project size",
default=True,
help="Stretch loaded image/s to project resolution?"
),
qargparse.Boolean(
"timestretch",
label="Stretch to timeline length",
default=True,
help="Clip loaded image/s to timeline length?"
),
qargparse.Boolean(
"preload",
label="Preload loaded image/s",
default=True,
help="Preload image/s?"
)
]
@classmethod
def get_options(cls, contexts):
return [
BoolDef(
"stretch",
label="Stretch to project size",
default=cls.defaults["stretch"],
tooltip="Stretch loaded image/s to project resolution?"
),
BoolDef(
"timestretch",
label="Stretch to timeline length",
default=cls.defaults["timestretch"],
tooltip="Clip loaded image/s to timeline length?"
),
BoolDef(
"preload",
label="Preload loaded image/s",
default=cls.defaults["preload"],
tooltip="Preload image/s?"
)
]
def load(self, context, name, namespace, options):
stretch = options.get("stretch", self.defaults["stretch"])

View file

@ -1,7 +1,6 @@
import collections
import qargparse
from openpype.lib.attribute_definitions import BoolDef
from openpype.pipeline import (
get_representation_context,
register_host,
@ -42,26 +41,28 @@ class LoadImage(plugin.Loader):
"preload": True
}
options = [
qargparse.Boolean(
"stretch",
label="Stretch to project size",
default=True,
help="Stretch loaded image/s to project resolution?"
),
qargparse.Boolean(
"timestretch",
label="Stretch to timeline length",
default=True,
help="Clip loaded image/s to timeline length?"
),
qargparse.Boolean(
"preload",
label="Preload loaded image/s",
default=True,
help="Preload image/s?"
)
]
@classmethod
def get_options(cls, contexts):
return [
BoolDef(
"stretch",
label="Stretch to project size",
default=cls.defaults["stretch"],
tooltip="Stretch loaded image/s to project resolution?"
),
BoolDef(
"timestretch",
label="Stretch to timeline length",
default=cls.defaults["timestretch"],
tooltip="Clip loaded image/s to timeline length?"
),
BoolDef(
"preload",
label="Preload loaded image/s",
default=cls.defaults["preload"],
tooltip="Preload image/s?"
)
]
def load(self, context, name, namespace, options):
stretch = options.get("stretch", self.defaults["stretch"])

View file

@ -91,7 +91,7 @@ class AbstractAttrDefMeta(ABCMeta):
@six.add_metaclass(AbstractAttrDefMeta)
class AbtractAttrDef:
class AbtractAttrDef(object):
"""Abstraction of attribute definiton.
Each attribute definition must have implemented validation and

View file

@ -3,8 +3,14 @@ from .widgets import (
AttributeDefinitionsWidget,
)
from .dialog import (
AttributeDefinitionsDialog,
)
__all__ = (
"create_widget_for_attr_def",
"AttributeDefinitionsWidget",
"AttributeDefinitionsDialog",
)

View file

@ -0,0 +1,33 @@
from Qt import QtWidgets
from .widgets import AttributeDefinitionsWidget
class AttributeDefinitionsDialog(QtWidgets.QDialog):
def __init__(self, attr_defs, parent=None):
super(AttributeDefinitionsDialog, self).__init__(parent)
attrs_widget = AttributeDefinitionsWidget(attr_defs, self)
btns_widget = QtWidgets.QWidget(self)
ok_btn = QtWidgets.QPushButton("OK", btns_widget)
cancel_btn = QtWidgets.QPushButton("Cancel", btns_widget)
btns_layout = QtWidgets.QHBoxLayout(btns_widget)
btns_layout.setContentsMargins(0, 0, 0, 0)
btns_layout.addStretch(1)
btns_layout.addWidget(ok_btn, 0)
btns_layout.addWidget(cancel_btn, 0)
main_layout = QtWidgets.QVBoxLayout(self)
main_layout.addWidget(attrs_widget, 0)
main_layout.addStretch(1)
main_layout.addWidget(btns_widget, 0)
ok_btn.clicked.connect(self.accept)
cancel_btn.clicked.connect(self.reject)
self._attrs_widget = attrs_widget
def get_values(self):
return self._attrs_widget.current_value()

View file

@ -2,6 +2,8 @@ import inspect
from Qt import QtGui
import qtawesome
from openpype.lib.attribute_definitions import AbtractAttrDef
from openpype.tools.attribute_defs import AttributeDefinitionsDialog
from openpype.tools.utils.widgets import (
OptionalAction,
OptionDialog
@ -34,21 +36,30 @@ def get_options(action, loader, parent, repre_contexts):
None when dialog was closed or cancelled, in all other cases {}
if no options
"""
# Pop option dialog
options = {}
loader_options = loader.get_options(repre_contexts)
if getattr(action, "optioned", False) and loader_options:
if not getattr(action, "optioned", False) or not loader_options:
return options
if isinstance(loader_options[0], AbtractAttrDef):
qargparse_options = False
dialog = AttributeDefinitionsDialog(loader_options, parent)
else:
qargparse_options = True
dialog = OptionDialog(parent)
dialog.setWindowTitle(action.label + " Options")
dialog.create(loader_options)
if not dialog.exec_():
return None
dialog.setWindowTitle(action.label + " Options")
# Get option
options = dialog.parse()
if not dialog.exec_():
return None
return options
# Get option
if qargparse_options:
return dialog.parse()
return dialog.get_values()
def add_representation_loaders_to_menu(loaders, menu, repre_contexts):

View file

@ -1,6 +1,6 @@
from Qt import QtWidgets, QtCore
from openpype.widgets.attribute_defs import create_widget_for_attr_def
from openpype.tools.attribute_defs import create_widget_for_attr_def
class PreCreateWidget(QtWidgets.QWidget):

View file

@ -9,7 +9,7 @@ import collections
from Qt import QtWidgets, QtCore, QtGui
import qtawesome
from openpype.widgets.attribute_defs import create_widget_for_attr_def
from openpype.tools.attribute_defs import create_widget_for_attr_def
from openpype.tools import resources
from openpype.tools.flickcharm import FlickCharm
from openpype.tools.utils import (
@ -1229,7 +1229,7 @@ class CreatorAttrsWidget(QtWidgets.QWidget):
Attributes are defined on creator so are dynamic. Their look and type is
based on attribute definitions that are defined in
`~/openpype/pipeline/lib/attribute_definitions.py` and their widget
representation in `~/openpype/widgets/attribute_defs/*`.
representation in `~/openpype/tools/attribute_defs/*`.
Widgets are disabled if context of instance is not valid.
@ -1353,7 +1353,7 @@ class PublishPluginAttrsWidget(QtWidgets.QWidget):
Look and type of attributes is based on attribute definitions that are
defined in `~/openpype/pipeline/lib/attribute_definitions.py` and their
widget representation in `~/openpype/widgets/attribute_defs/*`.
widget representation in `~/openpype/tools/attribute_defs/*`.
Widgets are disabled if context of instance is not valid.

View file

@ -3,10 +3,12 @@ import logging
from Qt import QtWidgets, QtCore, QtGui
import qargparse
import qtawesome
from openpype.style import (
get_objected_colors,
get_style_image_path
)
from openpype.lib.attribute_definitions import AbtractAttrDef
log = logging.getLogger(__name__)
@ -401,8 +403,26 @@ class OptionalAction(QtWidgets.QWidgetAction):
def set_option_tip(self, options):
sep = "\n\n"
mak = (lambda opt: opt["name"] + " :\n " + opt["help"])
self.option_tip = sep.join(mak(opt) for opt in options)
if not options or not isinstance(options[0], AbtractAttrDef):
mak = (lambda opt: opt["name"] + " :\n " + opt["help"])
self.option_tip = sep.join(mak(opt) for opt in options)
return
option_items = []
for option in options:
option_lines = []
if option.label:
option_lines.append(
"{} ({}) :".format(option.label, option.key)
)
else:
option_lines.append("{} :".format(option.key))
if option.tooltip:
option_lines.append(" - {}".format(option.tooltip))
option_items.append("\n".join(option_lines))
self.option_tip = sep.join(option_items)
def on_option(self):
self.optioned = True

View file

@ -3,7 +3,7 @@ from Qt import QtWidgets
from openpype import style
from openpype.lib import Logger
from openpype.pipeline import legacy_io
from openpype.widgets.attribute_defs import AttributeDefinitionsWidget
from openpype.tools.attribute_defs import AttributeDefinitionsWidget
class WorkfileBuildPlaceholderDialog(QtWidgets.QDialog):