0c340c4f74
* Prevent multiple inclusion of variables in CSS files * Use dict instead of tuple for variables * Add comments to variables * Improve appearance of main window * Tweak main window styles * Use json.dumps over pprint.format * Make study button primary * Improve header margin * Make bottom toolbar slimmer * Make congrats page more balanced * Fix type issue * Replace day/night with light/dark * Exclude top-level-drag-row from hover effect * Create dataclass for variables * Run formatter * Apply CSS variables from Python side Why go full-circle with the Sass variables? This way we only need one interface for add-on authors to interact with. It also makes it easier for us to apply additional themes in the future. * Fix typing * Fix rgba values in Qt * Darken button background * Fix palette not being applied in light theme For some odd reason this problem arose much later than #2016. * Tweak default button look * Reformat * Apply CSS vars to ts pages * Include elevation in button_mixins_lib * Cast opacity to int * Add some margin to studiedToday info * Tweak light theme button gradient * Tweak highlight-bg for light theme * Add back default button color as it made the browser sidebar tool icons dark in light theme. * Reformat * Tweak light theme buttons once more Sorry for the back-and-forth. Sass only compiles when there are changes in user files, not when I only change the vars. * Fix bottom toolbar button indicators * Make buttons more clicky * Fix button padding * Handle macOS separately again * Decrease elevation effect for main window buttons to 1 * Imitate box-shadow for Qt elements * Adjust shadow vars * Adjust primary border color because the save button in the deck options had a lighter color than its background gradient. * Boost box-shadow color of primary buttons * Format * Adjust Qt box-shadow imitation and shadow colors * Use more subtle default shadow color * Add some more padding to top toolbar * Revert "Apply CSS vars to ts pages" This reverts commit 5d8e7f6b7ffc8894b6517ecbb8cfba35407fc69a. * Revert "Apply CSS variables from Python side" This reverts commit 87db774412fd2bfd75e2630d2c5e782daef96b5f. * Better match the standard macOS buttons In the dark theme the standard color is a lighter grey, but at least the size/shape is similar again. This doesn't work for the editor buttons. * Reduce the top margin of the congrats screen * Fix illegible buttons when changing theme on macOS; match dark button style
116 lines
3.3 KiB
Python
116 lines
3.3 KiB
Python
# Copyright: Ankitects Pty Ltd and contributors
|
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
from __future__ import annotations
|
|
|
|
import time
|
|
from dataclasses import dataclass
|
|
from typing import TYPE_CHECKING, Generator, Sequence, Union
|
|
|
|
import aqt
|
|
import aqt.browser
|
|
from anki.cards import CardId
|
|
from anki.collection import BrowserColumns as Columns
|
|
from anki.collection import BrowserRow
|
|
from anki.notes import NoteId
|
|
from aqt import colors
|
|
from aqt.qt import QColor
|
|
from aqt.utils import tr
|
|
|
|
Column = Columns.Column
|
|
ItemId = Union[CardId, NoteId]
|
|
ItemList = Union[Sequence[CardId], Sequence[NoteId]]
|
|
|
|
|
|
@dataclass
|
|
class SearchContext:
|
|
search: str
|
|
browser: aqt.browser.Browser
|
|
order: bool | str | Column = True
|
|
reverse: bool = False
|
|
# if set, provided ids will be used instead of the regular search
|
|
ids: Sequence[ItemId] | None = None
|
|
|
|
|
|
@dataclass
|
|
class Cell:
|
|
text: str
|
|
is_rtl: bool
|
|
|
|
|
|
class CellRow:
|
|
is_disabled: bool = False
|
|
|
|
def __init__(
|
|
self,
|
|
cells: Generator[tuple[str, bool], None, None],
|
|
color: BrowserRow.Color.V,
|
|
font_name: str,
|
|
font_size: int,
|
|
) -> None:
|
|
self.refreshed_at: float = time.time()
|
|
self.cells: tuple[Cell, ...] = tuple(Cell(*cell) for cell in cells)
|
|
self.color: dict[str, str] | None = backend_color_to_aqt_color(color)
|
|
self.font_name: str = font_name or "arial"
|
|
self.font_size: int = font_size if font_size > 0 else 12
|
|
|
|
def is_stale(self, threshold: float) -> bool:
|
|
return self.refreshed_at < threshold
|
|
|
|
@staticmethod
|
|
def generic(length: int, cell_text: str) -> CellRow:
|
|
return CellRow(
|
|
((cell_text, False) for cell in range(length)),
|
|
BrowserRow.COLOR_DEFAULT,
|
|
"arial",
|
|
12,
|
|
)
|
|
|
|
@staticmethod
|
|
def placeholder(length: int) -> CellRow:
|
|
return CellRow.generic(length, "...")
|
|
|
|
@staticmethod
|
|
def disabled(length: int, cell_text: str) -> CellRow:
|
|
row = CellRow.generic(length, cell_text)
|
|
row.is_disabled = True
|
|
return row
|
|
|
|
|
|
def backend_color_to_aqt_color(color: BrowserRow.Color.V) -> dict[str, str] | None:
|
|
temp_color = None
|
|
|
|
if color == BrowserRow.COLOR_MARKED:
|
|
temp_color = colors.STATE_MARKED
|
|
if color == BrowserRow.COLOR_SUSPENDED:
|
|
temp_color = colors.STATE_SUSPENDED
|
|
if color == BrowserRow.COLOR_FLAG_RED:
|
|
temp_color = colors.FLAG_1
|
|
if color == BrowserRow.COLOR_FLAG_ORANGE:
|
|
temp_color = colors.FLAG_2
|
|
if color == BrowserRow.COLOR_FLAG_GREEN:
|
|
temp_color = colors.FLAG_3
|
|
if color == BrowserRow.COLOR_FLAG_BLUE:
|
|
temp_color = colors.FLAG_4
|
|
if color == BrowserRow.COLOR_FLAG_PINK:
|
|
temp_color = colors.FLAG_5
|
|
if color == BrowserRow.COLOR_FLAG_TURQUOISE:
|
|
temp_color = colors.FLAG_6
|
|
if color == BrowserRow.COLOR_FLAG_PURPLE:
|
|
temp_color = colors.FLAG_7
|
|
|
|
return adjusted_bg_color(temp_color)
|
|
|
|
|
|
def adjusted_bg_color(color: dict[str, str]) -> dict[str, str]:
|
|
if color:
|
|
color["light"] = QColor(color["light"]).lighter(150).name()
|
|
color["dark"] = QColor(color["dark"]).darker(150).name()
|
|
return color
|
|
else:
|
|
return None
|
|
|
|
|
|
from .model import DataModel
|
|
from .state import CardState, ItemState, NoteState
|
|
from .table import StatusDelegate, Table
|