mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 16:34:53 +01:00
loader can handle both qargparse and attribute definitions
This commit is contained in:
parent
563447e1a4
commit
cec37f0101
2 changed files with 40 additions and 9 deletions
|
|
@ -2,6 +2,8 @@ import inspect
|
||||||
from Qt import QtGui
|
from Qt import QtGui
|
||||||
import qtawesome
|
import qtawesome
|
||||||
|
|
||||||
|
from openpype.lib.attribute_definitions import AbtractAttrDef
|
||||||
|
from openpype.tools.attribute_defs import AttributeDefinitionsDialog
|
||||||
from openpype.tools.utils.widgets import (
|
from openpype.tools.utils.widgets import (
|
||||||
OptionalAction,
|
OptionalAction,
|
||||||
OptionDialog
|
OptionDialog
|
||||||
|
|
@ -34,21 +36,30 @@ def get_options(action, loader, parent, repre_contexts):
|
||||||
None when dialog was closed or cancelled, in all other cases {}
|
None when dialog was closed or cancelled, in all other cases {}
|
||||||
if no options
|
if no options
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Pop option dialog
|
# Pop option dialog
|
||||||
options = {}
|
options = {}
|
||||||
loader_options = loader.get_options(repre_contexts)
|
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 = OptionDialog(parent)
|
||||||
dialog.setWindowTitle(action.label + " Options")
|
|
||||||
dialog.create(loader_options)
|
dialog.create(loader_options)
|
||||||
|
|
||||||
if not dialog.exec_():
|
dialog.setWindowTitle(action.label + " Options")
|
||||||
return None
|
|
||||||
|
|
||||||
# Get option
|
if not dialog.exec_():
|
||||||
options = dialog.parse()
|
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):
|
def add_representation_loaders_to_menu(loaders, menu, repre_contexts):
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,12 @@ import logging
|
||||||
from Qt import QtWidgets, QtCore, QtGui
|
from Qt import QtWidgets, QtCore, QtGui
|
||||||
import qargparse
|
import qargparse
|
||||||
import qtawesome
|
import qtawesome
|
||||||
|
|
||||||
from openpype.style import (
|
from openpype.style import (
|
||||||
get_objected_colors,
|
get_objected_colors,
|
||||||
get_style_image_path
|
get_style_image_path
|
||||||
)
|
)
|
||||||
|
from openpype.lib.attribute_definitions import AbtractAttrDef
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
@ -317,8 +319,26 @@ class OptionalAction(QtWidgets.QWidgetAction):
|
||||||
|
|
||||||
def set_option_tip(self, options):
|
def set_option_tip(self, options):
|
||||||
sep = "\n\n"
|
sep = "\n\n"
|
||||||
mak = (lambda opt: opt["name"] + " :\n " + opt["help"])
|
if not options or not isinstance(options[0], AbtractAttrDef):
|
||||||
self.option_tip = sep.join(mak(opt) for opt in options)
|
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):
|
def on_option(self):
|
||||||
self.optioned = True
|
self.optioned = True
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue