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
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 15 additions & 0 deletions client/ayon_core/tools/loader/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,21 @@ def get_thumbnail_path(self, project_name, thumbnail_id):

pass

def get_folder_product_group_names(
self, project_name, folder_ids
):
"""Return all used product group names for products under folder ids.

Args:
project_name (str): Project name.
folder_ids (Iterable[str]): Folder ids.

Returns:
set[str]: Product group names set for products under given folders.

"""
pass

# Selection model wrapper calls
@abstractmethod
def get_selected_project_name(self):
Expand Down
12 changes: 12 additions & 0 deletions client/ayon_core/tools/loader/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,18 @@ def get_thumbnail_path(self, project_name, thumbnail_id):
project_name, thumbnail_id
)

def get_folder_product_group_names(
self, project_name, folder_ids
):
product_items = self.get_product_items(
project_name=project_name,
folder_ids=folder_ids)
product_groups = {
product_item.group_name for product_item in product_items
}
product_groups.discard(None)
return product_groups

def change_products_group(self, project_name, product_ids, group_name):
self._products_model.change_products_group(
project_name, product_ids, group_name
Expand Down
33 changes: 24 additions & 9 deletions client/ayon_core/tools/loader/ui/product_group_dialog.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,59 @@
import typing

from qtpy import QtWidgets

from ayon_core.tools.utils import PlaceholderLineEdit
from ayon_core.tools.utils import HintedLineEdit

if typing.TYPE_CHECKING:
from ayon_core.tools.loader.control import LoaderController


class ProductGroupDialog(QtWidgets.QDialog):
def __init__(self, controller, parent):
def __init__(self, controller: "LoaderController", parent):
super(ProductGroupDialog, self).__init__(parent)
self.setWindowTitle("Grouping products")
self.setMinimumWidth(250)
self.setModal(True)

main_label = QtWidgets.QLabel("Group Name", self)

group_name_input = PlaceholderLineEdit(self)
group_name_input.setPlaceholderText("Remain blank to ungroup..")
name_line_edit = HintedLineEdit(parent=self)
name_line_edit.setPlaceholderText("Remain blank to ungroup..")
name_line_edit.set_button_tool_tip(
"Pick from an existing product group (if any)")

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

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

group_btn.clicked.connect(self._on_apply_click)
name_line_edit.returnPressed.connect(self._on_apply_click)

self._project_name = None
self._product_ids = set()

self._controller = controller
self._controller: "LoaderController" = controller
self._group_btn = group_btn
self._group_name_input = group_name_input
self._name_line_edit = name_line_edit

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

# Update the product groups
product_groups = self._controller.get_folder_product_group_names(
project_name=project_name,
folder_ids=folder_ids
)
self._name_line_edit.set_options(list(sorted(product_groups)))

Comment on lines +53 to +54
Copy link
Member

@iLLiCiTiT iLLiCiTiT Sep 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pre-fill group field value based on selection.

Suggested change
self._name_line_edit.set_options(list(sorted(product_groups)))
product_group = ""
if product_groups:
product_group = next(iter(product_groups))
self._name_line_edit.setText(product_group)
self._name_line_edit.set_options(list(sorted(product_groups)))

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The listed product groups are ALL groups under the active folders - not just the groups of the products in your selection. Just so that you can easily move it into another group outside of your selection.

So technically, this would first have to get all the product entities, get their product groups - then from those pick the first entry (or most used entry)...

Copy link
Member

@iLLiCiTiT iLLiCiTiT Sep 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, right now it's prefilled with previous value of the widget. So either we use first, or empty string, or most common, but current behavior is not correct.

Suggested change
self._name_line_edit.set_options(list(sorted(product_groups)))
self._name_line_edit.setText("")
self._name_line_edit.set_options(list(sorted(product_groups)))

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder...

def _on_apply_click(self):
group_name = self._group_name_input.text().strip() or None
group_name = self._name_line_edit.text().strip() or None
self._controller.change_products_group(
self._project_name, self._product_ids, group_name
)
Expand Down
14 changes: 9 additions & 5 deletions client/ayon_core/tools/loader/ui/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,14 +402,18 @@ def _show_group_dialog(self):
if not project_name:
return

product_ids = {
i["product_id"]
for i in self._products_widget.get_selected_version_info()
}
product_ids = set()
folder_ids = set()
for version_info in self._products_widget.get_selected_version_info():
product_ids.add(version_info["product_id"])
folder_ids.add(version_info["folder_id"])

if not product_ids:
return

self._group_dialog.set_product_ids(project_name, product_ids)
self._group_dialog.set_product_ids(
project_name, folder_ids, product_ids
)
self._group_dialog.show()

def _on_folder_filter_change(self, text):
Expand Down