mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
Move flags into separate module
This commit is contained in:
parent
422584b814
commit
5a6ba1b0b9
5 changed files with 74 additions and 67 deletions
|
@ -18,6 +18,7 @@ from anki.utils import ids2str, isMac
|
||||||
from aqt import AnkiQt, gui_hooks
|
from aqt import AnkiQt, gui_hooks
|
||||||
from aqt.editor import Editor
|
from aqt.editor import Editor
|
||||||
from aqt.exporting import ExportDialog
|
from aqt.exporting import ExportDialog
|
||||||
|
from aqt.flags import load_flags
|
||||||
from aqt.operations.card import set_card_deck, set_card_flag
|
from aqt.operations.card import set_card_deck, set_card_flag
|
||||||
from aqt.operations.collection import redo, undo
|
from aqt.operations.collection import redo, undo
|
||||||
from aqt.operations.note import remove_notes
|
from aqt.operations.note import remove_notes
|
||||||
|
@ -42,7 +43,6 @@ from aqt.utils import (
|
||||||
current_top_level_widget,
|
current_top_level_widget,
|
||||||
ensure_editor_saved,
|
ensure_editor_saved,
|
||||||
getTag,
|
getTag,
|
||||||
load_flags,
|
|
||||||
no_arg_trigger,
|
no_arg_trigger,
|
||||||
openHelp,
|
openHelp,
|
||||||
qtMenuShortcutWorkaround,
|
qtMenuShortcutWorkaround,
|
||||||
|
|
|
@ -19,6 +19,7 @@ from aqt.browser.sidebar.model import SidebarModel
|
||||||
from aqt.browser.sidebar.searchbar import SidebarSearchBar
|
from aqt.browser.sidebar.searchbar import SidebarSearchBar
|
||||||
from aqt.browser.sidebar.toolbar import SidebarTool, SidebarToolbar
|
from aqt.browser.sidebar.toolbar import SidebarTool, SidebarToolbar
|
||||||
from aqt.clayout import CardLayout
|
from aqt.clayout import CardLayout
|
||||||
|
from aqt.flags import load_flags
|
||||||
from aqt.models import Models
|
from aqt.models import Models
|
||||||
from aqt.operations import QueryOp
|
from aqt.operations import QueryOp
|
||||||
from aqt.operations.deck import (
|
from aqt.operations.deck import (
|
||||||
|
@ -35,14 +36,7 @@ from aqt.operations.tag import (
|
||||||
)
|
)
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
from aqt.theme import ColoredIcon, theme_manager
|
from aqt.theme import ColoredIcon, theme_manager
|
||||||
from aqt.utils import (
|
from aqt.utils import KeyboardModifiersPressed, askUser, getOnlyText, showWarning, tr
|
||||||
KeyboardModifiersPressed,
|
|
||||||
askUser,
|
|
||||||
getOnlyText,
|
|
||||||
load_flags,
|
|
||||||
showWarning,
|
|
||||||
tr,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class SidebarStage(Enum):
|
class SidebarStage(Enum):
|
||||||
|
|
68
qt/aqt/flags.py
Normal file
68
qt/aqt/flags.py
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
# Copyright: Ankitects Pty Ltd and contributors
|
||||||
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from dataclasses import dataclass
|
||||||
|
from typing import Dict, List, cast
|
||||||
|
|
||||||
|
from anki import Collection
|
||||||
|
from anki.collection import SearchNode
|
||||||
|
from aqt import colors
|
||||||
|
from aqt.theme import ColoredIcon
|
||||||
|
from aqt.utils import tr
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class Flag:
|
||||||
|
"""A container class for flag related data.
|
||||||
|
|
||||||
|
index -- The integer by which the flag is represented internally (1-7).
|
||||||
|
label -- The text by which the flag is described in the GUI.
|
||||||
|
icon -- The icon by which the flag is represented in the GUI.
|
||||||
|
search_node -- The node to build a search string for finding cards with the flag.
|
||||||
|
action -- The name of the action to assign the flag in the browser form.
|
||||||
|
"""
|
||||||
|
|
||||||
|
index: int
|
||||||
|
label: str
|
||||||
|
icon: ColoredIcon
|
||||||
|
search_node: SearchNode
|
||||||
|
action: str
|
||||||
|
|
||||||
|
|
||||||
|
def load_flags(col: Collection) -> List[Flag]:
|
||||||
|
"""Return a list of all flags, reloading labels from the config."""
|
||||||
|
|
||||||
|
labels = cast(Dict[str, str], col.get_config("flagLabels", {}))
|
||||||
|
icon = ColoredIcon(path=":/icons/flag.svg", color=colors.DISABLED)
|
||||||
|
|
||||||
|
return [
|
||||||
|
Flag(
|
||||||
|
1,
|
||||||
|
labels["1"] if "1" in labels else tr.actions_red_flag(),
|
||||||
|
icon.with_color(colors.FLAG1_FG),
|
||||||
|
SearchNode(flag=SearchNode.FLAG_RED),
|
||||||
|
"actionRed_Flag",
|
||||||
|
),
|
||||||
|
Flag(
|
||||||
|
2,
|
||||||
|
labels["2"] if "2" in labels else tr.actions_orange_flag(),
|
||||||
|
icon.with_color(colors.FLAG2_FG),
|
||||||
|
SearchNode(flag=SearchNode.FLAG_ORANGE),
|
||||||
|
"actionOrange_Flag",
|
||||||
|
),
|
||||||
|
Flag(
|
||||||
|
3,
|
||||||
|
labels["3"] if "3" in labels else tr.actions_green_flag(),
|
||||||
|
icon.with_color(colors.FLAG3_FG),
|
||||||
|
SearchNode(flag=SearchNode.FLAG_GREEN),
|
||||||
|
"actionGreen_Flag",
|
||||||
|
),
|
||||||
|
Flag(
|
||||||
|
4,
|
||||||
|
labels["4"] if "4" in labels else tr.actions_blue_flag(),
|
||||||
|
icon.with_color(colors.FLAG4_FG),
|
||||||
|
SearchNode(flag=SearchNode.FLAG_BLUE),
|
||||||
|
"actionBlue_Flag",
|
||||||
|
),
|
||||||
|
]
|
|
@ -35,6 +35,7 @@ from anki.scheduler.v3 import Scheduler as V3Scheduler
|
||||||
from anki.tags import MARKED_TAG
|
from anki.tags import MARKED_TAG
|
||||||
from anki.utils import stripHTML
|
from anki.utils import stripHTML
|
||||||
from aqt import AnkiQt, gui_hooks
|
from aqt import AnkiQt, gui_hooks
|
||||||
|
from aqt.flags import load_flags
|
||||||
from aqt.operations.card import set_card_flag
|
from aqt.operations.card import set_card_flag
|
||||||
from aqt.operations.note import remove_notes
|
from aqt.operations.note import remove_notes
|
||||||
from aqt.operations.scheduling import (
|
from aqt.operations.scheduling import (
|
||||||
|
@ -51,14 +52,7 @@ from aqt.qt import *
|
||||||
from aqt.sound import av_player, play_clicked_audio, record_audio
|
from aqt.sound import av_player, play_clicked_audio, record_audio
|
||||||
from aqt.theme import theme_manager
|
from aqt.theme import theme_manager
|
||||||
from aqt.toolbar import BottomBar
|
from aqt.toolbar import BottomBar
|
||||||
from aqt.utils import (
|
from aqt.utils import askUserDialog, downArrow, qtMenuShortcutWorkaround, tooltip, tr
|
||||||
askUserDialog,
|
|
||||||
downArrow,
|
|
||||||
load_flags,
|
|
||||||
qtMenuShortcutWorkaround,
|
|
||||||
tooltip,
|
|
||||||
tr,
|
|
||||||
)
|
|
||||||
from aqt.webview import AnkiWebView
|
from aqt.webview import AnkiWebView
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,14 +6,12 @@ import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
from dataclasses import dataclass
|
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from typing import (
|
from typing import (
|
||||||
TYPE_CHECKING,
|
TYPE_CHECKING,
|
||||||
Any,
|
Any,
|
||||||
Callable,
|
Callable,
|
||||||
Dict,
|
|
||||||
List,
|
List,
|
||||||
Literal,
|
Literal,
|
||||||
Optional,
|
Optional,
|
||||||
|
@ -37,12 +35,10 @@ from PyQt5.QtWidgets import (
|
||||||
|
|
||||||
import aqt
|
import aqt
|
||||||
from anki import Collection
|
from anki import Collection
|
||||||
from anki.collection import SearchNode
|
|
||||||
from anki.lang import TR, tr_legacyglobal # pylint: disable=unused-import
|
from anki.lang import TR, tr_legacyglobal # pylint: disable=unused-import
|
||||||
from anki.utils import invalidFilename, isMac, isWin, noBundledLibs, versionWithBuild
|
from anki.utils import invalidFilename, isMac, isWin, noBundledLibs, versionWithBuild
|
||||||
from aqt import colors
|
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
from aqt.theme import ColoredIcon, theme_manager
|
from aqt.theme import theme_manager
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
TextFormat = Union[Literal["plain", "rich"]]
|
TextFormat = Union[Literal["plain", "rich"]]
|
||||||
|
@ -1027,51 +1023,6 @@ def no_arg_trigger(func: Callable) -> Callable:
|
||||||
return pyqtSlot()(func) # type: ignore
|
return pyqtSlot()(func) # type: ignore
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class Flag:
|
|
||||||
index: int
|
|
||||||
label: str
|
|
||||||
icon: ColoredIcon
|
|
||||||
search_node: SearchNode
|
|
||||||
action: str
|
|
||||||
|
|
||||||
|
|
||||||
def load_flags(col: Collection) -> List[Flag]:
|
|
||||||
labels = cast(Dict[str, str], col.get_config("flagLabels", {}))
|
|
||||||
icon = ColoredIcon(path=":/icons/flag.svg", color=colors.DISABLED)
|
|
||||||
|
|
||||||
return [
|
|
||||||
Flag(
|
|
||||||
1,
|
|
||||||
labels["1"] if "1" in labels else tr.actions_red_flag(),
|
|
||||||
icon.with_color(colors.FLAG1_FG),
|
|
||||||
SearchNode(flag=SearchNode.FLAG_RED),
|
|
||||||
"actionRed_Flag",
|
|
||||||
),
|
|
||||||
Flag(
|
|
||||||
2,
|
|
||||||
labels["2"] if "2" in labels else tr.actions_orange_flag(),
|
|
||||||
icon.with_color(colors.FLAG2_FG),
|
|
||||||
SearchNode(flag=SearchNode.FLAG_ORANGE),
|
|
||||||
"actionOrange_Flag",
|
|
||||||
),
|
|
||||||
Flag(
|
|
||||||
3,
|
|
||||||
labels["3"] if "3" in labels else tr.actions_green_flag(),
|
|
||||||
icon.with_color(colors.FLAG3_FG),
|
|
||||||
SearchNode(flag=SearchNode.FLAG_GREEN),
|
|
||||||
"actionGreen_Flag",
|
|
||||||
),
|
|
||||||
Flag(
|
|
||||||
4,
|
|
||||||
labels["4"] if "4" in labels else tr.actions_blue_flag(),
|
|
||||||
icon.with_color(colors.FLAG4_FG),
|
|
||||||
SearchNode(flag=SearchNode.FLAG_BLUE),
|
|
||||||
"actionBlue_Flag",
|
|
||||||
),
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class KeyboardModifiersPressed:
|
class KeyboardModifiersPressed:
|
||||||
"Util for type-safe checks of currently-pressed modifier keys."
|
"Util for type-safe checks of currently-pressed modifier keys."
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue