@@ -555,38 +555,119 @@ def _select_folder_path():
555
555
folder_parm .pressButton () # allow any callbacks to trigger
556
556
557
557
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."""
563
560
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 ):
566
646
567
- Returns:
568
- list[str]: Product names for Products menu.
569
- """
570
647
project_name = node .evalParm ("project_name" )
571
648
folder_path = node .evalParm ("folder_path" )
572
- product_type = node .evalParm ( "product_type " )
649
+ product_parm = node .parm ( "product_name " )
573
650
574
651
folder_entity = ayon_api .get_folder_by_path (project_name ,
575
652
folder_path ,
576
653
fields = {"id" })
577
654
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 (
584
658
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 ()
588
667
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
590
671
591
672
592
673
def set_to_latest_version (node ):
0 commit comments