Skip to content

Commit 01226ec

Browse files
committed
implement and use select product dialog
1 parent 701d46c commit 01226ec

File tree

3 files changed

+105
-47
lines changed

3 files changed

+105
-47
lines changed

client/ayon_houdini/api/hda_utils.py

+102-21
Original file line numberDiff line numberDiff line change
@@ -555,38 +555,119 @@ def _select_folder_path():
555555
folder_parm.pressButton() # allow any callbacks to trigger
556556

557557

558-
def get_available_products(node):
559-
"""Return products menu items
560-
It gets a list of available products of the specified product types
561-
within the specified folder path with in the specified project.
562-
Users can specify those in the HDA parameters.
558+
class SelectProductDialog(QtWidgets.QDialog):
559+
"""Simple dialog to allow a user to select a product."""
563560

564-
Args:
565-
node (hou.OpNode): The HDA node.
561+
def __init__(self, project_name, folder_id, parent=None):
562+
super(SelectProductDialog, self).__init__(parent)
563+
self.setWindowTitle("Select a Product")
564+
self.setStyleSheet(load_stylesheet())
565+
566+
self.project_name = project_name
567+
self.folder_id = folder_id
568+
569+
# Create widgets and layout
570+
product_types_widget = QtWidgets.QComboBox()
571+
products_widget = QtWidgets.QListWidget()
572+
accept_button = QtWidgets.QPushButton("Accept")
573+
574+
main_layout = QtWidgets.QVBoxLayout(self)
575+
main_layout.addWidget(product_types_widget, 0)
576+
main_layout.addWidget(products_widget, 1)
577+
main_layout.addWidget(accept_button, 0)
578+
579+
self.product_types_widget = product_types_widget
580+
self.products_widget = products_widget
581+
582+
# Connect Signals
583+
product_types_widget.currentTextChanged.connect(self.on_product_type_changed)
584+
products_widget.itemDoubleClicked.connect(self.accept)
585+
accept_button.clicked.connect(self.accept)
586+
587+
# Initialize widgets contents
588+
product_types_widget.addItems(self.get_product_types())
589+
product_type = self.get_selected_product_type()
590+
self.set_product_name(product_type)
591+
592+
def get_selected_product(self) -> str:
593+
if self.products_widget.currentItem():
594+
return self.products_widget.currentItem().text()
595+
return ""
596+
597+
def get_selected_product_type(self) -> str:
598+
return self.product_types_widget.currentText()
599+
600+
def get_product_types(self) -> List[str]:
601+
"""return default product types.
602+
"""
603+
604+
return [
605+
"*",
606+
"animation",
607+
"camera",
608+
"model",
609+
"pointcache",
610+
"usd",
611+
]
612+
613+
def on_product_type_changed(self, product_type: str):
614+
self.set_product_name(product_type)
615+
616+
def set_product_name(self, product_type: str):
617+
self.product_types_widget.setCurrentText(product_type)
618+
619+
if self.product_types_widget.currentText() != product_type:
620+
# Product type does not exist
621+
return
622+
623+
# Populate products list
624+
products = self.get_available_products(product_type)
625+
self.products_widget.clear()
626+
if products:
627+
self.products_widget.addItems(products)
628+
629+
def get_available_products(self, product_type):
630+
631+
if product_type == "*":
632+
product_type = ""
633+
634+
product_types = [product_type] if product_type else None
635+
636+
products = ayon_api.get_products(
637+
self.project_name,
638+
folder_ids=[self.folder_id],
639+
product_types=product_types
640+
)
641+
642+
return list(sorted(product["name"] for product in products))
643+
644+
645+
def select_a_product(node):
566646

567-
Returns:
568-
list[str]: Product names for Products menu.
569-
"""
570647
project_name = node.evalParm("project_name")
571648
folder_path = node.evalParm("folder_path")
572-
product_type = node.evalParm("product_type")
649+
product_parm = node.parm("product_name")
573650

574651
folder_entity = ayon_api.get_folder_by_path(project_name,
575652
folder_path,
576653
fields={"id"})
577654
if not folder_entity:
578-
return []
579-
580-
# Apply filter only if any value is set
581-
product_types = [product_type] if product_type else None
582-
583-
products = ayon_api.get_products(
655+
return
656+
657+
dialog = SelectProductDialog(
584658
project_name,
585-
folder_ids=[folder_entity["id"]],
586-
product_types=product_types
587-
)
659+
folder_entity["id"],
660+
parent=lib.get_main_window()
661+
)
662+
result = dialog.exec_()
663+
664+
if result != QtWidgets.QDialog.Accepted:
665+
return
666+
selected_product = dialog.get_selected_product()
588667

589-
return list(sorted(product["name"] for product in products))
668+
if selected_product:
669+
product_parm.set(selected_product)
670+
product_parm.pressButton() # allow any callbacks to trigger
590671

591672

592673
def set_to_latest_version(node):

client/ayon_houdini/startup/otls/ayon_lop_import.hda/ayon_8_8Lop_1lop__import_8_81.0/DialogScript

+2-25
Original file line numberDiff line numberDiff line change
@@ -47,36 +47,13 @@
4747
parmtag { "script_callback" "hou.phm().on_representation_parms_changed(kwargs['node'])" }
4848
parmtag { "script_callback_language" "python" }
4949
}
50-
parm {
51-
name "product_type"
52-
label "Product Type"
53-
type string
54-
default { "usd" }
55-
menu {
56-
"" "*"
57-
"animation" "animation"
58-
"camera" "camera"
59-
"model" "model"
60-
"pointcache" "pointcache"
61-
"usd" "usd"
62-
}
63-
}
6450
parm {
6551
name "product_name"
6652
label "Product"
6753
type string
6854
default { "usdAsset" }
69-
menureplace {
70-
[ "products = hou.phm().get_available_products(kwargs['node'])" ]
71-
[ "" ]
72-
[ "result = []" ]
73-
[ "for product in products:" ]
74-
[ " result.append(product)" ]
75-
[ " result.append(product)" ]
76-
[ " " ]
77-
[ "return result" ]
78-
language python
79-
}
55+
parmtag { "script_action" "from ayon_houdini.api.hda_utils import select_a_product;select_a_product(kwargs['node'])" }
56+
parmtag { "script_action_icon" "BUTTONS_reselect" }
8057
parmtag { "script_callback" "hou.phm().set_to_latest_version(kwargs['node'])\nhou.phm().on_representation_parms_changed(kwargs['node'])" }
8158
parmtag { "script_callback_language" "python" }
8259
}

client/ayon_houdini/startup/otls/ayon_lop_import.hda/ayon_8_8Lop_1lop__import_8_81.0/PythonModule

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ from ayon_houdini.api.hda_utils import (
55
on_representation_parms_changed,
66
setup_flag_changed_callback,
77
get_available_versions,
8-
get_available_products,
8+
select_a_product,
99
set_to_latest_version
1010
)

0 commit comments

Comments
 (0)