Skip to content

Commit

Permalink
Implement existing product group picker in Group Products dialog, fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
BigRoy committed Jun 18, 2024
1 parent e5cc5de commit b88430b
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion client/ayon_core/tools/loader/ui/product_group_dialog.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from qtpy import QtWidgets

from ayon_core.tools.utils import PlaceholderLineEdit
import ayon_api


class ProductGroupDialog(QtWidgets.QDialog):
Expand All @@ -15,13 +16,22 @@ def __init__(self, controller, parent):
group_name_input = PlaceholderLineEdit(self)
group_name_input.setPlaceholderText("Remain blank to ungroup..")

group_picker_btn = QtWidgets.QPushButton()
group_picker_btn.setFixedWidth(18)
group_picker_menu = QtWidgets.QMenu(group_picker_btn)
group_picker_btn.setMenu(group_picker_menu)

group_btn = QtWidgets.QPushButton("Apply", self)
group_btn.setAutoDefault(True)
group_btn.setDefault(True)

name_layout = QtWidgets.QHBoxLayout()
name_layout.addWidget(group_name_input)
name_layout.addWidget(group_picker_btn)

layout = QtWidgets.QVBoxLayout(self)
layout.addWidget(main_label, 0)
layout.addWidget(group_name_input, 0)
layout.addLayout(name_layout, 0)
layout.addWidget(group_btn, 0)

group_btn.clicked.connect(self._on_apply_click)
Expand All @@ -32,11 +42,46 @@ def __init__(self, controller, parent):
self._controller = controller
self._group_btn = group_btn
self._group_name_input = group_name_input
self._group_picker_btn = group_picker_btn
self._group_picker_menu = group_picker_menu
self._group_picker_menu.triggered.connect(self._on_picker_clicked)

def set_product_ids(self, project_name, product_ids):
self._project_name = project_name
self._product_ids = product_ids

# Get parent folders, then for all products under those folders
# get all product groups so we can provide those as 'predefined'
# entries
folder_ids = {
product["folderId"] for product in
ayon_api.get_products(
project_name, product_ids=product_ids, fields={"folderId"})
}
product_groups = set()
for product in ayon_api.get_products(
project_name,
folder_ids=folder_ids,
fields={"attrib.productGroup"}
):
product_group = product.get("attrib", {}).get("productGroup")
if product_group:
product_groups.add(product_group)

self._set_product_groups(product_groups)

def _set_product_groups(self, product_groups):
"""Update product groups for the preset list available in the dialog"""
# Update product group picker menu and state
self._group_picker_menu.clear()
for product_group in product_groups:
self._group_picker_menu.addAction(product_group)
self._group_picker_btn.setEnabled(bool(product_groups))

def _on_picker_clicked(self, action):
"""Callback when action is clicked in group picker menu"""
self._group_name_input.setText(action.text())

def _on_apply_click(self):
group_name = self._group_name_input.text().strip() or None
self._controller.change_products_group(
Expand Down

0 comments on commit b88430b

Please sign in to comment.