Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loader: Implement existing product group picker in Group Products dialog #668

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
BigRoy marked this conversation as resolved.
Show resolved Hide resolved
group_picker_btn.setFixedWidth(18)
BigRoy marked this conversation as resolved.
Show resolved Hide resolved
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()
BigRoy marked this conversation as resolved.
Show resolved Hide resolved
name_layout.addWidget(group_name_input)
name_layout.addWidget(group_picker_btn)
BigRoy marked this conversation as resolved.
Show resolved Hide resolved

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(
BigRoy marked this conversation as resolved.
Show resolved Hide resolved
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
Loading