Exemple #1
0
Fichier : sync.py Projet : dae/anki
    def _confirmFullSync(self):
        self.mw.progress.finish()
        if self.thread.localIsEmpty:
            diag = askUserDialog(
                _("Local collection has no cards. Download from AnkiWeb?"),
                [_("Download from AnkiWeb"), _("Cancel")])
            diag.setDefault(1)
        else:
            diag = askUserDialog(_("""\
Your decks here and on AnkiWeb differ in such a way that they can't \
be merged together, so it's necessary to overwrite the decks on one \
side with the decks from the other.

If you choose download, Anki will download the collection from AnkiWeb, \
and any changes you have made on your computer since the last sync will \
be lost.

If you choose upload, Anki will upload your collection to AnkiWeb, and \
any changes you have made on AnkiWeb or your other devices since the \
last sync to this device will be lost.

After all devices are in sync, future reviews and added cards can be merged \
automatically."""),
                [_("Upload to AnkiWeb"),
                 _("Download from AnkiWeb"),
                 _("Cancel")])
            diag.setDefault(2)
        ret = diag.run()
        if ret == _("Upload to AnkiWeb"):
            self.thread.fullSyncChoice = "upload"
        elif ret == _("Download from AnkiWeb"):
            self.thread.fullSyncChoice = "download"
        else:
            self.thread.fullSyncChoice = "cancel"
        self.mw.progress.start(immediate=True)
Exemple #2
0
    def _confirmFullSync(self):
        self.mw.progress.finish()
        if self.thread.localIsEmpty:
            diag = askUserDialog(
                _("Local collection has no cards. Download from AnkiWeb?"),
                [_("Download from AnkiWeb"), _("Cancel")])
            diag.setDefault(1)
        else:
            diag = askUserDialog(_("""\
Your decks here and on AnkiWeb differ in such a way that they can't \
be merged together, so it's necessary to overwrite the decks on one \
side with the decks from the other.

If you choose download, Anki will download the collection from AnkiWeb, \
and any changes you have made on your computer since the last sync will \
be lost.

If you choose upload, Anki will upload your collection to AnkiWeb, and \
any changes you have made on AnkiWeb or your other devices since the \
last sync to this device will be lost.

After all devices are in sync, future reviews and added cards can be merged \
automatically."""),
                [_("Upload to AnkiWeb"),
                 _("Download from AnkiWeb"),
                 _("Cancel")])
            diag.setDefault(2)
        ret = diag.run()
        if ret == _("Upload to AnkiWeb"):
            self.thread.fullSyncChoice = "upload"
        elif ret == _("Download from AnkiWeb"):
            self.thread.fullSyncChoice = "download"
        else:
            self.thread.fullSyncChoice = "cancel"
        self.mw.progress.start(immediate=True)
Exemple #3
0
def onCopyDeckClicked():
    
    deck = mw.col.decks.current()
    models = noteTypes(deck) # models to consider copying
    
    if not models:
        showInfo('Data models not found. Aborted. Try selecting a deck.')
        return
    dupMids = [unicode(m['id']) for m in models]  # assume "Clone all"

    modelNames = [m['name'] for m in models]
    q = '''%s %s
The current deck (%s) uses these Note Types:
%s
Do you want the copied deck to share these settings, or
do you want to clone the settings?
(Either way, media files will be shared, not cloned.)
    ''' % (ADDON_NAME, VERSION, deck['name'], ', '.join(modelNames))
    buttons = ['Clone all', 'Share all', 'Ask', 'Cancel']
    dlg = askUserDialog(q, buttons)
    dlg.setIcon(4)
    a = dlg.run()
    if a == 'Cancel':
        return
    elif a == 'Share all':
        dupMids = []
    elif a == 'Ask':
        q = 'Clone model %s?'
        buttons = ['Clone', 'Share', 'Cancel']
        for i in range(len(dupMids)-1, -1, -1):
            m = dupMids[i]
            dlg = askUserDialog(q % modelNames[i], buttons)
            dlg.setIcon(4)
            a = dlg.run()
            if a == 'Cancel':
                return
            elif a == 'Share':
                dupMids.pop(i)  # remove

        # TODO: Also ask whether to copy the media files. This is much trickier as it would have to modify the data to match.

    dd = DeckDuper(deck)
    _tmp = dd.dupDeck(dupMids)
    
    
    # refresh the screen so the new deck is visible
    mw.moveToState("deckBrowser")

    msg = 'Successfully copied %s notes, and generated %s cards (with fresh scheduling info). \n' % (dd.notesCopied, dd.cardsCopied)
    if dd.errorCount:
        s = list(dd.errors)
        summary = ' '.join(s)
        msg += 'Encountered %s errors. \n' % dd.errorCount
        msg += 'Summary: %s \n' % summary

    showInfo(msg)
