Beispiel #1
0
def setupGuiMenu():
    addMenu = False
    if not hasattr(mw, 'MigakuMainMenu'):
        mw.MigakuMainMenu = QMenu('Migaku', mw)
        addMenu = True
    if not hasattr(mw, 'MigakuMenuSettings'):
        mw.MigakuMenuSettings = []
    if not hasattr(mw, 'MigakuMenuActions'):
        mw.MigakuMenuActions = []

    setting = QAction("Vacation Settings", mw)
    setting.triggered.connect(openVacationSettings)
    mw.MigakuMenuSettings.append(setting)
    action = QAction("Optimize Schedule", mw)
    action.triggered.connect(mw.MigakuRescheduler.loopCol)
    action2 = QAction("Vacation Scheduler", mw)
    action2.triggered.connect(VacationScheduler.start)
    action3 = QAction("Sick Day (All Decks)", mw)
    action3.triggered.connect(mw.miSickSched.sickDayPrompt)
    action4 = QAction("Catch Up (All Decks)", mw)
    action4.triggered.connect(mw.miSickSched.openScheduler)
    mw.MigakuMenuActions.append(action)
    mw.MigakuMenuActions.append(action2)
    mw.MigakuMenuActions.append(action3)
    mw.MigakuMenuActions.append(action4)
    mw.MigakuMainMenu.clear()
    for act in mw.MigakuMenuSettings:
        mw.MigakuMainMenu.addAction(act)
    mw.MigakuMainMenu.addSeparator()
    for act in mw.MigakuMenuActions:
        mw.MigakuMainMenu.addAction(act)

    if addMenu:
        mw.form.menubar.insertMenu(mw.form.menuHelp.menuAction(),
                                   mw.MigakuMainMenu)
Beispiel #2
0
def setupMenu(ed):
    a = QAction('Regenerating pitch accent svgs', ed)
    if HOT_KEY:
        a.setShortcut(QKeySequence(HOT_KEY))
    a.triggered.connect(lambda: onRegenGlosses(ed))
    ed.form.menuEdit.addSeparator()
    ed.form.menuEdit.addAction(a)
Beispiel #3
0
def add_action(title, to, funct, checkable=False):
    action = QAction(_(title), mw)
    if checkable:
        action.setCheckable(True)
    action.triggered.connect(funct)
    to.addAction(action)
    return action
Beispiel #4
0
def load():
    menu = mw.form.menuTools.addMenu("jjigae")
    action = QAction("Fill missing", mw)
    action.triggered.connect(fill_missing)
    xaction = QAction("Prestudy", mw)
    xaction.triggered.connect(PrestudyDialog.instantiate_and_run)
    menu.addAction(action)
    menu.addAction(xaction)
Beispiel #5
0
def setupBrowserShortcuts(self):
    # self is browser
    cut = gc("shortcut: open window")
    if cut:
        cm = QShortcut(QKeySequence(cut), self)
        qconnect(cm.activated, lambda b=self: open_multiline_searchwindow(b))
    view = getMenu(self, "&View")
    action = QAction(self)
    action.setText("Show search string in multi-line dialog")
    view.addAction(action)
    action.triggered.connect(lambda _, b=self: open_multiline_searchwindow(b))
Beispiel #6
0
def mainSetupMenus():
    global alreadyrun
    if alreadyrun:
        return
    alreadyrun = True

    view = getMenu(mw, "More &Stats")

    action = QAction(mw)
    action.setText("New Cards processed today")
    view.addAction(action)
    action.triggered.connect(show_new_cards_learned)
Beispiel #7
0
def setup_browser_menu(browser):
    menu = QMenu('Kanji Extractor', browser)
    browser.form.menuEdit.addAction(menu.menuAction())

    create_action = QAction("Extract Kanji", browser)
    create_action.triggered.connect(
        lambda: create_kanji_notes_browser(browser))
    menu.addAction(create_action)

    update_action = QAction("Update Kanji Notes", browser)
    update_action.triggered.connect(
        lambda: update_kanji_notes_browser(browser))
    menu.addAction(update_action)
