loader can handle both qargparse and attribute definitions

This commit is contained in:
Jakub Trllo 2022-11-01 14:36:50 +01:00
parent 563447e1a4
commit cec37f0101
2 changed files with 40 additions and 9 deletions

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):