Beispiel #1
0
    def yield_one_word(self, filter_lang=''):
        self._preload_data = None
        # validate db still online
        if not self.on_select_kindle_db(False):
            showInfo(_trans("ENSURE USB"),
                     mw,
                     type="warning",
                     title=_trans("ANKINDLE"))
            return
        progress = ProgressManager(mw)
        progress.start(immediate=True)
        words = self.word_data
        for i, _ in enumerate(words):
            progress.update(
                _trans("IMPORTING") + "\n{} / {}".format(i + 1, len(words)), i,
                True)
            (id, word, stem, lang, added_tm, usage, title, authors,
             category) = _
            if lang and (
                    lang.upper() !=
                (filter_lang if filter_lang else self.current_mdx_lang)):
                continue
            yield id, word, stem, lang, added_tm, usage, title, authors, category

        progress.finish()
Beispiel #2
0
 def _downloadCardData(self):
     url = "{0}api/v1/cards.json?state=reviewed&sort=age&serializer=export&api_key={1}".format(SERVER, self._apiKey)
     progress = ProgressManager(mw)
     try:
         progress.start(label="Downloading new cards...", immediate=True)
         progress.update()
         stream = urllib2.urlopen(url)
         try:
             progress.update()
             return json.load(stream)
         finally:
             stream.close()
     finally:
         progress.finish()
Beispiel #3
0
 def _importCards(self, cards):
     """Import a group of cards."""
     self._skipped = 0
     self._importedIDs = []
     progress = ProgressManager(mw)
     try:
         progress.start(max=len(cards), label="Importing cards...")
         for i, card in enumerate(cards):
             self._importCard(card)
             progress.update(value=i)
         progress.update(label="Marking cards as imported...")
         self._markCardsAsExported()
     finally:
         progress.finish()
     self._summarizeImport()
Beispiel #4
0
def afterStateChange(state, oldState):
    '''
    Called when user alternates between deckBrowser, overview, review screens.
    It updates some variables and shows/hides the bar.
    '''
    lifeDrain = getLifeDrain()

    if not lifeDrain.disable:  # Enabled
        if not lifeDrain.timer:
            lifeDrain.timer = ProgressManager(mw).timer(
                1000, timerTrigger, True)
        lifeDrain.timer.stop()

        if lifeDrain.status['reviewed'] and state in ['overview', 'review']:
            lifeDrain.deckBarManager.recover()
        lifeDrain.status['reviewed'] = False
        lifeDrain.status['screen'] = state

        if state == 'deckBrowser':
            lifeDrain.deckBarManager.barVisible(False)
            lifeDrain.deckBarManager.setDeck(None)
        else:
            if mw.col is not None:
                lifeDrain.deckBarManager.setDeck(mw.col.decks.current()['id'])
            lifeDrain.deckBarManager.barVisible(True)

        if state == 'review':
            lifeDrain.timer.start()

    else:  # Disabled
        lifeDrain.deckBarManager.barVisible(False)
        if lifeDrain.timer is not None:
            lifeDrain.timer.stop()
Beispiel #5
0
 def _downloadCardData(self):
     url = "{0}api/v1/cards.json?state=reviewed&sort=age&serializer=export&api_key={1}".format(SERVER, self._apiKey)
     progress = ProgressManager(mw)
     try:
         progress.start(label="Downloading new cards...", immediate=True)
         progress.update()
         stream = urllib2.urlopen(url)
         try:
             progress.update()
             return json.load(stream)
         finally:
             stream.close()
     finally:
         progress.finish()
Beispiel #6
0
 def _importCards(self, cards):
     """Import a group of cards."""
     self._skipped = 0
     self._importedIDs = []
     progress = ProgressManager(mw)
     try:
         progress.start(max=len(cards), label="Importing cards...")
         for i, card in enumerate(cards):
             self._importCard(card)
             progress.update(value=i)
         progress.update(label="Marking cards as imported...")
         self._markCardsAsExported()
     finally:
         progress.finish()
     self._summarizeImport()
Beispiel #7
0
def main():
    """Initializes the Life Drain add-on."""
    make_timer = ProgressManager(mw).timer
    lifedrain = Lifedrain(make_timer, mw, qt)

    setup_shortcuts(lifedrain)
    setup_state_change(lifedrain)
    setup_deck_browser(lifedrain)
    setup_overview(lifedrain)
    setup_review(lifedrain)

    mw.addonManager.setConfigAction(__name__, lifedrain.global_settings)
    hooks.addHook('LifeDrain.recover', lifedrain.deck_manager.recover_life)
Beispiel #8
0
    def mark_mature(self):
        progress = ProgressManager(mw)
        progress.start(immediate=True)
        progress.update(_trans("Marking Words as Manure"))

        category = 100 if self.tabs.currentIndex() else 0
        if category:
            tableView = self.learned_view
        else:
            tableView = self.new_view

        for idx in tableView.selectionModel().selectedRows():
            kindle_word_id = tableView.model().word_data[idx.row()][0]
            self.parent().db.update_word_mature(kindle_word_id, 100 if not category else 0)

        progress.finish()
        self.refresh()
def import_words():
    """
    Import words from vocab.db into the deck "Vocabulary Builder".
    """
    db = DEFAULT_OS_X_DB
    try:
        vocabdb = sqlite3.connect(db)
    except sqlite3.OperationalError as e:
        showInfo(f"Error connecting to database: {e}")
        return

    cursor = vocabdb.cursor()
    query = '''
        SELECT WORDS.word, WORDS.stem, LOOKUPS.usage
        FROM WORDS
        JOIN LOOKUPS ON WORDS.id = LOOKUPS.word_key
        WHERE WORDS.lang=\'fr\''''
    cursor.execute(query)
    results = cursor.fetchall()

    mw.checkpoint("Importing words from Kindle")

    progress = ProgressManager(mw)
    progress.start(immediate=True)
    # Create an Anki card for each word
    word_num = 0
    total_words = len(results)
    for result in results:
        word_num = word_num + 1
        word = result[0]
        progress.update(f"Importing word {word_num} of {total_words}: {word}")
        stem = result[1]
        usage = result[2]
        create_note(word, stem, usage)

    # Create an Anki package based on the contents
    # vocab_package = genanki.Package(vocab_deck)
    # vocab_package.write_to_file('output.apkg')
    vocab_deck.write_to_collection_from_addon()

    # Reset the word database so new words show up
    progress.finish()
    mw.reset()

    vocabdb.close()