Ejemplo n.º 1
0
def anki_import_init():
    import_action = QAction("CrowdAnki: Import from disk", mw)
    import_action.triggered.connect(on_import_action)

    github_import_action = QAction("CrowdAnki: Import from Github", mw)
    github_import_action.triggered.connect(lambda : GithubImporter.on_github_import_action(mw.col))

    # -2 supposed to give the separator after import/export section, so button should be at the end of this section
    mw.form.menuCol.insertActions(mw.form.menuCol.actions()[-2], [import_action, github_import_action])
Ejemplo n.º 2
0
def anki_import_init():
    import_action = QAction("Import CrowdAnki Json", mw)
    import_action.triggered.connect(on_import_action)

    # -2 supposed to give the separator after import/export section, so button should be at the end of this section
    mw.form.menuCol.insertActions(mw.form.menuCol.actions()[-2],
                                  [import_action])
Ejemplo n.º 3
0
    def init_menu(self):
        # init actions

        if not self.main_menu:
            self.main_menu = QMenu(
                _trans("AnKindle") +
                u" +" if self.ext_unlocked else _trans("AnKindle"),
                mw.form.menuTools,
            )
            mw.form.menuTools.addMenu(self.main_menu)

            self.action_show_vocab_dialog = QAction(
                _trans("SHOW VOCAB IMPORT"), self.main_menu)
            self.action_show_vocab_dialog.triggered.connect(
                self.on_show_vocab_dialog)
            self.action_show_vocab_dialog.setShortcut("CTRL+K")
            self.main_menu.addAction(self.action_show_vocab_dialog)

            if self.ext_available:
                self.action_show_clipping_dialog = QAction(
                    _trans("SHOW CLIPPING IMPORT"), self.main_menu)
                self.action_show_clipping_dialog.triggered.connect(
                    self.on_show_clipping_dialog)
                self.action_show_clipping_dialog.setShortcut("CTRL+L")
                self.main_menu.addAction(self.action_show_clipping_dialog)

            self.main_menu.addSeparator()
            if self.ext_available:
                if not self.ext_unlocked:
                    action_upgrade = QAction(_trans("UPGRADE TO PLUS"),
                                             self.main_menu)
                    action_upgrade.triggered.connect(
                        partial(AnKindlePlus.call_purchase_dialog, mw))
                    self.main_menu.addAction(action_upgrade)
                if self.sn_register_dlg:
                    action_upgrade = QAction(_trans("REGISTER PLUS"),
                                             self.main_menu)
                    AnKindlePlus._bind_qt_slots(action_upgrade.triggered,
                                                self.on_show_enter_sn_dialog)
                    self.main_menu.addAction(action_upgrade)
