Add browser hook setup and teardown hooks #2201
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Makes it easier for add-ons to subscribe to events such as
browser_did_change_row
with closures that refer to the current browser instance or child objects thereof, e.g. addon-provided UI elements.The concrete use case that spawned this: As part of a new feature, the AMBOSS add-on needs to add a button to the card browser that responds to the number of cards currently selected. As
gui_hooks.browser_did_change_row
is a global, but both the button and browser instance will likely be deleted during the session lifetime, adding a hook likebrowser_did_teardown_hooks
allows the add-on to sever the connection at the appropriate time.Debug console sanity check snippet:
A quick thought before merging: I'm wondering if instead you'd also be open to adding a Qt signal to
Browser
, e.g.selection_changed
. That would make it even easier for add-ons to listen to selection state changes without having to clean up after themselves (as Qt takes care of severing the signal/slot connections). But, it throws more Qt-specificity into the mix and from what I can tell, Anki only uses a handful of custom Qt signals and I don't think they were ever explicitly regarded as add-on APIs.Copyright disclosure: This patch was written as part of my work for AMBOSS. Its rights of use lie with AMBOSS MD Inc and it is being submitted in agreement with Anki's contributor license agreement, as signed by AMBOSS MD Inc. (see the
CONTRIBUTORS
file).