From ea0f299a4e4badd57c9c4fb72abd751a240ffdfb Mon Sep 17 00:00:00 2001 From: Jonathan Schoreels Date: Thu, 24 Apr 2025 22:21:16 +0200 Subject: [PATCH] Add a way to pass information from browser_will_search to browser_did_search without having it going to the backend --- qt/aqt/browser/table/__init__.py | 1 + qt/aqt/browser/table/model.py | 1 + qt/tools/genhooks_gui.py | 6 ++++++ 3 files changed, 8 insertions(+) diff --git a/qt/aqt/browser/table/__init__.py b/qt/aqt/browser/table/__init__.py index ac3348bbb..0ddd5770d 100644 --- a/qt/aqt/browser/table/__init__.py +++ b/qt/aqt/browser/table/__init__.py @@ -29,6 +29,7 @@ class SearchContext: browser: aqt.browser.Browser order: bool | str | Column = True reverse: bool = False + properties: dict = None # if set, provided ids will be used instead of the regular search ids: Sequence[ItemId] | None = None diff --git a/qt/aqt/browser/table/model.py b/qt/aqt/browser/table/model.py index 12a5162d1..a137a7505 100644 --- a/qt/aqt/browser/table/model.py +++ b/qt/aqt/browser/table/model.py @@ -269,6 +269,7 @@ class DataModel(QAbstractTableModel): # invalid sort column in config context.order = self.columns["noteCrt"] context.reverse = self._state.sort_backwards + context.properties = {} gui_hooks.browser_will_search(context) if context.ids is None: context.ids = self._state.find_items( diff --git a/qt/tools/genhooks_gui.py b/qt/tools/genhooks_gui.py index f63a64f91..25743bb5b 100644 --- a/qt/tools/genhooks_gui.py +++ b/qt/tools/genhooks_gui.py @@ -549,6 +549,9 @@ hooks = [ You can modify context.search to change the text that is sent to the searching backend. + If you need to pass properties to the browser_did_search hook, you can + do it with context.properties + If you set context.ids to a list of ids, the regular search will not be performed, and the provided ids will be used instead. @@ -578,6 +581,9 @@ hooks = [ backend did not recognize will be returned as an empty string, and can be replaced with custom content. + You can retrieve properties passed from browser_will_search with + context.properties (for example to trigger post-processing filtering) + Columns is a list of string values identifying what each column in the row represents. """,