Beispiel #8
0
def on_menu_setup(browser: Browser):
    anki_ocr_menu = QMenu(("AnkiOCR"), browser)

    act_run_ocr = QAction(browser, text="Run AnkiOCR on selected notes")
    act_run_ocr.triggered.connect(lambda b=browser: on_run_ocr(browser))
    anki_ocr_menu.addAction(act_run_ocr)

    act_rm_ocr_fields = QAction(browser, text="Remove OCR data from selected notes")
    act_rm_ocr_fields.triggered.connect(lambda b=browser: on_rm_ocr_fields(browser))
    anki_ocr_menu.addAction(act_rm_ocr_fields)

    browser_cards_menu = browser.form.menu_Cards
    browser_cards_menu.addSeparator()
    browser_cards_menu.addMenu(anki_ocr_menu)
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)
Beispiel #10
0
 def __init__(self, mw):
     if mw:
         self.menuAction = QAction("Generate Kanji/Hanzi Grid",
                                   mw,
                                   triggered=self.setup)
         mw.form.menuTools.addSeparator()
         mw.form.menuTools.addAction(self.menuAction)
Beispiel #11
0
def add_menu_items(menu_items, parent=None):
    if not parent:
        parent = mw.form.menubar
    for title, action in menu_items:
        if title == "SEPARATOR":
            parent.addSeparator()
        elif isinstance(action, list):
            menu = QMenu(_(title), parent)
            parent.insertMenu(mw.form.menuTools.menuAction(), menu)
            add_menu_items(action, menu)
        else:
            checkable = False
            if isinstance(action, dict):
                options = action
                action = options['action']
                if 'checkable' in options:
                    checkable = options['checkable']
            # if ANKNOTES.DEVELOPER_MODE.ENABLED and ANKNOTES.DEVELOPER_MODE.AUTO_RELOAD_MODULES:
            action = auto_reload_wrapper(action)
            # noinspection PyArgumentList
            menu_action = QAction(_(title), mw, checkable=checkable)
            parent.addAction(menu_action)
            parent.connect(menu_action, SIGNAL("triggered()"), action)
            if checkable:
                anknotes_checkable_menu_items[title] = menu_action
Beispiel #12
0
def create_item(prefix, root, name, fs):
    if name == '--':
        root.addSeparator()
    else:
        action = QAction(name, mw)
        mw.connect(action, SIGNAL("triggered()"), fs[prefix + '_' + to_id(name)])
        root.addAction(action)
Beispiel #13
0
def setup_menu(browser):
    menu = browser.form.menu_Notes
    before = browser.form.actionClear_Unused_Tags
    browser.form.actionFind_replace_tags = action = QAction(
        'Find and Replace Tags (RegEx)')
    menu.insertAction(before, action)
    action.setShortcut(QKeySequence("Ctrl+Alt+Shift+R"))
    action.triggered.connect(lambda: Replacer(browser))
    def setupBindings(self):
        addHook('AnkiWebView.contextMenuEvent', self.onReviewerHandle)

        Reviewer.nextCard = self.wrapOnCardShift(Reviewer.nextCard)
        Reviewer._shortcutKeys = self.wrap_shortcutKeys(Reviewer._shortcutKeys)

        # Add config to menu
        action = QAction("Anki-Web-Browser Config", self._ankiMw)
        action.triggered.connect(self.openConfig)
        self._ankiMw.form.menuTools.addAction(action)