Exemple #4
0
 def nextCard(self):
     elapsed = self.mw.col.timeboxReached()
     if elapsed:
         part1 = ngettext("%d card studied in", "%d cards studied in", elapsed[1]) % elapsed[1]
         mins = int(round(elapsed[0]/60))
         part2 = ngettext("%s minute.", "%s minutes.", mins) % mins
         fin = _("Finish")
         diag = askUserDialog("%s %s" % (part1, part2),
                          [_("Continue"), fin])
         diag.setIcon(QMessageBox.Information)
         if diag.run() == fin:
             return self.mw.moveToState("deckBrowser")
         self.mw.col.startTimebox()
     if self.cardQueue:
         # undone/edited cards to show
         c = self.cardQueue.pop()
         c.startTimer()
         self.hadCardQueue = True
     else:
         if self.hadCardQueue:
             # the undone/edited cards may be sitting in the regular queue;
             # need to reset
             self.mw.col.reset()
             self.hadCardQueue = False
         c = self.mw.col.sched.getCard()
     self.card = c
     clearAudioQueue()
     if not c:
         self.mw.moveToState("overview")
         return
     if self._reps is None or self._reps % 100 == 0:
         # we recycle the webview periodically so webkit can free memory
         self._initWeb()
     else:
         self._showQuestion()
Exemple #5
0
    def onUnbury(self):
        if self.mw.col.schedVer() == 1:
            self.mw.col.sched.unburyCardsForDeck()
            self.mw.reset()
            return

        sibs = self.mw.col.sched.haveBuriedSiblings()
        man = self.mw.col.sched.haveManuallyBuried()

        if sibs and man:
            opts = [
                _("Manually Buried Cards"),
                _("Buried Siblings"),
                _("All Buried Cards"),
                _("Cancel"),
            ]

            diag = askUserDialog(_("What would you like to unbury?"), opts)
            diag.setDefault(0)
            ret = diag.run()
            if ret == opts[0]:
                self.mw.col.sched.unburyCardsForDeck(type="manual")
            elif ret == opts[1]:
                self.mw.col.sched.unburyCardsForDeck(type="siblings")
            elif ret == opts[2]:
                self.mw.col.sched.unburyCardsForDeck(type="all")
        else:
            self.mw.col.sched.unburyCardsForDeck(type="all")

        self.mw.reset()
Exemple #6
0
    def onUnbury(self) -> None:
        if self.mw.col.schedVer() == 1:
            self.mw.col.sched.unburyCardsForDeck()
            self.mw.reset()
            return

        info = self.mw.col.sched.congratulations_info()
        if info.have_sched_buried and info.have_user_buried:
            opts = [
                tr(TR.STUDYING_MANUALLY_BURIED_CARDS),
                tr(TR.STUDYING_BURIED_SIBLINGS),
                tr(TR.STUDYING_ALL_BURIED_CARDS),
                tr(TR.ACTIONS_CANCEL),
            ]

            diag = askUserDialog(tr(TR.STUDYING_WHAT_WOULD_YOU_LIKE_TO_UNBURY),
                                 opts)
            diag.setDefault(0)
            ret = diag.run()
            if ret == opts[0]:
                self.mw.col.sched.unburyCardsForDeck(type="manual")
            elif ret == opts[1]:
                self.mw.col.sched.unburyCardsForDeck(type="siblings")
            elif ret == opts[2]:
                self.mw.col.sched.unburyCardsForDeck(type="all")
        else:
            self.mw.col.sched.unburyCardsForDeck(type="all")

        self.mw.reset()
Exemple #7
0
    def onUnbury(self):
        if self.mw.col.schedVer() == 1:
            self.mw.col.sched.unburyCardsForDeck()
            self.mw.reset()
            return

        sibs = self.mw.col.sched.haveBuriedSiblings()
        man = self.mw.col.sched.haveManuallyBuried()

        if sibs and man:
            opts = [_("Manually Buried Cards"),
                    _("Buried Siblings"),
                    _("All Buried Cards"),
                    _("Cancel")]

            diag = askUserDialog(_("What would you like to unbury?"), opts)
            diag.setDefault(0)
            ret = diag.run()
            if ret == opts[0]:
                self.mw.col.sched.unburyCardsForDeck(type="manual")
            elif ret == opts[1]:
                self.mw.col.sched.unburyCardsForDeck(type="siblings")
            elif ret == opts[2]:
                self.mw.col.sched.unburyCardsForDeck(type="all")
        else:
            self.mw.col.sched.unburyCardsForDeck(type="all")

        self.mw.reset()
