mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 06:52:21 -04:00
Fix typing
This commit is contained in:
parent
87db774412
commit
caba214d6a
3 changed files with 12 additions and 20 deletions
|
@ -14,7 +14,6 @@ from anki.collection import BrowserRow
|
||||||
from anki.notes import NoteId
|
from anki.notes import NoteId
|
||||||
from aqt import colors
|
from aqt import colors
|
||||||
from aqt.qt import QColor
|
from aqt.qt import QColor
|
||||||
from aqt.theme import AnkiVariable
|
|
||||||
from aqt.utils import tr
|
from aqt.utils import tr
|
||||||
|
|
||||||
Column = Columns.Column
|
Column = Columns.Column
|
||||||
|
@ -50,7 +49,7 @@ class CellRow:
|
||||||
) -> None:
|
) -> None:
|
||||||
self.refreshed_at: float = time.time()
|
self.refreshed_at: float = time.time()
|
||||||
self.cells: tuple[Cell, ...] = tuple(Cell(*cell) for cell in cells)
|
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_name: str = font_name or "arial"
|
||||||
self.font_size: int = font_size if font_size > 0 else 12
|
self.font_size: int = font_size if font_size > 0 else 12
|
||||||
|
|
||||||
|
@ -77,7 +76,7 @@ class CellRow:
|
||||||
return row
|
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
|
temp_color = None
|
||||||
|
|
||||||
if color == BrowserRow.COLOR_MARKED:
|
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)
|
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:
|
if color:
|
||||||
color.light = color.light.lighter(150).name()
|
color["light"] = QColor(color["light"]).lighter(150).name()
|
||||||
color.dark = color.dark.darker(150).name()
|
color["dark"] = QColor(color["dark"]).darker(150).name()
|
||||||
return color
|
return color
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -4,7 +4,7 @@ from typing import cast
|
||||||
|
|
||||||
from aqt import colors
|
from aqt import colors
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
from aqt.theme import AnkiVariable, theme_manager
|
from aqt.theme import theme_manager
|
||||||
|
|
||||||
|
|
||||||
class Switch(QAbstractButton):
|
class Switch(QAbstractButton):
|
||||||
|
@ -19,8 +19,8 @@ class Switch(QAbstractButton):
|
||||||
radius: int = 10,
|
radius: int = 10,
|
||||||
left_label: str = "",
|
left_label: str = "",
|
||||||
right_label: str = "",
|
right_label: str = "",
|
||||||
left_color: AnkiVariable = colors.ACCENT_CARD,
|
left_color: dict[str, str] = colors.ACCENT_CARD | {},
|
||||||
right_color: AnkiVariable = colors.ACCENT_NOTE,
|
right_color: dict[str, str] = colors.ACCENT_NOTE | {},
|
||||||
parent: QWidget = None,
|
parent: QWidget = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
super().__init__(parent=parent)
|
super().__init__(parent=parent)
|
||||||
|
|
|
@ -27,17 +27,10 @@ from aqt.qt import (
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class AnkiVariable:
|
|
||||||
light: str
|
|
||||||
dark: str
|
|
||||||
comment: str
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ColoredIcon:
|
class ColoredIcon:
|
||||||
path: str
|
path: str
|
||||||
color: AnkiVariable
|
color: dict[str, str]
|
||||||
|
|
||||||
def current_color(self, night_mode: bool) -> str:
|
def current_color(self, night_mode: bool) -> str:
|
||||||
if night_mode:
|
if night_mode:
|
||||||
|
@ -45,7 +38,7 @@ class ColoredIcon:
|
||||||
else:
|
else:
|
||||||
return self.color.get("light", "")
|
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)
|
return ColoredIcon(path=self.path, color=color)
|
||||||
|
|
||||||
|
|
||||||
|
@ -183,11 +176,11 @@ class ThemeManager:
|
||||||
"Returns body classes used when showing a card."
|
"Returns body classes used when showing a card."
|
||||||
return f"card card{card_ord+1} {self.body_class(night_mode)}"
|
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."""
|
"""Given day/night colors/props, return the correct one for the current theme."""
|
||||||
return vars["dark" if self.night_mode else "light"]
|
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))
|
return QColor(self.var(colors))
|
||||||
|
|
||||||
def _determine_night_mode(self) -> bool:
|
def _determine_night_mode(self) -> bool:
|
||||||
|
|
Loading…
Reference in a new issue