Beispiel #15
0
def setup_menu():
    menu = QMenu('Kanji Exctractor', mw)
    mw.form.menuTools.addAction(menu.menuAction())
    # mw.form.menuLookup = menu

    create_action = QAction('Create Kanji Notes', mw)
    create_action.triggered.connect(create_kanji_notes)
    menu.addAction(create_action)

    settings_action = QAction('Update Kanji Notes', mw)
    settings_action.triggered.connect(open_settings)
    menu.addAction(settings_action)

    settings_action = QAction('Settings', mw)
    settings_action.triggered.connect(open_settings)
    menu.addAction(settings_action)

    about_action = QAction('About...', mw)
    about_action.triggered.connect(show_about)
    menu.addAction(about_action)
    def setupBindings(self):
        anki.hooks.addHook('EditorWebView.contextMenuEvent',
                           self.onEditorHandle)
        anki.hooks.addHook('AnkiWebView.contextMenuEvent',
                           self.onReviewerHandle)

        Reviewer.nextCard = self.wrapOnCardShift(Reviewer.nextCard)
        Editor.loadNote = self.wrapOnCardShift(Editor.loadNote)

        # Add config to menu
        action = QAction("Anki-Web-Browser Config", self._ankiMw)
        action.triggered.connect(self.openConfig)
        self._ankiMw.form.menuTools.addAction(action)
def addResetModelButton():
    def _():
        # This could happen on environment like macOS, where menu item can be
        # clicked without main window being visible (e.g: no profile loaded)
        if not mw.col:
            return

        if askUser(
                "Really reset the model template? This will wipe all your UI customization."
        ):
            resetClozeHideModel(mw.col)
            mw.reset()
            tooltip("Template reset")

    action = QAction("(Warning) Reset template of Cloze (Hide All)", mw)
    action.triggered.connect(_)
    mw.form.menuHelp.addAction(action)
Beispiel #18
0
    def __init__(self):
        mw.addonManager.setWebExports("AnkiEmperor", ".*")

        # Setup
        self.db = DBConnect()
        self.__treasureChest = TreasureChest(self.db)
        self.__options = Options(self.db)
        self.__eventManager = EventManager(self, self.__options,
                                           self.__treasureChest)
        self.__stats = Stats(self.db, self.__eventManager)
        world = World(self.db, self.__options.getOption("activeCountry"))
        self.__buildingAuthority = BuildingAuthority(self, world)
        self.__ranks = Ranks(self.db, self.__eventManager, world)
        self.__ranks.updateRank(
            self.__treasureChest.getTotalGold(),
            self.__buildingAuthority.getActiveCountry().
            getCompletedObjectsPercentage(),
            True,
        )
        self.__layout = None  # Setup as a property as we must be able to clear it
        # Keep's track of current view. Useful if we want to update a view, but we're not sure which one
        self.__view = None
        self.deckSelected = False

        # Setup window
        QDialog.__init__(self, mw, Qt.WindowTitleHint)
        self.setWindowTitle(getPluginName())
        self.resize(300, 800)
        gui_hooks.reviewer_did_answer_card.append(self.answerCard)
        gui_hooks.webview_did_receive_js_message.append(self.links)
        self.open_main()

        # Wrap Anki methods

        # This should probably be handled better
        # Should each view have its own call to did_receive_js_message?
        # FIXME Investigate if there are native versions of these functions..
        _Collection.undo = wrap(_Collection.undo, self.undo)
        DeckManager.select = wrap(DeckManager.select, self.refreshSettings)

        # Add AnkiEmperor to the Anki menu
        action = QAction(getPluginName(), mw)
        action.triggered.connect(self.show)
        # mw.connect(action, SIGNAL("triggered()"), self.show)
        mw.form.menuTools.addAction(action)
Beispiel #19
0
def add_menu_item(path, text, func, keys=None, checkable=False, checked=False):
    action = QAction(text, mw)

    if keys:
        action.setShortcut(QKeySequence(keys))

    if checkable:
        action.setCheckable(checkable)
        action.toggled.connect(func)
        if not hasattr(mw, 'action_groups'):
            mw.action_groups = {}
        if path not in mw.action_groups:
            mw.action_groups[path] = QActionGroup(None)
        mw.action_groups[path].addAction(action)
        action.setChecked(checked)
    else:
        action.triggered.connect(func)

    add_menu(path)
    mw.custom_menus[path].addAction(action)