Exemple #8
0
    def onUnbury(self) -> None:
        if self.mw.col.schedVer() == 1:
            self.mw.col.sched.unburyCardsForDeck()
            self.mw.reset()
            return

        info = self.mw.col.sched.congratulations_info()
        if info.have_sched_buried and info.have_user_buried:
            opts = [
                tr.studying_manually_buried_cards(),
                tr.studying_buried_siblings(),
                tr.studying_all_buried_cards(),
                tr.actions_cancel(),
            ]

            diag = askUserDialog(tr.studying_what_would_you_like_to_unbury(), opts)
            diag.setDefault(0)
            ret = diag.run()
            if ret == opts[0]:
                self.mw.col.sched.unburyCardsForDeck(type="manual")
            elif ret == opts[1]:
                self.mw.col.sched.unburyCardsForDeck(type="siblings")
            elif ret == opts[2]:
                self.mw.col.sched.unburyCardsForDeck(type="all")
        else:
            self.mw.col.sched.unburyCardsForDeck(type="all")

        self.mw.reset()
Exemple #9
0
    def onUnbury(self):
        if self.mw.col.schedVer() == 1:
            self.mw.col.sched.unburyCardsForDeck()
            self.mw.reset()
            return

        info = self.mw.col.sched.congratulations_info()
        if info.have_sched_buried and info.have_user_buried:
            opts = [
                _("Manually Buried Cards"),
                _("Buried Siblings"),
                _("All Buried Cards"),
                _("Cancel"),
            ]

            diag = askUserDialog(_("What would you like to unbury?"), opts)
            diag.setDefault(0)
            ret = diag.run()
            if ret == opts[0]:
                self.mw.col.sched.unburyCardsForDeck(type="manual")
            elif ret == opts[1]:
                self.mw.col.sched.unburyCardsForDeck(type="siblings")
            elif ret == opts[2]:
                self.mw.col.sched.unburyCardsForDeck(type="all")
        else:
            self.mw.col.sched.unburyCardsForDeck(type="all")

        self.mw.reset()
Exemple #10
0
def confirm_win(text="", conf="Yes", canc="Cancel", default=0):
    diag = askUserDialog(text, [conf, canc])
    diag.setDefault(default)
    ret = diag.run()
    if ret == conf:
        return True
    else:
        return False
Exemple #11
0
def dialogbox(text, buttons, icon=4, log=True):
    if log:
        L.debug("\n_____ Dialog _____\n" + text + "\n----------")
    if A.IN_ANKI:
        no_hourglass()
        b = askUserDialog(text, buttons)
        if icon: b.setIcon(icon)
        x = b.run()
    else:
        x = buttons[0]  # first button is default when testing
    return x
Exemple #12
0
def dialogbox(text, buttons, icon=4, log=True):
    if log:
        L.debug("\n_____ Dialog _____\n" + text + "\n----------")
    if A.IN_ANKI:    
        no_hourglass()
        b = askUserDialog(text, buttons)
        if icon: b.setIcon(icon)
        x = b.run()
    else:
        x = buttons[0]  # first button is default when testing
    return x
Exemple #13
0
 def ask_on_close(self, evt):
     # Compatibility: 2.1.0+
     opts = ["Cancel", "Discard", "Save"]
     diag = askUserDialog("Discard Changes?", opts, parent=self)
     diag.setDefault(0)
     ret = diag.run()
     if ret == opts[0]:
         evt.ignore()
     elif ret == opts[1]:
         evt.accept()
     elif ret == opts[2]:
         self.save()
         evt.ignore()
Exemple #14
0
def ask_user_to_decide_direction() -> FullSyncChoice:
    button_labels = [
        tr.sync_upload_to_ankiweb(),
        tr.sync_download_from_ankiweb(),
        tr.sync_cancel_button(),
    ]
    diag = askUserDialog(tr.sync_conflict_explanation(), button_labels)
    diag.setDefault(2)
    ret = diag.run()
    if ret == button_labels[0]:
        return FullSyncChoice.UPLOAD
    elif ret == button_labels[1]:
        return FullSyncChoice.DOWNLOAD
    else:
        return FullSyncChoice.CANCEL
Exemple #15
0
def ask_user_word(words):
    """
    Ask the user to choose between multiple word results.

    Returns the word selected or `None` if the user cancels the action.
    """

    buttons = map(QPushButton, words + ['Cancel'])
    dialog = askUserDialog('Multiple results were found. Which should be used?',
                           buttons)
    result = dialog.run()

    if result == 'Cancel':
        return None
    return result
Exemple #16
0
    def _confirmFullSync(self):
        diag = askUserDialog(_("""\
Your decks here and on AnkiWeb differ in such a way that they can't \
be merged together, so it's necessary to overwrite the decks on one \
side with the decks from the other.

Do you want to upload the decks from here, or download the decks \
from AnkiWeb?"""),
                [_("Upload to AnkiWeb"),
                 _("Download from AnkiWeb"),
                 _("Cancel")])
        diag.setDefault(2)
        ret = diag.run()
        if ret == _("Upload to AnkiWeb"):
            self.thread.fullSyncChoice = "upload"
        elif ret == _("Download from AnkiWeb"):
            self.thread.fullSyncChoice = "download"
        else:
            self.thread.fullSyncChoice = "cancel"