Ejemplo n.º 4
0
class AnKindleAddon:
    def __init__(self):
        self.on_start()
        # variables
        self.main_menu = None
        self.action_show_vocab_dialog = None
        self.action_show_clipping_dialog = None
        # self.main_menu_action = None

        if not self.avl_col_model_names:
            importFile(mw, DEFAULT_TEMPLATE)

        if self.ext_available and not self.ext_unlocked:
            self.sn_register_dlg = AnKindlePlus.SNReg(mw, "ANKINDLE_PLUS")
        else:
            self.sn_register_dlg = None

    def perform_hooks(self, func):
        # func('reviewCleanup', self.on_review_cleanup)
        func('profileLoaded', self.on_profile_loaded)
        # func('afterStateChange', self.after_anki_state_change)

    def on_profile_loaded(self):
        self.init_menu()

    def on_start(self):
        if self.ext_available:
            AnKindlePlus.start_AnKindle_plus()

    def init_menu(self):
        # init actions

        if not self.main_menu:
            self.main_menu = QMenu(
                _trans("AnKindle") +
                u" +" if self.ext_unlocked else _trans("AnKindle"),
                mw.form.menuTools,
            )
            mw.form.menuTools.addMenu(self.main_menu)

            self.action_show_vocab_dialog = QAction(
                _trans("SHOW VOCAB IMPORT"), self.main_menu)
            self.action_show_vocab_dialog.triggered.connect(
                self.on_show_vocab_dialog)
            self.action_show_vocab_dialog.setShortcut("CTRL+K")
            self.main_menu.addAction(self.action_show_vocab_dialog)

            if self.ext_available:
                self.action_show_clipping_dialog = QAction(
                    _trans("SHOW CLIPPING IMPORT"), self.main_menu)
                self.action_show_clipping_dialog.triggered.connect(
                    self.on_show_clipping_dialog)
                self.action_show_clipping_dialog.setShortcut("CTRL+L")
                self.main_menu.addAction(self.action_show_clipping_dialog)

            self.main_menu.addSeparator()
            if self.ext_available:
                if not self.ext_unlocked:
                    action_upgrade = QAction(_trans("UPGRADE TO PLUS"),
                                             self.main_menu)
                    action_upgrade.triggered.connect(
                        partial(AnKindlePlus.call_purchase_dialog, mw))
                    self.main_menu.addAction(action_upgrade)
                if self.sn_register_dlg:
                    action_upgrade = QAction(_trans("REGISTER PLUS"),
                                             self.main_menu)
                    AnKindlePlus._bind_qt_slots(action_upgrade.triggered,
                                                self.on_show_enter_sn_dialog)
                    self.main_menu.addAction(action_upgrade)

    @property
    def ext_available(self):
        return _try_ext_module()

    @property
    def ext_unlocked(self):
        if self.ext_available:
            return AnKindlePlus.KuangKuang.Unlocked()
        return False

    def on_show_enter_sn_dialog(self, *args):
        self.sn_register_dlg.exec_()

    def on_show_clipping_dialog(self):
        mw.onAddCard()

    def on_show_vocab_dialog(self):
        self.vocab_dlg = Window(
            mw,
            self.avl_col_model_names,
            self.avl_decks,
        )
        if self.ext_unlocked:
            title = "{} Plus - {}".format(_trans("AnKindle"), __version__)
            if AnKindlePlus.BETA_VERSION:
                title += " (BETA{})".format(
                    AnKindlePlus.BETA_VERSION_TEST_INDEX)
            self.vocab_dlg.setWindowTitle(title)
        else:
            self.vocab_dlg.setWindowTitle("{} - {}".format(
                _trans("AnKindle"), __version__))
        self.vocab_dlg.exec_()

    def avl_col_model_names(self):
        _ = []
        for mid, m_values in self.collection.models.models.items():
            if not set([f.lower() for f in MUST_IMPLEMENT_FIELDS]).difference(
                    set([f[u'name'] for f in m_values[u'flds']])):
                _.append(mid)
        return [v for k, v in self.collection.models.models.items() if k in _]

    def avl_decks(self):
        _ = []
        for did, d_values in self.collection.decks.decks.items():
            _.append(did)
        return [v for k, v in self.collection.decks.decks.items() if k in _]

    @property
    def collection(self):
        """

        :rtype: _Collection
        """

        return mw.col
Ejemplo n.º 5
0
def setup_menu_option():
    action = QAction('Text Wrapper Settings...', mw)
    action.triggered.connect(invoke_options)
    mw.form.menuTools.addAction(action)
Ejemplo n.º 6
0
from aqt import mw, QAction, QKeySequence
from .mainwindow import MainWindow
from . import startmodule


def start():
    startmodule.start()


def debugStart():
    from . import debugreload
    debugreload.reloadAll(__name__)
    startmodule.start()


startAction = QAction("English word manager: start", mw)
startAction.setShortcut(QKeySequence('Ctrl+M'))
startAction.triggered.connect(debugStart)
mw.form.menuTools.addSeparator()
mw.form.menuTools.addAction(startAction)