def add_menu_actions(menu, menu_options):
    for mp in menu_options:

        k = mp[0]
        t = mp[1]
        cb = mp[2]

        hk = 0
        if k:
            hk = get_config_value(k)

        act = QAction(t, menu)
        if hk:
            act.setShortcut(QKeySequence(hk))
            act.setShortcutContext(Qt.ApplicationShortcut)

        if len(mp) > 3:
            icon = mp[3]
            icon = QIcon(utility.misc.get_web_folder_path() + "icons/" + icon)
            act.setIcon(icon)

        act.triggered.connect(cb)
        menu.addAction(act)
Beispiel #21
0
    #    #else:
    #    #    showInfo("Unable to load config. Make sure that config.json "
    #    #             "is present and not in use by other applications")

def parse_saved_wl():
    
    mw.wl_pareser = WParseSavedWL()
    mw.wl_pareser.parse()
    

    
mw.edit_cambridge_submenu = QMenu(u"&Cambridge Dictionary", mw)
mw.form.menuEdit.addSeparator()
mw.form.menuEdit.addMenu(mw.edit_cambridge_submenu)
# Single word 
mw.create_notes_from_link_action = QAction(mw)
mw.create_notes_from_link_action.setText("Create new note(s) from link")
mw.create_notes_from_link_action.setToolTip("Fetch word definitions from provided link.")
mw.create_notes_from_link_action.setShortcut(CREATE_NEW_NOTES_SHORTCUT)

mw.create_notes_from_link_action.triggered.connect(ask_user_for_link)
mw.edit_cambridge_submenu.addAction(mw.create_notes_from_link_action)

# Word list - saved
mw.parse_saved_wl_action = QAction(mw)
mw.parse_saved_wl_action.setText("Fetch new words from user wordlists")
mw.parse_saved_wl_action.setToolTip("Fetch new words from user wordlists")
mw.parse_saved_wl_action.triggered.connect(parse_saved_wl)
mw.edit_cambridge_submenu.addAction(mw.parse_saved_wl_action)

# Addon settings
        # We use this custom code to avoid sorting by id as users
        # may have customized orders in the due field.
        customSortCards(col, str_dids, start=redline, shuffle=shuffle)

    # Reset pos counter
    col.conf['nextPos'] = col.db.scalar(
        "select max(due)+1 from cards where type = 0") or 0

    mw.progress.finish()


if AUTOMATIC_SCAN_BEFORE_DB_CHECKUP:
    anki.collection._Collection.fixIntegrity = wrap(
        anki.collection._Collection.fixIntegrity, redue, "before")
else:
    action = QAction(mw)
    action.setText("Clean bulky dues")
    mw.form.menuTools.addAction(action)
    action.triggered.connect(lambda: redue(mw.col))

############################################
##  UTILS.py
###########################################


def customSortCards(col, str_dids, start=1, shuffle=False):
    now = intTime()

    if start <= 65536:  #16bits
        limit = "and due>666000 "
        due = start
Beispiel #23
0
def main():
    action = QAction('Import Roam notes...', mw)
    action.triggered.connect(import_roam_notes_into_anki)
    mw.form.menuTools.addAction(action)
Beispiel #24
0
# -*- mode: python ; coding: utf-8 -*-
# Copyright © 2012 Roland Sieker
# This file: License: GNU GPL, version 3 or later;
# http://www.gnu.org/copyleft/gpl.html
#

"""Change the names of files to more readable versions.

Go through the collection and detect files that alook like MD5
hashes used by Anki <1.2, look at the note for a better name and
rename the files, changing the notes as well.

"""

import dehashilator
from aqt import mw
from aqt.qt import QAction, SIGNAL

from dehashilator import __version__

dhma = QAction(mw)
dhma.setText("Dehashilate media")
mw.form.menuTools.addAction(dhma)
mw.connect(dhma, SIGNAL("triggered()"), dehashilator.test_and_dehashilate)
Beispiel #25
0
from aqt import mw
from aqt.qt import QAction


