Exemplo n.º 1
0
def initializeViews():
    try:
        from aqt.gui_hooks import (
            deck_browser_will_render_content,
            overview_will_render_content,
        )

        deck_browser_will_render_content.append(on_deckbrowser_will_render_content)
        overview_will_render_content.append(on_overview_will_render_content)
    except (ImportError, ModuleNotFoundError):
        Overview._body = ov_body
        Overview._renderPage = overviewRenderPage
        DeckBrowser._renderStats = wrap(
            DeckBrowser._renderStats, deckbrowserRenderStats, "around"
        )

    # TODO: Submit Anki PR to add hook to CollectionStats.report
    CollectionStats.dueGraph = wrap(
        CollectionStats.dueGraph, collectionStatsDueGraph, "around"
    )
    DeckStats.__init__ = wrap(DeckStats.__init__, deckStatsInit21, "after")
    DeckStats.reject = wrap(DeckStats.reject, deckStatsReject)

    # Initially set up hotkey:
    # TODO: Migrate to config.json storage, so that profile hook is not required
    try:
        from aqt.gui_hooks import profile_did_open

        profile_did_open.append(initializeHotkey)
    except (ImportError, ModuleNotFoundError):
        addHook("profileLoaded", initializeHotkey)

    # Update hotkey on config save:
    addHook("config_saved_heatmap", initializeHotkey)
Exemplo n.º 2
0
def initialize_reviewer():
    """Delay patching reviewer to counteract bad practices in other add-ons that
    overwrite revHtml and _linkHandler in their entirety"""

    from aqt.gui_hooks import profile_did_open, webview_will_show_context_menu

    profile_did_open.append(patch_reviewer)
    webview_will_show_context_menu.append(on_webview_will_show_context_menu)

    setup_shortcuts()
Exemplo n.º 3
0
def init():
    setup_script()
    profile_did_open.append(install_script)
    profile_did_open.append(update_closet)

    init_webview()
    init_editor()
    init_addcards()

    init_models_dialog()
    init_addon_manager()
Exemplo n.º 4
0
def init_addon_manager():
    profile_did_open.append(update_graphs_data)
    mw.addonManager.setConfigAction(__name__, show_settings)
def init_conf_dict():
    profile_did_open.append(load_conf_dict)
    profile_will_close.append(save_conf_dict)
Exemplo n.º 6
0
    for level in sorted(nestedlevels.keys(), reverse=True):
        for did in nestedlevels[level]:
            thiscount = newcounts_per_deck[did]
            if thiscount:
                newcount += newcounts_per_deck[did]
                for parent in mw.col.decks.parents(did):
                    newcounts_per_deck[parent["id"]] -= newcounts_per_deck[did]
    new_cards_today__from_decks = newcount


def onload():
    if gc("count method") == "deck":
        new_cards__set_from_deck_settings()


profile_did_open.append(onload)


def after_sync(col):
    if gc("count method") == "deck":
        new_cards__set_from_deck_settings()


collection_did_load.append(after_sync)

###### count based on revlog entries
import datetime


# TODO: simplify this
def return_day_start_in_epoch():
Exemplo n.º 7
0
def init_deckbrowser():
    profile_did_open.append(add_deckbrowser_hook)
    profile_will_close.append(remove_deckbrowser_hook)
    DeckBrowser._linkHandler = wrap(DeckBrowser._linkHandler,
                                    add_browser_search_link, "before")
Exemplo n.º 8
0
from aqt.gui_hooks import browser_menus_did_init, profile_did_open
from aqt.qt import *

try:
    from aqt.browser.browser import Browser
except:
    from aqt.browser import Browser

from .compat import add_compat_aliases_to_anki, add_compat_aliases_to_aqt

add_compat_aliases_to_anki()

from .mindmap_creator_dialog import show as show_dialog


def setup_menu(self: Browser):
    menubar = self.form.menubar
    menu = menubar.addMenu("Mind map")

    a = menu.addAction("Create a mind map")
    a.triggered.connect(lambda _: show_dialog())


profile_did_open.append(add_compat_aliases_to_aqt)

browser_menus_did_init.append(setup_menu)
Exemplo n.º 9
0
        # autodestroy = False
        # it can also be a function, taking id and storage
        # autodestroy = lambda id, storage: True or False
    )

    lib.register_interface(my_interface)


def install_script():
    # insert the script for every model
    for model_id in mw.col.models.ids():
        # create the meta script which points to your interface
        my_meta_script = lib.make_meta_script(
            # this is the tag your interface above is registered on!
            f"{script_name}_tag",
            # your id: you can register an id only once per model per tag
            # it is typically useful to point to the model_id from the id
            # this way you can associate scripts with models from within the interface methods above if you need to
            f"{model_id}",
        )

        lib.register_meta_script(
            model_id,
            my_meta_script,
        )


if am:
    setup_script()
    profile_did_open.append(install_script)
Exemplo n.º 10
0
def initialize_template():
    from aqt.gui_hooks import profile_did_open

    profile_did_open.append(maybe_create_template)
alreadyrun = False


def main_setup_menus():  # noqa
    global alreadyrun
    if alreadyrun:
        return
    alreadyrun = True

    view = get_menu(mw, "&View")

    action = QAction(mw)
    action.setText("Card Stats")
    action.setCheckable(True)
    action.setChecked(sidebar_visibility)
    action.setShortcut(QKeySequence("Shift+C"))
    view.addAction(action)
    action.toggled.connect(card_stats)


profile_did_open.append(main_setup_menus)  # noqa


def hide_sidebar():
    global sidebar_visibility
    cs.hide()


profile_will_close.append(hide_sidebar)  # noqa
Exemplo n.º 12
0

def quick_insert_addon_check():
    global alreadyrun
    global quick_insert_addon_filter_func
    if alreadyrun:
        return
    alreadyrun = True
    try:
        quick_insert_addon_filter_func = __import__(
            "1052724801").onSearchEditTextChange
    except:
        quick_insert_addon_filter_func = None


profile_did_open.append(quick_insert_addon_check)


def open_multiline_searchwindow(browser):
    le = browser.form.searchEdit.lineEdit()
    sbi = SearchBox(browser, le.text(), quick_insert_addon_filter_func)
    if sbi.exec():
        le.setText(sbi.newsearch)
        le.setFocus()
        browser.onSearchActivated()


def setupBrowserShortcuts(self):
    # self is browser
    cut = gc("shortcut: open window")
    if cut: