From e7014f377730213f193e2b79003a4a8b620bf4a4 Mon Sep 17 00:00:00 2001 From: h Date: Wed, 28 Jan 2026 23:35:59 +0100 Subject: [PATCH] feat: search is filtered by category --- src/illogical/modules/models.py | 27 ++++++++++++++++++++++++-- src/illogical/ui/main_window.py | 33 ++++++++++++++++++++++++++------ src/illogical/ui/plugin_table.py | 12 ++++++++++-- 3 files changed, 62 insertions(+), 10 deletions(-) diff --git a/src/illogical/modules/models.py b/src/illogical/modules/models.py index 83a28d5..7c198ab 100644 --- a/src/illogical/modules/models.py +++ b/src/illogical/modules/models.py @@ -183,9 +183,32 @@ class PluginTableModel(QAbstractTableModel): self._apply_sort() self.endResetModel() - def filter_by_search_results(self, plugins: list[AudioComponent]) -> None: + def filter_by_search_results( + self, + plugins: list[AudioComponent], + category: str | None = None, + manufacturer: str | None = None, + ) -> None: self.beginResetModel() - self._plugins = plugins + if manufacturer is not None: + self._plugins = [ + p for p in plugins if p.manufacturer.lower() == manufacturer.lower() + ] + elif category == "Show All" or category is ...: + self._plugins = plugins + elif category is None: + self._plugins = [p for p in plugins if not p.categories] + elif category == "Top Level": + self._plugins = [ + p for p in plugins if any(c.name == "" for c in p.categories) + ] + elif category is not None: + self._plugins = [ + p for p in plugins if any(c.name == category for c in p.categories) + ] + else: + self._plugins = plugins + self._apply_sort() self.endResetModel() def get_plugin(self, row: int) -> AudioComponent | None: diff --git a/src/illogical/ui/main_window.py b/src/illogical/ui/main_window.py index 9079db0..c8200fa 100644 --- a/src/illogical/ui/main_window.py +++ b/src/illogical/ui/main_window.py @@ -40,6 +40,8 @@ class MainWindow(QMainWindow): self._logic: Logic | None = None self._glass_applied = False self._settings = Settings() + self._current_category: str | None = "Show All" + self._current_manufacturer: str | None = None self._setup_ui() self._setup_service() @@ -139,16 +141,31 @@ class MainWindow(QMainWindow): self._plugin_table.focus_table() def _on_category_selected(self, category: str | None) -> None: - self._plugin_table.clear_search() - self._plugin_table.filter_by_category(category) + self._current_category = category + self._current_manufacturer = None + query = self._plugin_table.get_search_text() + if query: + self._service.search(query) + else: + self._plugin_table.filter_by_category(category) def _on_manufacturer_selected(self, manufacturer: str) -> None: - self._plugin_table.clear_search() - self._plugin_table.filter_by_manufacturer(manufacturer) + self._current_manufacturer = manufacturer + self._current_category = None + query = self._plugin_table.get_search_text() + if query: + self._service.search(query) + else: + self._plugin_table.filter_by_manufacturer(manufacturer) def _on_search_changed(self, query: str) -> None: if not query: - self._plugin_table.filter_by_category("Show All") + if self._current_manufacturer: + self._plugin_table.filter_by_manufacturer(self._current_manufacturer) + else: + self._plugin_table.filter_by_category( + self._current_category if self._current_category else "Show All" + ) return self._service.search(query) @@ -179,7 +196,11 @@ class MainWindow(QMainWindow): def _on_search_results(self, results: list[SearchResult]) -> None: plugins = [r.plugin for r in results] - self._plugin_table.filter_by_search_results(plugins) + self._plugin_table.filter_by_search_results( + plugins, + category=self._current_category, + manufacturer=self._current_manufacturer, + ) def _on_error(self, message: str) -> None: self._loading_overlay.set_message(f"Error: {message}") diff --git a/src/illogical/ui/plugin_table.py b/src/illogical/ui/plugin_table.py index 09d3033..bf241ac 100644 --- a/src/illogical/ui/plugin_table.py +++ b/src/illogical/ui/plugin_table.py @@ -148,8 +148,13 @@ class PluginTableView(QWidget): def filter_by_manufacturer(self, manufacturer: str) -> None: self._model.filter_by_manufacturer(manufacturer) - def filter_by_search_results(self, plugins: list[AudioComponent]) -> None: - self._model.filter_by_search_results(plugins) + def filter_by_search_results( + self, + plugins: list[AudioComponent], + category: str | None = None, + manufacturer: str | None = None, + ) -> None: + self._model.filter_by_search_results(plugins, category, manufacturer) def update_plugin_display(self, plugin: AudioComponent, column: int) -> None: self._model.update_plugin_display(plugin, column) @@ -157,6 +162,9 @@ class PluginTableView(QWidget): def clear_search(self) -> None: self._search_bar.clear() + def get_search_text(self) -> str: + return self._search_bar.text() + def focus_search(self) -> None: self._search_bar.setFocus() self._search_bar.selectAll()