def onRestrictClicked():
    cardType = "Comprehension"
    noteType = "Word"
    deck = mw.col.decks.current()
    deckName = deck['name']

    query = 'card:"%s" note:"%s" deck:"%s"' % (cardType, noteType, deckName)
    mw.onCram(query)  #  ('card:"my card type"')


action = QAction("filtered deck for one card type", mw)
action.triggered.connect(onRestrictClicked)
mw.form.menuTools.addAction(action)
Beispiel #26
0
def create_menu():
    mn = QMenu()
    mn.setTitle("Nachschlagen")
    mw.form.menuTools.addAction(mn.menuAction())
    #
    mw.form.menu_nachschlagen = mn
    # add actions
    if show_japanese:
        # Maybe not show the Japanese actions.
        wae = QAction(mw)
        wae.setText("Japanisch bei Wadoku")
        # wae.setShortcut("Ctrl+4")
        mn.addAction(wae)
        mw.connect(wae, SIGNAL("triggered()"), on_lookup_wadoku_expression)
        wam = QAction(mw)
        wam.setText("Deutsch bei Wadoku")
        # wam.setShortcut("Ctrl+2")
        mn.addAction(wam)
        mw.connect(wam, SIGNAL("triggered()"), on_lookup_wadoku_meaning)
        was = QAction(mw)
        was.setText("Auswahl bei Wadoku")
        mn.addAction(was)
        mw.connect(was, SIGNAL("triggered()"), on_lookup_wadoku_selection)

        if show_saiga:
            # Personal taste: i like the Kanjilexikon better than the
            # Saiga look up. So i like this switched off.
            sae = QAction(mw)
            sae.setText("Kanji bei Saiga")
            #sae.setShortcut("Ctrl+4")
            mn.addAction(sae)
            mw.connect(sae, SIGNAL("triggered()"), on_lookup_saiga_expression)
            sas = QAction(mw)
            sas.setText("Kanjiauswahl bei Saiga")
            mn.addAction(sas)
            mw.connect(sas, SIGNAL("triggered()"), on_lookup_saiga_selection)

        kle = QAction(mw)
        kle.setText("Kanji bei Kanji-Lexikon")
        # kle.setShortcut("Ctrl+4")
        mn.addAction(kle)
        mw.connect(kle, SIGNAL("triggered()"), on_lookup_kl_expression)
        kls = QAction(mw)
        kls.setText("Kanjiauswahl bei Kanji-Lexikon")
        mn.addAction(kls)
        mw.connect(kls, SIGNAL("triggered()"), on_lookup_kl_selection)
    # Show these always.
    fae = QAction(mw)
    fae.setText("Ausdruck bei Forvo")
    # fae.setShortcut("Ctrl+4")
    mn.addAction(fae)
    mw.connect(fae, SIGNAL("triggered()"), on_lookup_forvo_expression)
    fas = QAction(mw)
    fas.setText("Auswahl bei Forvo")
    mn.addAction(fas)
    mw.connect(fas, SIGNAL("triggered()"), on_lookup_forvo_selection)
Beispiel #27
0
from aqt import mw
from aqt.qt import QAction, QKeySequence
from .canto.main import start_main
from .forms import dict_ui


def open_dict():
    mw.dict = start_main(dict_ui.Ui_Dialog())
    mw.dict.show()
    mw.dict.raise_()
    mw.dict.activateWindow()


action = QAction("CC-CANTO for Anki", mw)
action.triggered.connect(open_dict)
mw.form.menuTools.addAction(action)
action.setShortcut(QKeySequence("Ctrl+D"))
Beispiel #28
0
from anki.importing import TextImporter


def testFunction():
    file = u"/home/hollisma/.local/share/Anki2/addons21/myaddon/cards.txt"

    # Select deck
    did = mw.col.decks.id("Vocab")
    mw.col.decks.select(did)

    # Settings for cards
    m = mw.col.models.byName("Cloze")
    deck = mw.col.decks.get(did)
    deck['mid'] = m['id']
    mw.col.decks.save(deck)
    m['did'] = did
    mw.col.models.save(m)

    # Import cards
    ti = TextImporter(mw.col, file)
    ti.initMapping()
    ti.run()

    showInfo('Done!')


