add hook to modify browser row content

This commit is contained in:
Damien Elmes 2021-03-23 19:13:52 +10:00
parent 9c456dd7b0
commit 3199dcb54d
2 changed files with 18 additions and 2 deletions

View File

@ -166,7 +166,7 @@ class DataModel(QAbstractTableModel):
self.browser = browser
self.col = browser.col
self.sortKey = None
self.activeCols = self.col.get_config(
self.activeCols: List[str] = self.col.get_config(
"activeCols", ["noteFld", "template", "cardDue", "deck"]
)
self.cards: Sequence[int] = []
@ -199,12 +199,15 @@ class DataModel(QAbstractTableModel):
def _fetch_row_from_backend(self, cid: int) -> CellRow:
try:
return CellRow(*self.col.browser_row_for_card(cid))
row = CellRow(*self.col.browser_row_for_card(cid))
except NotFoundError:
return CellRow.deleted(len(self.activeCols))
except Exception as e:
return CellRow.generic(len(self.activeCols), str(e))
gui_hooks.browser_did_fetch_row(cid, row, self.activeCols)
return row
def getCard(self, index: QModelIndex) -> Optional[Card]:
"""Try to return the indicated, possibly deleted card."""
try:

View File

@ -365,6 +365,19 @@ hooks = [
args=["context: aqt.browser.SearchContext"],
doc="""Allows you to modify the list of returned card ids from a search.""",
),
Hook(
name="browser_did_fetch_row",
args=["card_id: int", "row: aqt.browser.CellRow", "columns: Sequence[str]"],
doc="""Allows you to add or modify content to a row in the browser.
You can mutate the row object to change what is displayed. Any columns the
backend did not recognize will be returned as an empty string, and can be
replaced with custom content.
Columns is a list of string values identifying what each column in the row
represents.
""",
),
# Main window states
###################
# these refer to things like deckbrowser, overview and reviewer state,