Add browser_did_fetch_columns hook and some doc
This commit is contained in:
parent
eafa2afc0d
commit
db32179a25
@ -817,16 +817,27 @@ def backend_color_to_aqt_color(color: BrowserRow.Color.V) -> Optional[Tuple[str,
|
|||||||
|
|
||||||
|
|
||||||
class DataModel(QAbstractTableModel):
|
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:
|
def __init__(self, col: Collection, state: ItemState) -> None:
|
||||||
QAbstractTableModel.__init__(self)
|
QAbstractTableModel.__init__(self)
|
||||||
self.col: Collection = col
|
self.col: Collection = col
|
||||||
self.columns: Dict[str, Column] = dict(
|
self.columns: Dict[str, Column] = dict(
|
||||||
((c.key, c) for c in self.col.all_browser_columns())
|
((c.key, c) for c in self.col.all_browser_columns())
|
||||||
)
|
)
|
||||||
|
gui_hooks.browser_did_fetch_columns(self.columns)
|
||||||
self._state: ItemState = state
|
self._state: ItemState = state
|
||||||
self._items: Sequence[ItemId] = []
|
self._items: Sequence[ItemId] = []
|
||||||
self._rows: Dict[int, CellRow] = {}
|
self._rows: Dict[int, CellRow] = {}
|
||||||
# serve stale content to avoid hitting the DB?
|
|
||||||
self._block_updates = False
|
self._block_updates = False
|
||||||
self._stale_cutoff = 0.0
|
self._stale_cutoff = 0.0
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ prefix = """\
|
|||||||
|
|
||||||
from __future__ import annotations
|
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 anki
|
||||||
import aqt
|
import aqt
|
||||||
@ -423,6 +423,18 @@ hooks = [
|
|||||||
represents.
|
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
|
# Main window states
|
||||||
###################
|
###################
|
||||||
# these refer to things like deckbrowser, overview and reviewer state,
|
# these refer to things like deckbrowser, overview and reviewer state,
|
||||||
|
Loading…
Reference in New Issue
Block a user