# Add button in dropdown menu
action = QAction('Add vocab cards!', mw)
action.triggered.connect(testFunction)
mw.form.menuTools.addAction(action)
Beispiel #29
0
def setup_menu(browser):
    a = QAction("Sync readings Audio", browser)
    browser.form.menuEdit.addAction(a)
    browser.connect(a, SIGNAL("triggered()"), run)
Beispiel #30
0
def add_menu_item(browser, m):
    action = QAction("Reset cards", browser.mw)
    action.triggered.connect(lambda: reset_selected_cards(browser))
    m.addAction(action)
Beispiel #31
0
    imp = 0
    noCard = 0
    for line in lines:
        ret = addBackNote(line, wrongMids, presentNids)
        if ret is True or ret == "no card":
            imp += 1
        if ret == "no card":
            noCard += 1
        cnt += 1
        if (cnt % 100) == 0:
            print(f"Saving the {cnt} first elements")
    if wrongMids:
        message.append(f"The wrong mids are {wrongMids}")
    if presentNids:
        message.append(f"Already contains note with nids {presentNids}")
    if imp:
        message.append(f"Succesfully imported back {imp} notes")
    else:
        message.append(f"No note imported")
    if noCard:
        message.append(
            f"{noCard} notes have generated 0 card. We added card 1 to them, and the tag NoteWithNoCard. You should edit them quickly, or «empty cards» will make them disappear."
        )
    showInfo("\n".join(message))


action = QAction(mw)
action.setText("add back")
mw.form.menuTools.addAction(action)
action.triggered.connect(addBack)
Beispiel #32
0
            d = difflib.Differ()
            diff = d.compare(css.splitlines(), modelcss.splitlines())
            sys.stdout.writelines(diff)
            assert modelcss == css, "CSS does not match for %s" % name


def get_collections():
    collection_dirs = []
    for listing in os.listdir(ANKI_BASE_PATH):
        listing_path = os.path.join(ANKI_BASE_PATH, listing)
        # Only look at directories, not files
        if not os.path.isdir(listing_path):
            continue
        # Ignore builtin addons/addons21 folders that are reserved
        if listing == "addons" or listing == "addons21":
            continue
        # Check that folder contains a collection, then add it
        db_path = os.path.join(listing_path, "collection.anki2")
        if os.path.isfile(db_path):
            collection_dirs.append(listing)
    return collection_dirs


if __name__ != '__main__':
    eaction = QAction("Export styles from Anki", mw)
    eaction.triggered.connect(save_collection_css)
    mw.form.menuTools.addAction(eaction)
    iaction = QAction("Import styles into Anki", mw)
    iaction.triggered.connect(push_collection_css)
    mw.form.menuTools.addAction(iaction)
Beispiel #33
0
    if model is not None:
        return

    model = mm.new(lpcg_models.NAME)
    for i in lpcg_models.FIELDS:
        field = mm.newField(i)
        mm.addField(model, field)
    t = mm.newTemplate(lpcg_models.TEMPLATE_NAME)
    t['qfmt'] = lpcg_models.FRONT_TEMPLATE
    t['afmt'] = lpcg_models.BACK_TEMPLATE
    mm.addTemplate(model, t)
    model['css'] = lpcg_models.STYLING
    model['sortf'] = lpcg_models.SORT_FIELD
    mm.add(model)

def open_dialog():
    "Launch the add-poem dialog."
    dialog = LPCGDialog(aqt.mw)
    dialog.exec_()

action = QAction(aqt.mw)
action.setText("Import &Lyrics/Poetry")
aqt.mw.form.menuTools.addAction(action)
action.triggered.connect(open_dialog)

addHook('profileLoaded', ensure_note_type)

# TODO: bug of unclear source with both end markers? only happens sometimes. I
# added a 'continue' which may fix this but seems unlikely because it's the
# wrong order.