diff --git a/qt/aqt/table.py b/qt/aqt/table.py index 65831ced9..4fff87fb1 100644 --- a/qt/aqt/table.py +++ b/qt/aqt/table.py @@ -817,16 +817,27 @@ def backend_color_to_aqt_color(color: BrowserRow.Color.V) -> Optional[Tuple[str, class DataModel(QAbstractTableModel): + """Data manager for the browser table. + + _items -- The card or note ids currently hold and corresponding to the + table's rows. + _rows -- The cached data objects to render items to rows. + columns -- The data objects of all available columns, used to define the display + of active columns and list all toggleable columns to the user. + _block_updates -- If True, serve stale content to avoid hitting the DB. + _stale_cutoff -- A threshold to decide whether a cached row has gone stale. + """ + def __init__(self, col: Collection, state: ItemState) -> None: QAbstractTableModel.__init__(self) self.col: Collection = col self.columns: Dict[str, Column] = dict( ((c.key, c) for c in self.col.all_browser_columns()) ) + gui_hooks.browser_did_fetch_columns(self.columns) self._state: ItemState = state self._items: Sequence[ItemId] = [] self._rows: Dict[int, CellRow] = {} - # serve stale content to avoid hitting the DB? self._block_updates = False self._stale_cutoff = 0.0 diff --git a/qt/tools/genhooks_gui.py b/qt/tools/genhooks_gui.py index ebcf373b1..55b244135 100644 --- a/qt/tools/genhooks_gui.py +++ b/qt/tools/genhooks_gui.py @@ -16,7 +16,7 @@ prefix = """\ from __future__ import annotations -from typing import Any, Callable, List, Sequence, Tuple, Optional, Union +from typing import Any, Callable, Dict, List, Sequence, Tuple, Optional, Union import anki import aqt @@ -423,6 +423,18 @@ hooks = [ represents. """, ), + Hook( + name="browser_did_fetch_columns", + args=["columns: Dict[str, aqt.table.Column]"], + doc="""Allows you to add custom columns to the browser. + + columns is a dictionary of data obejcts. You can add an entry with a custom + column to describe how it should be displayed in the browser or modify + existing entries. + + Every column in the dictionary will be toggleable by the user. + """, + ), # Main window states ################### # these refer to things like deckbrowser, overview and reviewer state,