Remove Column class and use pb class instead
This commit is contained in:
parent
6c3c479906
commit
f78401619a
@ -21,6 +21,7 @@ OpChangesWithId = _pb.OpChangesWithId
|
|||||||
OpChangesAfterUndo = _pb.OpChangesAfterUndo
|
OpChangesAfterUndo = _pb.OpChangesAfterUndo
|
||||||
DefaultsForAdding = _pb.DeckAndNotetype
|
DefaultsForAdding = _pb.DeckAndNotetype
|
||||||
BrowserRow = _pb.BrowserRow
|
BrowserRow = _pb.BrowserRow
|
||||||
|
BrowserColumns = _pb.BrowserColumns
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
import os
|
import os
|
||||||
@ -696,15 +697,11 @@ class Collection:
|
|||||||
# Browser Table
|
# Browser Table
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
def all_browser_card_columns(
|
def all_browser_card_columns(self) -> Sequence[BrowserColumns.Column]:
|
||||||
self,
|
return self._backend.all_browser_card_columns()
|
||||||
) -> Generator[Tuple[str, str, bool, bool, bool, bool], None, None]:
|
|
||||||
return (_column_data(c) for c in self._backend.all_browser_card_columns())
|
|
||||||
|
|
||||||
def all_browser_note_columns(
|
def all_browser_note_columns(self) -> Sequence[BrowserColumns.Column]:
|
||||||
self,
|
return self._backend.all_browser_note_columns()
|
||||||
) -> Generator[Tuple[str, str, bool, bool, bool, bool], None, None]:
|
|
||||||
return (_column_data(c) for c in self._backend.all_browser_note_columns())
|
|
||||||
|
|
||||||
def browser_row_for_id(
|
def browser_row_for_id(
|
||||||
self, id_: int
|
self, id_: int
|
||||||
@ -1141,16 +1138,3 @@ def _build_sort_mode(
|
|||||||
return _pb.SortOrder(none=_pb.Empty())
|
return _pb.SortOrder(none=_pb.Empty())
|
||||||
else:
|
else:
|
||||||
return _pb.SortOrder(builtin=_pb.SortOrder.Builtin(kind=order, reverse=reverse))
|
return _pb.SortOrder(builtin=_pb.SortOrder.Builtin(kind=order, reverse=reverse))
|
||||||
|
|
||||||
|
|
||||||
def _column_data(
|
|
||||||
column: _pb.BrowserColumns.Column,
|
|
||||||
) -> Tuple[str, str, bool, bool, bool, bool]:
|
|
||||||
return (
|
|
||||||
column.key,
|
|
||||||
column.label,
|
|
||||||
column.is_sortable,
|
|
||||||
column.sorts_reversed,
|
|
||||||
column.uses_cell_font,
|
|
||||||
column.aligns_centered,
|
|
||||||
)
|
|
||||||
|
@ -5,7 +5,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import time
|
import time
|
||||||
from abc import ABC, abstractmethod, abstractproperty
|
from abc import ABC, abstractmethod, abstractproperty
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass
|
||||||
from typing import (
|
from typing import (
|
||||||
Any,
|
Any,
|
||||||
Callable,
|
Callable,
|
||||||
@ -22,6 +22,7 @@ from typing import (
|
|||||||
import aqt
|
import aqt
|
||||||
import aqt.forms
|
import aqt.forms
|
||||||
from anki.cards import Card, CardId
|
from anki.cards import Card, CardId
|
||||||
|
from anki.collection import BrowserColumns as Columns
|
||||||
from anki.collection import BrowserRow, Collection, Config, OpChanges
|
from anki.collection import BrowserRow, Collection, Config, OpChanges
|
||||||
from anki.consts import *
|
from anki.consts import *
|
||||||
from anki.errors import NotFoundError
|
from anki.errors import NotFoundError
|
||||||
@ -39,6 +40,7 @@ from aqt.utils import (
|
|||||||
tr,
|
tr,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Column = Columns.Column
|
||||||
ItemId = Union[CardId, NoteId]
|
ItemId = Union[CardId, NoteId]
|
||||||
ItemList = Union[Sequence[CardId], Sequence[NoteId]]
|
ItemList = Union[Sequence[CardId], Sequence[NoteId]]
|
||||||
|
|
||||||
@ -551,7 +553,7 @@ class ItemState(ABC):
|
|||||||
try:
|
try:
|
||||||
return self._columns[key]
|
return self._columns[key]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self._columns[key] = Column(key)
|
self._columns[key] = addon_column_fillin(key)
|
||||||
return self._columns[key]
|
return self._columns[key]
|
||||||
|
|
||||||
# Columns and sorting
|
# Columns and sorting
|
||||||
@ -628,9 +630,7 @@ class ItemState(ABC):
|
|||||||
class CardState(ItemState):
|
class CardState(ItemState):
|
||||||
def __init__(self, col: Collection) -> None:
|
def __init__(self, col: Collection) -> None:
|
||||||
super().__init__(col)
|
super().__init__(col)
|
||||||
self._columns = dict(
|
self._columns = dict(((c.key, c) for c in self.col.all_browser_card_columns()))
|
||||||
((c[0], Column(*c)) for c in self.col.all_browser_card_columns())
|
|
||||||
)
|
|
||||||
self._active_columns = self.col.load_browser_card_columns()
|
self._active_columns = self.col.load_browser_card_columns()
|
||||||
self._sort_column = self.col.get_config("sortType")
|
self._sort_column = self.col.get_config("sortType")
|
||||||
self._sort_backwards = self.col.get_config_bool(
|
self._sort_backwards = self.col.get_config_bool(
|
||||||
@ -698,9 +698,7 @@ class CardState(ItemState):
|
|||||||
class NoteState(ItemState):
|
class NoteState(ItemState):
|
||||||
def __init__(self, col: Collection) -> None:
|
def __init__(self, col: Collection) -> None:
|
||||||
super().__init__(col)
|
super().__init__(col)
|
||||||
self._columns = dict(
|
self._columns = dict(((c.key, c) for c in self.col.all_browser_note_columns()))
|
||||||
((c[0], Column(*c)) for c in self.col.all_browser_note_columns())
|
|
||||||
)
|
|
||||||
self._active_columns = self.col.load_browser_note_columns()
|
self._active_columns = self.col.load_browser_note_columns()
|
||||||
self._sort_column = self.col.get_config("noteSortType")
|
self._sort_column = self.col.get_config("noteSortType")
|
||||||
self._sort_backwards = self.col.get_config_bool(
|
self._sort_backwards = self.col.get_config_bool(
|
||||||
@ -769,16 +767,6 @@ class NoteState(ItemState):
|
|||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class Column:
|
|
||||||
key: str
|
|
||||||
label: str = field(default_factory=tr.browsing_addon)
|
|
||||||
is_sortable: bool = False
|
|
||||||
sorts_reversed: bool = False
|
|
||||||
uses_cell_font: bool = False
|
|
||||||
aligns_centered: bool = True
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Cell:
|
class Cell:
|
||||||
text: str
|
text: str
|
||||||
@ -1097,3 +1085,17 @@ class StatusDelegate(QItemDelegate):
|
|||||||
painter.fillRect(option.rect, brush)
|
painter.fillRect(option.rect, brush)
|
||||||
painter.restore()
|
painter.restore()
|
||||||
return QItemDelegate.paint(self, painter, option, index)
|
return QItemDelegate.paint(self, painter, option, index)
|
||||||
|
|
||||||
|
|
||||||
|
def addon_column_fillin(key: str) -> Column:
|
||||||
|
"""Return a column with generic fields and a label indicating to the user that this column was
|
||||||
|
added by an add-on.
|
||||||
|
"""
|
||||||
|
return Column(
|
||||||
|
key=key,
|
||||||
|
label=tr.browsing_addon(),
|
||||||
|
is_sortable=False,
|
||||||
|
sorts_reversed=False,
|
||||||
|
uses_cell_font=False,
|
||||||
|
aligns_centered=True,
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user