Exemplo n.º 1
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)
Exemplo n.º 2
0
    def _createActions(self):
        makeFirst = QAction('Set item first', self)
        makeFirst.setShortcut(Qt.Key_1)
        makeFirst.setShortcutContext(Qt.WidgetWithChildrenShortcut)
        makeFirst.triggered.connect(self._makeSelectedFirst)
        self.addAction(makeFirst)

        add = QAction('Add item', self)
        add.setShortcut(Qt.Key_A)
        add.setShortcutContext(Qt.WidgetWithChildrenShortcut)
        add.triggered.connect(self._addNewItem)
        self.addAction(add)
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)
Exemplo n.º 4
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)
Exemplo n.º 5
0
    def _setupFastRepositionActions(self):
        """Add actions to the browser menu to move the cards up and down
        """
        # Set the actions active only if the cards are sorted by due date. This is necessary because the reposition
        # is done considering the current ordering in the browser
        mvtotopAction = QAction("Move to top", self.browser)
        mvtotopAction.setShortcut(
            shortcut(gc("shortcut: Move to top", "Alt+0")))
        mvtotopAction.triggered.connect(self.moveCardToTop)
        self.actions.append(mvtotopAction)

        mvuponeAction = QAction("Move one up", self.browser)
        mvuponeAction.setShortcut(
            shortcut(gc("shortcut: Move one up", "Alt+Up")))
        mvuponeAction.triggered.connect(self.moveCardUp)
        self.actions.append(mvuponeAction)

        mvdownoneAction = QAction("Move one down", self.browser)
        mvdownoneAction.setShortcut(
            shortcut(gc("shortcut: Move one down", "Alt+Down")))
        mvdownoneAction.triggered.connect(self.moveCardDown)
        self.actions.append(mvdownoneAction)

        self.browser.form.menu_Cards.addSeparator()
        self.browser.form.menu_Cards.addAction(mvtotopAction)
        self.browser.form.menu_Cards.addAction(mvuponeAction)
        self.browser.form.menu_Cards.addAction(mvdownoneAction)

        browse_mode_switch = self.browser.findChild(Switch)
        qconnect(browse_mode_switch.toggled, self._onBrowserModeToggled)

        isDueSort = self.browser.col.conf['sortType'] == 'cardDue'
        self.setActionsEnabled(isDueSort
                               and not browse_mode_switch.isChecked())
Exemplo n.º 6
0
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)
Exemplo n.º 7
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"))

def reschedule_all_cards():
    days_to_skip = dues_to_skip_relative()
    card_ids = cards_to_reschedule()
    for card_id in card_ids:
        print(card_id)
        reschedule_card(card_id, days_to_skip)
    showInfo("""Successfully rescheduled cards originally scheduled on
             unwanted days.""")


action = QAction("Reschedule Cards (Weekends and Holidays addon)", mw)
action.triggered.connect(reschedule_all_cards)
if config['shortcut']:
    action.setShortcut(QKeySequence(config['shortcut']))
mw.form.menuTools.addAction(action)

if config.get('execute_at_startup'):
    try:
        from aqt import gui_hooks
        gui_hooks.profile_did_open.append(reschedule_all_cards)
    except Exception:
        try:
            from anki.hooks import addHook
            addHook("profileLoaded", reschedule_all_cards)
        except Exception:
            showInfo("""Automatic rescheduling failed: incompatible version
                     If you see this message, please consider submitting a bug report at:
                     https://github.com/vasarmilan/AnkiWeekendsAndHolidays""")
Exemplo n.º 9
0
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
###############################################################################

import time

import anki.collection

import aqt
from aqt import mw
from aqt.qt import QAction

# overwrite autosave function with one that triggers faster and can be forced
SAVE_THRESHOLD = mw.addonManager.getConfig(__name__)['saveEveryNSeconds']
def newAutosave(self, force=False):
    if force or time.time() - self._lastSave > SAVE_THRESHOLD:
        self.save()
        return True

anki.collection._Collection.autosave = newAutosave

# install new menu item to force a save
action = QAction(mw)
action.setText("Save now")
action.setShortcut("Ctrl+S")
mw.form.menuCol.addAction(action)
action.triggered.connect(lambda: mw.col.autosave(True))
Exemplo n.º 10
0
    # This hook isn't in some supported versions of Anki yet,
    # so silently skip adding the warning if it's not available.
    # After we drop support for 2.1.48 and below, we can remove this check.
    if hasattr(aqt.gui_hooks, 'add_cards_did_change_note_type'):
        # lol at the line being too long because of the false positive lint
        # pylint: disable=no-member, line-too-long
        aqt.gui_hooks.add_cards_did_change_note_type.append(
            on_change_note_type)  # type: ignore
    aqt.gui_hooks.add_cards_did_init.append(on_add_init)


if aqt.mw is not None:
    # Set up menu option to begin a sync.
    action = QAction(aqt.mw)
    action.setText("Sync from &TiddlyWiki")
    action.setShortcut(QKeySequence("Shift+Y"))
    aqt.mw.form.menuTools.addAction(action)
    action.triggered.connect(begin_sync)  # type: ignore

    # Set up config dialog.
    aqt.mw.addonManager.setConfigAction(__name__, edit_settings)

    # Set up reminder message when user selects the TR note type to add notes.
    register_note_type_warning()

    # Set up macro exporter.
    def add_exporter(lst):
        lst.append(MACRO_EXPORTER_PROPERTIES)

    anki.hooks.exporters_list_created.append(add_exporter)
Exemplo n.º 11
0
        actions = [actions]
    for action in actions:
        for data in datas:
            if considerTable(data.name):
                getattr(data, action)()
    tooltip(f"Ended {action}")


action = QAction(mw)
action.setText("Anki to Readable")
mw.form.menuTools.addAction(action)
action.triggered.connect(lambda: run([
    "clarify"
    #,"view"
]))
action.setShortcut(QKeySequence("Ctrl+Shift+C"))

action = QAction(mw)
action.setText("Readable to anki")
mw.form.menuTools.addAction(action)
action.setShortcut(QKeySequence("Ctrl+Shift+R"))
action.triggered.connect(lambda: run(["rebuild"] +
                                     ([] if keepTable() else ["delete"])))

action = QAction(mw)
action.setText("Delete Readable tables")
mw.form.menuTools.addAction(action)
action.triggered.connect(lambda: run("delete"))

action = QAction(mw)
action.setText("Empty Readable tables")