mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
use constants for other color references
str_color/qcolor() doesn't appear to have been used by any add-ons except one of mine, so changing the signature should be safe
This commit is contained in:
parent
b8d67cdad5
commit
bb30e8f7bc
6 changed files with 32 additions and 41 deletions
|
@ -21,7 +21,7 @@ from anki.models import NoteType
|
|||
from anki.notes import Note
|
||||
from anki.stats import CardStats
|
||||
from anki.utils import htmlToTextLine, ids2str, isMac, isWin
|
||||
from aqt import AnkiQt, gui_hooks
|
||||
from aqt import AnkiQt, colors, gui_hooks
|
||||
from aqt.editor import Editor
|
||||
from aqt.exporting import ExportDialog
|
||||
from aqt.main import ResetReason
|
||||
|
@ -412,13 +412,13 @@ class StatusDelegate(QItemDelegate):
|
|||
|
||||
col = None
|
||||
if c.userFlag() > 0:
|
||||
col = theme_manager.qcolor(f"flag{c.userFlag()}-bg")
|
||||
col = getattr(colors, f"FLAG{c.userFlag()}_BG")
|
||||
elif c.note().hasTag("Marked"):
|
||||
col = theme_manager.qcolor("marked-bg")
|
||||
col = colors.MARKED_BG
|
||||
elif c.queue == QUEUE_TYPE_SUSPENDED:
|
||||
col = theme_manager.qcolor("suspended-bg")
|
||||
col = colors.SUSPENDED_BG
|
||||
if col:
|
||||
brush = QBrush(col)
|
||||
brush = QBrush(theme_manager.qcolor(col))
|
||||
painter.save()
|
||||
painter.fillRect(option.rect, brush)
|
||||
painter.restore()
|
||||
|
@ -744,7 +744,7 @@ class Browser(QMainWindow):
|
|||
"selection-color: black; }"
|
||||
)
|
||||
elif theme_manager.macos_dark_mode():
|
||||
grid = theme_manager.str_color("frame-bg")
|
||||
grid = colors.FRAME_BG
|
||||
self.form.tableView.setStyleSheet(
|
||||
f"""
|
||||
QTableView {{ gridline-color: {grid} }}
|
||||
|
|
|
@ -8,7 +8,7 @@ from anki.collection import SearchTerm
|
|||
from anki.decks import Deck, DeckRenameError
|
||||
from anki.errors import InvalidInput
|
||||
from anki.lang import without_unicode_isolation
|
||||
from aqt import AnkiQt, gui_hooks
|
||||
from aqt import AnkiQt, colors, gui_hooks
|
||||
from aqt.qt import *
|
||||
from aqt.theme import theme_manager
|
||||
from aqt.utils import (
|
||||
|
@ -70,7 +70,7 @@ class DeckConf(QDialog):
|
|||
self.set_custom_searches(search, search_2)
|
||||
qconnect(self.form.search_button.clicked, self.on_search_button)
|
||||
qconnect(self.form.search_button_2.clicked, self.on_search_button_2)
|
||||
color = theme_manager.str_color("link")
|
||||
color = theme_manager.color(colors.LINK)
|
||||
self.setStyleSheet(
|
||||
f"""QPushButton[flat=true] {{ text-align: left; color: {color}; padding: 0; border: 0 }}
|
||||
QPushButton[flat=true]:hover {{ text-decoration: underline }}"""
|
||||
|
|
|
@ -27,7 +27,7 @@ from anki.hooks import runFilter
|
|||
from anki.httpclient import HttpClient
|
||||
from anki.notes import Note
|
||||
from anki.utils import checksum, isLin, isWin, namedtmp
|
||||
from aqt import AnkiQt, gui_hooks
|
||||
from aqt import AnkiQt, colors, gui_hooks
|
||||
from aqt.main import ResetReason
|
||||
from aqt.qt import *
|
||||
from aqt.sound import av_player
|
||||
|
@ -629,7 +629,7 @@ class Editor:
|
|||
self.tags.setToolTip(
|
||||
shortcut(tr(TR.EDITING_JUMP_TO_TAGS_WITH_CTRLANDSHIFTANDT))
|
||||
)
|
||||
border = theme_manager.str_color("border")
|
||||
border = theme_manager.color(colors.BORDER)
|
||||
self.tags.setStyleSheet(f"border: 1px solid {border}")
|
||||
tb.addWidget(self.tags, 1, 1)
|
||||
g.setLayout(tb)
|
||||
|
|
|
@ -372,7 +372,7 @@ class SidebarTreeView(QTreeView):
|
|||
) -> None:
|
||||
if self.current_search and (item := self.model().item_for_index(idx)):
|
||||
if item.is_highlighted():
|
||||
brush = QBrush(theme_manager.qcolor("suspended-bg"))
|
||||
brush = QBrush(theme_manager.qcolor(colors.SUSPENDED_BG))
|
||||
painter.save()
|
||||
painter.fillRect(options.rect, brush)
|
||||
painter.restore()
|
||||
|
|
|
@ -121,22 +121,13 @@ class ThemeManager:
|
|||
"Returns body classes used when showing a card."
|
||||
return f"card card{card_ord+1} {self.body_class(night_mode)}"
|
||||
|
||||
def str_color(self, key: str) -> str:
|
||||
"""Get a color defined in _vars.scss
|
||||
|
||||
If the colour is called '--frame-bg', key should be
|
||||
'frame-bg'.
|
||||
|
||||
Returns the color as a string hex code or color name."""
|
||||
def color(self, colors: Tuple[str, str]) -> str:
|
||||
"""Given day/night colors, return the correct one for the current theme."""
|
||||
idx = 1 if self.night_mode else 0
|
||||
return colors[idx]
|
||||
|
||||
key = key.replace("-", "_").upper()
|
||||
|
||||
return getattr(colors, key)[idx]
|
||||
|
||||
def qcolor(self, key: str) -> QColor:
|
||||
"""Get a color defined in _vars.scss as a QColor."""
|
||||
return QColor(self.str_color(key))
|
||||
def qcolor(self, colors: Tuple[str, str]) -> QColor:
|
||||
return QColor(self.color(colors))
|
||||
|
||||
def apply_style(self, app: QApplication) -> None:
|
||||
self._apply_palette(app)
|
||||
|
@ -191,10 +182,10 @@ QScrollBar::sub-line {
|
|||
|
||||
QTabWidget { background-color: %s; }
|
||||
""" % (
|
||||
self.str_color("window-bg"),
|
||||
self.color(colors.WINDOW_BG),
|
||||
# fushion-button-hover-bg
|
||||
"#656565",
|
||||
self.str_color("window-bg"),
|
||||
self.color(colors.WINDOW_BG),
|
||||
)
|
||||
|
||||
# allow addons to modify the styling
|
||||
|
@ -211,33 +202,33 @@ QTabWidget { background-color: %s; }
|
|||
|
||||
palette = QPalette()
|
||||
|
||||
text_fg = self.qcolor("text-fg")
|
||||
text_fg = self.qcolor(colors.TEXT_FG)
|
||||
palette.setColor(QPalette.WindowText, text_fg)
|
||||
palette.setColor(QPalette.ToolTipText, text_fg)
|
||||
palette.setColor(QPalette.Text, text_fg)
|
||||
palette.setColor(QPalette.ButtonText, text_fg)
|
||||
|
||||
hlbg = self.qcolor("highlight-bg")
|
||||
hlbg = self.qcolor(colors.HIGHLIGHT_BG)
|
||||
hlbg.setAlpha(64)
|
||||
palette.setColor(QPalette.HighlightedText, self.qcolor("highlight-fg"))
|
||||
palette.setColor(QPalette.HighlightedText, self.qcolor(colors.HIGHLIGHT_FG))
|
||||
palette.setColor(QPalette.Highlight, hlbg)
|
||||
|
||||
window_bg = self.qcolor("window-bg")
|
||||
window_bg = self.qcolor(colors.WINDOW_BG)
|
||||
palette.setColor(QPalette.Window, window_bg)
|
||||
palette.setColor(QPalette.AlternateBase, window_bg)
|
||||
|
||||
palette.setColor(QPalette.Button, QColor("#454545"))
|
||||
|
||||
frame_bg = self.qcolor("frame-bg")
|
||||
frame_bg = self.qcolor(colors.FRAME_BG)
|
||||
palette.setColor(QPalette.Base, frame_bg)
|
||||
palette.setColor(QPalette.ToolTipBase, frame_bg)
|
||||
|
||||
disabled_color = self.qcolor("disabled")
|
||||
disabled_color = self.qcolor(colors.DISABLED)
|
||||
palette.setColor(QPalette.Disabled, QPalette.Text, disabled_color)
|
||||
palette.setColor(QPalette.Disabled, QPalette.ButtonText, disabled_color)
|
||||
palette.setColor(QPalette.Disabled, QPalette.HighlightedText, disabled_color)
|
||||
|
||||
palette.setColor(QPalette.Link, self.qcolor("link"))
|
||||
palette.setColor(QPalette.Link, self.qcolor(colors.LINK))
|
||||
|
||||
palette.setColor(QPalette.BrightText, Qt.red)
|
||||
|
||||
|
@ -246,11 +237,11 @@ QTabWidget { background-color: %s; }
|
|||
def _update_stat_colors(self) -> None:
|
||||
import anki.stats as s
|
||||
|
||||
s.colLearn = self.str_color("new-count")
|
||||
s.colRelearn = self.str_color("learn-count")
|
||||
s.colCram = self.str_color("suspended-bg")
|
||||
s.colSusp = self.str_color("suspended-bg")
|
||||
s.colMature = self.str_color("review-count")
|
||||
s.colLearn = self.color(colors.NEW_COUNT)
|
||||
s.colRelearn = self.color(colors.LEARN_COUNT)
|
||||
s.colCram = self.color(colors.SUSPENDED_BG)
|
||||
s.colSusp = self.color(colors.SUSPENDED_BG)
|
||||
s.colMature = self.color(colors.REVIEW_COUNT)
|
||||
|
||||
|
||||
theme_manager = ThemeManager()
|
||||
|
|
|
@ -10,7 +10,7 @@ from typing import Any, Callable, List, Optional, Sequence, Tuple, cast
|
|||
import anki
|
||||
from anki.lang import is_rtl
|
||||
from anki.utils import isLin, isMac, isWin
|
||||
from aqt import gui_hooks
|
||||
from aqt import colors, gui_hooks
|
||||
from aqt.qt import *
|
||||
from aqt.theme import theme_manager
|
||||
from aqt.utils import TR, openLink, showInfo, tr
|
||||
|
@ -378,7 +378,7 @@ class AnkiWebView(QWebEngineView):
|
|||
|
||||
def _getWindowColor(self) -> QColor:
|
||||
if theme_manager.night_mode:
|
||||
return theme_manager.qcolor("window-bg")
|
||||
return theme_manager.qcolor(colors.WINDOW_BG)
|
||||
if isMac:
|
||||
# standard palette does not return correct window color on macOS
|
||||
return QColor("#ececec")
|
||||
|
|
Loading…
Reference in a new issue