Switch frontend to use backend links

This commit is contained in:
RumovZ 2021-07-22 10:07:13 +02:00
parent 55e1f178ef
commit d8d69a3810
5 changed files with 14 additions and 34 deletions

View file

@ -6,6 +6,7 @@ persistent = no
ignored-classes=
BrowserColumns,
BrowserRow,
HelpPage,
FormatTimespanRequest,
CardAnswer,
QueuedCards,

View file

@ -14,6 +14,7 @@ import anki.cards_pb2
import anki.collection_pb2
import anki.decks_pb2
import anki.deckconfig_pb2
import anki.links_pb2
import anki.notes_pb2
import anki.notetypes_pb2
import anki.scheduler_pb2
@ -195,6 +196,7 @@ service_modules = dict(
CARD_RENDERING=anki.card_rendering_pb2,
TAGS=anki.tags_pb2,
MEDIA=anki.media_pb2,
LINKS=anki.links_pb2,
)
for service in anki.backend_pb2.ServiceIndex.DESCRIPTOR.values:
@ -236,6 +238,7 @@ import anki.cards_pb2
import anki.collection_pb2
import anki.decks_pb2
import anki.deckconfig_pb2
import anki.links_pb2
import anki.notes_pb2
import anki.notetypes_pb2
import anki.scheduler_pb2

View file

@ -12,12 +12,14 @@ from anki import (
collection_pb2,
config_pb2,
generic_pb2,
links_pb2,
search_pb2,
stats_pb2,
)
from anki._legacy import DeprecatedNamesMixin, deprecated
# protobuf we publicly export - listed first to avoid circular imports
HelpPage = links_pb2.HelpPageLinkRequest
SearchNode = search_pb2.SearchNode
Progress = collection_pb2.Progress
EmptyCardsReport = card_rendering_pb2.EmptyCardsReport

1
pylib/anki/links_pb2.pyi Normal file
View file

@ -0,0 +1 @@
../../bazel-bin/pylib/anki/links_pb2.pyi

View file

@ -34,7 +34,7 @@ from PyQt5.QtWidgets import (
)
import aqt
from anki.collection import Collection
from anki.collection import Collection, HelpPage
from anki.lang import TR, tr_legacyglobal # pylint: disable=unused-import
from anki.utils import invalidFilename, isMac, isWin, noBundledLibs, versionWithBuild
from aqt.qt import *
@ -69,42 +69,15 @@ def locale_dir() -> str:
# shortcut to access Fluent translations; set as
tr = tr_legacyglobal
class HelpPage(Enum):
NOTE_TYPE = "getting-started#note-types"
BROWSING = "browsing"
BROWSING_FIND_AND_REPLACE = "browsing#find-and-replace"
BROWSING_NOTES_MENU = "browsing#notes"
KEYBOARD_SHORTCUTS = "studying#keyboard-shortcuts"
EDITING = "editing"
ADDING_CARD_AND_NOTE = "editing#adding-cards-and-notes"
ADDING_A_NOTE_TYPE = "editing#adding-a-note-type"
LATEX = "math#latex"
PREFERENCES = "preferences"
INDEX = ""
TEMPLATES = "templates/intro"
FILTERED_DECK = "filtered-decks"
IMPORTING = "importing"
CUSTOMIZING_FIELDS = "editing#customizing-fields"
DECK_OPTIONS = "deck-options"
EDITING_FEATURES = "editing#features"
HelpPageArgument = Optional[Union[HelpPage, str]]
"""This type represents what can be used as argument expecting a specific help page. Anki code should use HelpPage as
argument. However, add-on may use string, and we want to accept this.
"""
HelpPageArgument = Union["HelpPage.HelpPage.V", str]
def openHelp(section: HelpPageArgument) -> None:
link = aqt.appHelpSite
if section:
if isinstance(section, HelpPage):
link += section.value
if isinstance(section, str):
page = HelpPage(literal=section)
else:
link += section
openLink(link)
page = HelpPage(variant=section)
openLink(tr.backend().help_page_link(page))
def openLink(link: Union[str, QUrl]) -> None: