Merge pull request #944 from Arthur-Milchior/help
NF: HelpPage in an enum
This commit is contained in:
commit
e324f06348
@ -16,6 +16,7 @@ from aqt.qt import *
|
||||
from aqt.sound import av_player
|
||||
from aqt.utils import (
|
||||
TR,
|
||||
HelpPage,
|
||||
addCloseShortcut,
|
||||
askUser,
|
||||
disable_help_button,
|
||||
@ -64,7 +65,7 @@ class AddCards(QDialog):
|
||||
self.deckChooser = aqt.deckchooser.DeckChooser(self.mw, self.form.deckArea)
|
||||
|
||||
def helpRequested(self):
|
||||
openHelp("editing?id=adding-cards-and-notes")
|
||||
openHelp(HelpPage.ADDING_CARD_AND_NOTE)
|
||||
|
||||
def setupButtons(self) -> None:
|
||||
bb = self.form.buttonBox
|
||||
@ -172,7 +173,7 @@ class AddCards(QDialog):
|
||||
problem = tr(TR.ADDING_THE_FIRST_FIELD_IS_EMPTY)
|
||||
problem = gui_hooks.add_cards_will_add_note(problem, note)
|
||||
if problem is not None:
|
||||
showWarning(problem, help="editing?id=adding-cards-and-notes")
|
||||
showWarning(problem, help=HelpPage.ADDING_CARD_AND_NOTE)
|
||||
return None
|
||||
if note.model()["type"] == MODEL_CLOZE:
|
||||
if not note.cloze_numbers_in_fields():
|
||||
|
@ -8,7 +8,7 @@ import time
|
||||
from concurrent.futures import Future
|
||||
from dataclasses import dataclass
|
||||
from operator import itemgetter
|
||||
from typing import List, Sequence, Tuple, cast
|
||||
from typing import List, Optional, Sequence, Tuple, cast
|
||||
|
||||
import aqt
|
||||
import aqt.forms
|
||||
@ -39,6 +39,7 @@ from aqt.sidebar import SidebarTreeView
|
||||
from aqt.theme import theme_manager
|
||||
from aqt.utils import (
|
||||
TR,
|
||||
HelpPage,
|
||||
MenuList,
|
||||
SubMenu,
|
||||
askUser,
|
||||
@ -1196,7 +1197,7 @@ where id in %s"""
|
||||
return sf
|
||||
|
||||
def onHelp(self):
|
||||
openHelp("browsing")
|
||||
openHelp(HelpPage.BROWSING)
|
||||
|
||||
# Misc menu options
|
||||
######################################################################
|
||||
@ -1296,7 +1297,7 @@ where id in %s"""
|
||||
current=current,
|
||||
accept=tr(TR.BROWSING_MOVE_CARDS),
|
||||
title=tr(TR.BROWSING_CHANGE_DECK),
|
||||
help="browsing",
|
||||
help=HelpPage.BROWSING,
|
||||
parent=self,
|
||||
)
|
||||
if not ret.name:
|
||||
@ -1648,7 +1649,7 @@ where id in %s"""
|
||||
self.mw.taskman.run_in_background(do_search, on_done)
|
||||
|
||||
def onFindReplaceHelp(self):
|
||||
openHelp("browsing?id=find-and-replace")
|
||||
openHelp(HelpPage.BROWSING_FIND_AND_REPLACE)
|
||||
|
||||
# Edit: finding dupes
|
||||
######################################################################
|
||||
@ -2002,7 +2003,7 @@ class ChangeModel(QDialog):
|
||||
QDialog.accept(self)
|
||||
|
||||
def onHelp(self):
|
||||
openHelp("browsing?id=other-menu-items")
|
||||
openHelp(HelpPage.BROWSING_OTHER_MENU_ITEMS)
|
||||
|
||||
|
||||
# Card Info Dialog
|
||||
|
@ -20,6 +20,7 @@ from aqt.sound import av_player, play_clicked_audio
|
||||
from aqt.theme import theme_manager
|
||||
from aqt.utils import (
|
||||
TR,
|
||||
HelpPage,
|
||||
askUser,
|
||||
disable_help_button,
|
||||
downArrow,
|
||||
@ -828,4 +829,4 @@ class CardLayout(QDialog):
|
||||
self.mw = None
|
||||
|
||||
def onHelp(self):
|
||||
openHelp("templates/intro")
|
||||
openHelp(HelpPage.TEMPLATES)
|
||||
|
@ -5,7 +5,7 @@ from typing import Any
|
||||
|
||||
from aqt import AnkiQt, gui_hooks
|
||||
from aqt.qt import *
|
||||
from aqt.utils import TR, shortcut, tr
|
||||
from aqt.utils import TR, HelpPage, shortcut, tr
|
||||
|
||||
|
||||
class DeckChooser(QHBoxLayout):
|
||||
@ -86,7 +86,7 @@ class DeckChooser(QHBoxLayout):
|
||||
current=current,
|
||||
accept=tr(TR.ACTIONS_CHOOSE),
|
||||
title=tr(TR.QT_MISC_CHOOSE_DECK),
|
||||
help="editing",
|
||||
help=HelpPage.EDITING,
|
||||
cancel=False,
|
||||
parent=self.widget,
|
||||
geomKey="selectDeck",
|
||||
|
@ -13,6 +13,7 @@ from aqt import gui_hooks
|
||||
from aqt.qt import *
|
||||
from aqt.utils import (
|
||||
TR,
|
||||
HelpPage,
|
||||
askUser,
|
||||
disable_help_button,
|
||||
getOnlyText,
|
||||
@ -40,7 +41,9 @@ class DeckConf(QDialog):
|
||||
self.setupCombos()
|
||||
self.setupConfs()
|
||||
self.setWindowModality(Qt.WindowModal)
|
||||
qconnect(self.form.buttonBox.helpRequested, lambda: openHelp("deck-options"))
|
||||
qconnect(
|
||||
self.form.buttonBox.helpRequested, lambda: openHelp(HelpPage.DECK_OPTIONS)
|
||||
)
|
||||
qconnect(self.form.confOpts.clicked, self.confOpts)
|
||||
qconnect(
|
||||
self.form.buttonBox.button(QDialogButtonBox.RestoreDefaults).clicked,
|
||||
|
@ -9,6 +9,7 @@ from anki.rsbackend import InvalidInput
|
||||
from aqt.qt import *
|
||||
from aqt.utils import (
|
||||
TR,
|
||||
HelpPage,
|
||||
askUser,
|
||||
disable_help_button,
|
||||
openHelp,
|
||||
@ -36,7 +37,9 @@ class DeckConf(QDialog):
|
||||
self.mw.checkpoint(tr(TR.ACTIONS_OPTIONS))
|
||||
disable_help_button(self)
|
||||
self.setWindowModality(Qt.WindowModal)
|
||||
qconnect(self.form.buttonBox.helpRequested, lambda: openHelp("filtered-decks"))
|
||||
qconnect(
|
||||
self.form.buttonBox.helpRequested, lambda: openHelp(HelpPage.FILTERED_DECK)
|
||||
)
|
||||
self.setWindowTitle(
|
||||
without_unicode_isolation(tr(TR.ACTIONS_OPTIONS_FOR, val=self.deck["name"]))
|
||||
)
|
||||
|
@ -32,6 +32,7 @@ from aqt.sound import av_player
|
||||
from aqt.theme import theme_manager
|
||||
from aqt.utils import (
|
||||
TR,
|
||||
HelpPage,
|
||||
disable_help_button,
|
||||
getFile,
|
||||
openHelp,
|
||||
@ -572,7 +573,9 @@ class Editor:
|
||||
form.setupUi(d)
|
||||
restoreGeom(d, "htmlEditor")
|
||||
disable_help_button(d)
|
||||
qconnect(form.buttonBox.helpRequested, lambda: openHelp("editing?id=features"))
|
||||
qconnect(
|
||||
form.buttonBox.helpRequested, lambda: openHelp(HelpPage.EDITING_FEATURES)
|
||||
)
|
||||
form.textEdit.setPlainText(self.note.fields[field])
|
||||
d.show()
|
||||
form.textEdit.moveCursor(QTextCursor.End)
|
||||
|
@ -11,6 +11,7 @@ from aqt.qt import *
|
||||
from aqt.schema_change_tracker import ChangeTracker
|
||||
from aqt.utils import (
|
||||
TR,
|
||||
HelpPage,
|
||||
askUser,
|
||||
disable_help_button,
|
||||
getOnlyText,
|
||||
@ -245,4 +246,4 @@ class FieldDialog(QDialog):
|
||||
self.mw.taskman.with_progress(save, on_done, self)
|
||||
|
||||
def onHelp(self):
|
||||
openHelp("editing?id=customizing-fields")
|
||||
openHelp(HelpPage.CUSTOMIZING_FIELDS)
|
||||
|
@ -19,6 +19,7 @@ from aqt import AnkiQt, gui_hooks
|
||||
from aqt.qt import *
|
||||
from aqt.utils import (
|
||||
TR,
|
||||
HelpPage,
|
||||
askUser,
|
||||
disable_help_button,
|
||||
getFile,
|
||||
@ -122,7 +123,7 @@ class ImportDialog(QDialog):
|
||||
getOnlyText(
|
||||
tr(TR.IMPORTING_BY_DEFAULT_ANKI_WILL_DETECT_THE),
|
||||
self,
|
||||
help="importing",
|
||||
help=HelpPage.IMPORTING,
|
||||
)
|
||||
or "\t"
|
||||
)
|
||||
@ -280,7 +281,7 @@ class ImportDialog(QDialog):
|
||||
QDialog.reject(self)
|
||||
|
||||
def helpRequested(self):
|
||||
openHelp("importing")
|
||||
openHelp(HelpPage.IMPORTING)
|
||||
|
||||
def importModeChanged(self, newImportMode):
|
||||
if newImportMode == 0:
|
||||
|
@ -48,6 +48,7 @@ from aqt.taskman import TaskManager
|
||||
from aqt.theme import theme_manager
|
||||
from aqt.utils import (
|
||||
TR,
|
||||
HelpPage,
|
||||
askUser,
|
||||
checkInvalidFilename,
|
||||
disable_help_button,
|
||||
@ -1090,7 +1091,7 @@ title="%s" %s>%s</button>""" % (
|
||||
openLink(aqt.appDonate)
|
||||
|
||||
def onDocumentation(self):
|
||||
openHelp("")
|
||||
openHelp(HelpPage.INDEX)
|
||||
|
||||
# Importing & exporting
|
||||
##########################################################################
|
||||
|
@ -5,7 +5,7 @@ from typing import Optional
|
||||
|
||||
from aqt import AnkiQt, gui_hooks
|
||||
from aqt.qt import *
|
||||
from aqt.utils import TR, shortcut, tr
|
||||
from aqt.utils import TR, HelpPage, shortcut, tr
|
||||
|
||||
|
||||
class ModelChooser(QHBoxLayout):
|
||||
@ -82,7 +82,7 @@ class ModelChooser(QHBoxLayout):
|
||||
names=nameFunc,
|
||||
accept=tr(TR.ACTIONS_CHOOSE),
|
||||
title=tr(TR.QT_MISC_CHOOSE_NOTE_TYPE),
|
||||
help="getting-started?id=note-types",
|
||||
help=HelpPage.NOTE_TYPE,
|
||||
current=current,
|
||||
parent=self.widget,
|
||||
buttons=[edit],
|
||||
|
@ -15,6 +15,7 @@ from aqt import AnkiQt, gui_hooks
|
||||
from aqt.qt import *
|
||||
from aqt.utils import (
|
||||
TR,
|
||||
HelpPage,
|
||||
askUser,
|
||||
disable_help_button,
|
||||
getText,
|
||||
@ -48,7 +49,7 @@ class Models(QDialog):
|
||||
self.form.setupUi(self)
|
||||
qconnect(
|
||||
self.form.buttonBox.helpRequested,
|
||||
lambda: openHelp("editing?id=adding-a-note-type"),
|
||||
lambda: openHelp(HelpPage.ADDING_A_NOTE_TYPE),
|
||||
)
|
||||
self.models: List[pb.NoteTypeNameIDUseCount] = []
|
||||
self.setupModels()
|
||||
@ -181,7 +182,7 @@ class Models(QDialog):
|
||||
d.setWindowTitle(
|
||||
without_unicode_isolation(tr(TR.ACTIONS_OPTIONS_FOR, val=nt["name"]))
|
||||
)
|
||||
qconnect(frm.buttonBox.helpRequested, lambda: openHelp("math?id=latex"))
|
||||
qconnect(frm.buttonBox.helpRequested, lambda: openHelp(HelpPage.LATEX))
|
||||
restoreGeom(d, "modelopts")
|
||||
gui_hooks.models_advanced_will_show(d)
|
||||
d.exec_()
|
||||
@ -266,4 +267,4 @@ class AddModel(QDialog):
|
||||
QDialog.accept(self)
|
||||
|
||||
def onHelp(self) -> None:
|
||||
openHelp("editing?id=adding-a-note-type")
|
||||
openHelp(HelpPage.ADDING_A_NOTE_TYPE)
|
||||
|
@ -8,6 +8,7 @@ from aqt.profiles import RecordingDriver, VideoDriver
|
||||
from aqt.qt import *
|
||||
from aqt.utils import (
|
||||
TR,
|
||||
HelpPage,
|
||||
askUser,
|
||||
disable_help_button,
|
||||
openHelp,
|
||||
@ -42,7 +43,9 @@ class Preferences(QDialog):
|
||||
disable_help_button(self)
|
||||
self.form.buttonBox.button(QDialogButtonBox.Help).setAutoDefault(False)
|
||||
self.form.buttonBox.button(QDialogButtonBox.Close).setAutoDefault(False)
|
||||
qconnect(self.form.buttonBox.helpRequested, lambda: openHelp("preferences"))
|
||||
qconnect(
|
||||
self.form.buttonBox.helpRequested, lambda: openHelp(HelpPage.PREFERENCES)
|
||||
)
|
||||
self.silentlyClose = True
|
||||
self.prefs = self.mw.col.backend.get_preferences()
|
||||
self.setupLang()
|
||||
|
@ -1,11 +1,14 @@
|
||||
# Copyright: Ankitects Pty Ltd and contributors
|
||||
# -*- coding: utf-8 -*-
|
||||
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
|
||||
import aqt
|
||||
from aqt import gui_hooks
|
||||
from aqt.qt import *
|
||||
from aqt.utils import (
|
||||
TR,
|
||||
HelpPage,
|
||||
HelpPageArgument,
|
||||
disable_help_button,
|
||||
getOnlyText,
|
||||
openHelp,
|
||||
@ -24,7 +27,7 @@ class StudyDeck(QDialog):
|
||||
names=None,
|
||||
accept=None,
|
||||
title=None,
|
||||
help="studying?id=keyboard-shortcuts",
|
||||
help: HelpPageArgument = HelpPage.KEYBOARD_SHORTCUTS,
|
||||
current=None,
|
||||
cancel=True,
|
||||
parent=None,
|
||||
|
@ -7,6 +7,7 @@ import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
from enum import Enum
|
||||
from typing import TYPE_CHECKING, Any, List, Optional, Union, cast
|
||||
|
||||
from markdown import markdown
|
||||
@ -46,10 +47,40 @@ def tr(key: TRValue, **kwargs: Union[str, int, float]) -> str:
|
||||
return anki.lang.current_i18n.translate(key, **kwargs)
|
||||
|
||||
|
||||
def openHelp(section):
|
||||
class HelpPage(Enum):
|
||||
NOTE_TYPE = "getting-started?id=note-types"
|
||||
BROWSING = "browsing"
|
||||
BROWSING_FIND_AND_REPLACE = "browsing?id=find-and-replace"
|
||||
BROWSING_OTHER_MENU_ITEMS = "browsing?id=other-menu-items"
|
||||
KEYBOARD_SHORTCUTS = "studying?id=keyboard-shortcuts"
|
||||
EDITING = "editing"
|
||||
ADDING_CARD_AND_NOTE = "editing?id=adding-cards-and-notes"
|
||||
ADDING_A_NOTE_TYPE = "editing?id=adding-a-note-type"
|
||||
LATEX = "math?id=latex"
|
||||
PREFERENCES = "preferences"
|
||||
INDEX = ""
|
||||
TEMPLATES = "templates/intro"
|
||||
FILTERED_DECK = "filtered-decks"
|
||||
IMPORTING = "importing"
|
||||
CUSTOMIZING_FIELDS = "editing?id=customizing-fields"
|
||||
DECK_OPTIONS = "deck-options"
|
||||
EDITING_FEATURES = "editing?id=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.
|
||||
|
||||
"""
|
||||
|
||||
|
||||
def openHelp(section: HelpPageArgument):
|
||||
link = aqt.appHelpSite
|
||||
if section:
|
||||
link += section
|
||||
if isinstance(section, HelpPage):
|
||||
link += section.value
|
||||
else:
|
||||
link += section
|
||||
openLink(link)
|
||||
|
||||
|
||||
@ -180,7 +211,14 @@ def showText(
|
||||
return diag, box
|
||||
|
||||
|
||||
def askUser(text, parent=None, help="", defaultno=False, msgfunc=None, title="Anki"):
|
||||
def askUser(
|
||||
text,
|
||||
parent=None,
|
||||
help: HelpPageArgument = None,
|
||||
defaultno=False,
|
||||
msgfunc=None,
|
||||
title="Anki",
|
||||
):
|
||||
"Show a yes/no question. Return true if yes."
|
||||
if not parent:
|
||||
parent = aqt.mw.app.activeWindow()
|
||||
@ -204,7 +242,9 @@ def askUser(text, parent=None, help="", defaultno=False, msgfunc=None, title="An
|
||||
|
||||
|
||||
class ButtonedDialog(QMessageBox):
|
||||
def __init__(self, text, buttons, parent=None, help="", title="Anki"):
|
||||
def __init__(
|
||||
self, text, buttons, parent=None, help: HelpPageArgument = None, title="Anki"
|
||||
):
|
||||
QMessageBox.__init__(self, parent)
|
||||
self._buttons = []
|
||||
self.setWindowTitle(title)
|
||||
@ -231,7 +271,9 @@ class ButtonedDialog(QMessageBox):
|
||||
self.setDefaultButton(self._buttons[idx])
|
||||
|
||||
|
||||
def askUserDialog(text, buttons, parent=None, help="", title="Anki"):
|
||||
def askUserDialog(
|
||||
text, buttons, parent=None, help: HelpPageArgument = None, title="Anki"
|
||||
):
|
||||
if not parent:
|
||||
parent = aqt.mw
|
||||
diag = ButtonedDialog(text, buttons, parent, help, title=title)
|
||||
@ -243,7 +285,7 @@ class GetTextDialog(QDialog):
|
||||
self,
|
||||
parent,
|
||||
question,
|
||||
help=None,
|
||||
help: HelpPageArgument = None,
|
||||
edit=None,
|
||||
default="",
|
||||
title="Anki",
|
||||
@ -289,7 +331,7 @@ class GetTextDialog(QDialog):
|
||||
def getText(
|
||||
prompt,
|
||||
parent=None,
|
||||
help=None,
|
||||
help: HelpPageArgument = None,
|
||||
edit=None,
|
||||
default="",
|
||||
title="Anki",
|
||||
|
Loading…
Reference in New Issue
Block a user