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

General/TVPaint: Attribute defs dialog #4052

Merged
merged 10 commits into from
Nov 4, 2022
44 changes: 23 additions & 21 deletions openpype/hosts/tvpaint/plugins/load/load_image.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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"])
Expand Down
45 changes: 23 additions & 22 deletions openpype/hosts/tvpaint/plugins/load/load_reference_image.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import collections

import qargparse

from openpype.lib.attribute_definitions import BoolDef
from openpype.pipeline import (
get_representation_context,
register_host,
Expand Down Expand Up @@ -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"])
Expand Down
2 changes: 1 addition & 1 deletion openpype/lib/attribute_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def __call__(self, *args, **kwargs):


@six.add_metaclass(AbstractAttrDefMeta)
class AbtractAttrDef:
class AbtractAttrDef(object):
"""Abstraction of attribute definiton.

Each attribute definition must have implemented validation and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
AttributeDefinitionsWidget,
)

from .dialog import (
AttributeDefinitionsDialog,
)


__all__ = (
"create_widget_for_attr_def",
"AttributeDefinitionsWidget",

"AttributeDefinitionsDialog",
)
33 changes: 33 additions & 0 deletions openpype/tools/attribute_defs/dialog.py
Original file line number Diff line number Diff line change
@@ -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()
25 changes: 18 additions & 7 deletions openpype/tools/loader/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
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
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion openpype/tools/publisher/widgets/precreate_widget.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
6 changes: 3 additions & 3 deletions openpype/tools/publisher/widgets/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
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 (
Expand Down Expand Up @@ -1223,7 +1223,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.

Expand Down Expand Up @@ -1345,7 +1345,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.

Expand Down
24 changes: 22 additions & 2 deletions openpype/tools/utils/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
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__)

Expand Down Expand Up @@ -317,8 +319,26 @@ def createWidget(self, parent):

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
Expand Down
2 changes: 1 addition & 1 deletion openpype/tools/workfile_template_build/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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):
Expand Down