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
|
||||
DefaultsForAdding = _pb.DeckAndNotetype
|
||||
BrowserRow = _pb.BrowserRow
|
||||
BrowserColumns = _pb.BrowserColumns
|
||||
|
||||
import copy
|
||||
import os
|
||||
@ -696,15 +697,11 @@ class Collection:
|
||||
# Browser Table
|
||||
##########################################################################
|
||||
|
||||
def all_browser_card_columns(
|
||||
self,
|
||||
) -> 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_card_columns(self) -> Sequence[BrowserColumns.Column]:
|
||||
return self._backend.all_browser_card_columns()
|
||||
|
||||
def all_browser_note_columns(
|
||||
self,
|
||||
) -> Generator[Tuple[str, str, bool, bool, bool, bool], None, None]:
|
||||
return (_column_data(c) for c in self._backend.all_browser_note_columns())
|
||||
def all_browser_note_columns(self) -> Sequence[BrowserColumns.Column]:
|
||||
return self._backend.all_browser_note_columns()
|
||||
|
||||
def browser_row_for_id(
|
||||
self, id_: int
|
||||
@ -1141,16 +1138,3 @@ def _build_sort_mode(
|
||||
return _pb.SortOrder(none=_pb.Empty())
|
||||
else:
|
||||
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
|
||||
from abc import ABC, abstractmethod, abstractproperty
|
||||
from dataclasses import dataclass, field
|
||||
from dataclasses import dataclass
|
||||
from typing import (
|
||||
Any,
|
||||
Callable,
|
||||
@ -22,6 +22,7 @@ from typing import (
|
||||
import aqt
|
||||
import aqt.forms
|
||||
from anki.cards import Card, CardId
|
||||
from anki.collection import BrowserColumns as Columns
|
||||
from anki.collection import BrowserRow, Collection, Config, OpChanges
|
||||
from anki.consts import *
|
||||
from anki.errors import NotFoundError
|
||||
@ -39,6 +40,7 @@ from aqt.utils import (
|
||||
tr,
|
||||
)
|
||||
|
||||
Column = Columns.Column
|
||||
ItemId = Union[CardId, NoteId]
|
||||
ItemList = Union[Sequence[CardId], Sequence[NoteId]]
|
||||
|
||||
@ -551,7 +553,7 @@ class ItemState(ABC):
|
||||
try:
|
||||
return self._columns[key]
|
||||
except KeyError:
|
||||
self._columns[key] = Column(key)
|
||||
self._columns[key] = addon_column_fillin(key)
|
||||
return self._columns[key]
|
||||
|
||||
# Columns and sorting
|
||||
@ -628,9 +630,7 @@ class ItemState(ABC):
|
||||
class CardState(ItemState):
|
||||
def __init__(self, col: Collection) -> None:
|
||||
super().__init__(col)
|
||||
self._columns = dict(
|
||||
((c[0], Column(*c)) for c in self.col.all_browser_card_columns())
|
||||
)
|
||||
self._columns = dict(((c.key, c) for c in self.col.all_browser_card_columns()))
|
||||
self._active_columns = self.col.load_browser_card_columns()
|
||||
self._sort_column = self.col.get_config("sortType")
|
||||
self._sort_backwards = self.col.get_config_bool(
|
||||
@ -698,9 +698,7 @@ class CardState(ItemState):
|
||||
class NoteState(ItemState):
|
||||
def __init__(self, col: Collection) -> None:
|
||||
super().__init__(col)
|
||||
self._columns = dict(
|
||||
((c[0], Column(*c)) for c in self.col.all_browser_note_columns())
|
||||
)
|
||||
self._columns = dict(((c.key, c) for c in self.col.all_browser_note_columns()))
|
||||
self._active_columns = self.col.load_browser_note_columns()
|
||||
self._sort_column = self.col.get_config("noteSortType")
|
||||
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
|
||||
class Cell:
|
||||
text: str
|
||||
@ -1097,3 +1085,17 @@ class StatusDelegate(QItemDelegate):
|
||||
painter.fillRect(option.rect, brush)
|
||||
painter.restore()
|
||||
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