From c34e3bb15ed6d5c4cb50b993680921856cf567db Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Fri, 13 Jun 2025 15:22:22 +0200 Subject: [PATCH] auto set product type filters --- .../ayon_core/tools/loader/ui/search_bar.py | 13 ++++++++++ client/ayon_core/tools/loader/ui/window.py | 25 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/client/ayon_core/tools/loader/ui/search_bar.py b/client/ayon_core/tools/loader/ui/search_bar.py index 840013c97c..5e9e409ee1 100644 --- a/client/ayon_core/tools/loader/ui/search_bar.py +++ b/client/ayon_core/tools/loader/ui/search_bar.py @@ -709,6 +709,19 @@ class FiltersBar(BaseClickableFrame): return value return None + def set_filter_value(self, name: str, value: Any): + """Set the value of a filter by its name.""" + if name not in self._filter_defs_by_name: + return + + item_widget = self._widgets_by_name.get(name) + if item_widget is None: + self.add_item(name) + item_widget = self._widgets_by_name.get(name) + + item_widget.set_value(value) + self.filter_changed.emit(name) + def add_item(self, name: str): """Add a new item to the search bar. diff --git a/client/ayon_core/tools/loader/ui/window.py b/client/ayon_core/tools/loader/ui/window.py index 40802d3d88..a3a476b330 100644 --- a/client/ayon_core/tools/loader/ui/window.py +++ b/client/ayon_core/tools/loader/ui/window.py @@ -318,6 +318,8 @@ class LoaderWindow(QtWidgets.QWidget): self._selected_folder_ids = set() self._selected_version_ids = set() + self._set_product_type_filters = True + self._products_widget.set_enable_grouping( self._product_group_checkbox.isChecked() ) @@ -573,6 +575,29 @@ class LoaderWindow(QtWidgets.QWidget): ), ]) + # Set product types filter from settings + if self._set_product_type_filters: + self._set_product_type_filters = False + product_types_filter = self._controller.get_product_types_filter() + product_types = [] + for item in filter_product_type_items: + product_type = item["value"] + matching = ( + int(product_type in product_types_filter.product_types) + + int(product_types_filter.is_allow_list) + ) + if matching % 2 == 0: + product_types.append(product_type) + + if ( + product_types + and len(product_types) < len(filter_product_type_items) + ): + self._search_bar.set_filter_value( + "product_types", + product_types + ) + def _on_folders_selection_changed(self, event): self._selected_folder_ids = set(event["folder_ids"]) self._update_thumbnails()