Fix typing

This commit is contained in:
Matthias Metelka 2022-10-23 13:02:15 +02:00
parent 87db774412
commit caba214d6a
3 changed files with 12 additions and 20 deletions

View file

@ -14,7 +14,6 @@ from anki.collection import BrowserRow
from anki.notes import NoteId
from aqt import colors
from aqt.qt import QColor
from aqt.theme import AnkiVariable
from aqt.utils import tr
Column = Columns.Column
@ -50,7 +49,7 @@ class CellRow:
) -> None:
self.refreshed_at: float = time.time()
self.cells: tuple[Cell, ...] = tuple(Cell(*cell) for cell in cells)
self.color: AnkiVariable | None = backend_color_to_aqt_color(color)
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
@ -77,7 +76,7 @@ class CellRow:
return row
def backend_color_to_aqt_color(color: BrowserRow.Color.V) -> AnkiVariable | None:
def backend_color_to_aqt_color(color: BrowserRow.Color.V) -> dict[str, str] | None:
temp_color = None
if color == BrowserRow.COLOR_MARKED:
@ -102,10 +101,10 @@ def backend_color_to_aqt_color(color: BrowserRow.Color.V) -> AnkiVariable | None
return adjusted_bg_color(temp_color)
def adjusted_bg_color(color: AnkiVariable) -> AnkiVariable:
def adjusted_bg_color(color: dict[str, str]) -> dict[str, str]:
if color:
color.light = color.light.lighter(150).name()
color.dark = color.dark.darker(150).name()
color["light"] = QColor(color["light"]).lighter(150).name()
color["dark"] = QColor(color["dark"]).darker(150).name()
return color
else:
return None

View file

@ -4,7 +4,7 @@ from typing import cast
from aqt import colors
from aqt.qt import *
from aqt.theme import AnkiVariable, theme_manager
from aqt.theme import theme_manager
class Switch(QAbstractButton):
@ -19,8 +19,8 @@ class Switch(QAbstractButton):
radius: int = 10,
left_label: str = "",
right_label: str = "",
left_color: AnkiVariable = colors.ACCENT_CARD,
right_color: AnkiVariable = colors.ACCENT_NOTE,
left_color: dict[str, str] = colors.ACCENT_CARD | {},
right_color: dict[str, str] = colors.ACCENT_NOTE | {},
parent: QWidget = None,
) -> None:
super().__init__(parent=parent)

View file

@ -27,17 +27,10 @@ from aqt.qt import (
)
@dataclass
class AnkiVariable:
light: str
dark: str
comment: str
@dataclass
class ColoredIcon:
path: str
color: AnkiVariable
color: dict[str, str]
def current_color(self, night_mode: bool) -> str:
if night_mode:
@ -45,7 +38,7 @@ class ColoredIcon:
else:
return self.color.get("light", "")
def with_color(self, color: AnkiVariable) -> ColoredIcon:
def with_color(self, color: dict[str, str]) -> ColoredIcon:
return ColoredIcon(path=self.path, color=color)
@ -183,11 +176,11 @@ class ThemeManager:
"Returns body classes used when showing a card."
return f"card card{card_ord+1} {self.body_class(night_mode)}"
def var(self, vars: AnkiVariable) -> str:
def var(self, vars: dict[str, str]) -> str:
"""Given day/night colors/props, return the correct one for the current theme."""
return vars["dark" if self.night_mode else "light"]
def qcolor(self, colors: AnkiVariable) -> QColor:
def qcolor(self, colors: dict[str, str]) -> QColor:
return QColor(self.var(colors))
def _determine_night_mode(self) -> bool: