Esempio n. 1
0
 def _linkHandler(self, url):
     if ":" in url:
         (cmd, arg) = url.split(":")
     else:
         cmd = url
     if cmd == "open":
         self._selDeck(arg)
     elif cmd == "opts":
         self._showOptions(arg)
     elif cmd == "shared":
         self._onShared()
     elif cmd == "import":
         self.mw.onImport()
     elif cmd == "lots":
         openHelp("using-decks-appropriately")
     elif cmd == "hidelots":
         self.mw.pm.profile['hideDeckLotsMsg'] = True
         self.refresh()
     elif cmd == "create":
         deck = getOnlyText(_("Name for deck:"))
         if deck:
             self.mw.col.decks.id(deck)
             self.refresh()
     elif cmd == "drag":
         draggedDeckDid, ontoDeckDid = arg.split(',')
         self._dragDeckOnto(draggedDeckDid, ontoDeckDid)
     elif cmd == "collapse":
         self._collapse(arg)
Esempio n. 2
0
 def renameGroup(self):
     old = self.conf['name']
     name = getOnlyText(_("New name:"), default=old)
     if not name or name == old:
         return
     self.conf['name'] = name
     self.loadConfs()
Esempio n. 3
0
 def onRename(self):
     item = self.form.tree.currentItem()
     old = unicode(item.text(0))
     oldfull = self.fullNames[old]
     gid = self.groupMap[old]
     txt = getOnlyText(_("Rename to:"), self, default=oldfull)
     if txt and not txt.startswith("::") and not txt.endswith("::"):
         self._rename(oldfull, txt, gid, item)
Esempio n. 4
0
 def onRename(self):
     name = getOnlyText(_("New name:"), default=self.card.template()["name"])
     if not name:
         return
     if name in [c.template()["name"] for c in self.cards if c.template()["ord"] != self.ord]:
         return showWarning(_("That name is already used."))
     self.card.template()["name"] = name
     self.tabs.setTabText(self.tabs.currentIndex(), name)
Esempio n. 5
0
 def onAddCard(self):
     name = getOnlyText(_("Name:"))
     if not name:
         return
     if name in [c.template()['name'] for c in self.cards]:
         return showWarning(_("That name is already used."))
     t = self.mm.newTemplate(name)
     self.mm.addTemplate(self.model, t)
     self.redraw()
Esempio n. 6
0
File: main.py Progetto: dae/anki
 def onAddProfile(self):
     name = getOnlyText(_("Name:")).strip()
     if name:
         if name in self.pm.profiles():
             return showWarning(_("Name exists."))
         if not self.profileNameOk(name):
             return
         self.pm.create(name)
         self.pm.name = name
         self.refreshProfilesList()
Esempio n. 7
0
 def onRename(self):
     name = getOnlyText(_("New name:"),
                        default=self.card.template()['name'])
     if not name:
         return
     if name in [c.template()['name'] for c in self.cards
                 if c.template()['ord'] != self.ord]:
         return showWarning(_("That name is already used."))
     self.card.template()['name'] = name
     self.redraw()
Esempio n. 8
0
 def _uniqueName(self, prompt, ignoreOrd=None):
     txt = getOnlyText(prompt)
     if not txt:
         return
     for f in self.model["flds"]:
         if ignoreOrd is not None and f["ord"] == ignoreOrd:
             continue
         if f["name"] == txt:
             showWarning(_("That field name is already used."))
             return
     return txt
Esempio n. 9
0
 def _rename(self, did):
     self.mw.checkpoint(_("Rename Deck"))
     deck = self.mw.col.decks.get(did)
     newName = getOnlyText(_("New deck name:"), default=deck['name'])
     newName = newName.replace("'", "").replace('"', "")
     if not newName:
         return
     if deck in self.mw.col.decks.allNames():
         return showWarning(_("That deck already exists."))
     self.mw.col.decks.rename(deck, newName)
     self.show()
Esempio n. 10
0
 def onAddDeck(self):
     row = self.form.list.currentRow()
     if row < 0:
         default = self.form.filter.text()
     else:
         default = self.names[self.form.list.currentRow()]
     n = getOnlyText(_("New deck name:"), default=default)
     if n:
         self.mw.col.decks.id(n)
         self.name = n
         QDialog.accept(self)
Esempio n. 11
0
 def _uniqueName(self, prompt, ignoreOrd=None, old=""):
     txt = getOnlyText(prompt, default=old)
     if not txt:
         return
     for f in self.model['flds']:
         if ignoreOrd is not None and f['ord'] == ignoreOrd:
             continue
         if f['name'] == txt:
             showWarning(_("That field name is already used."))
             return
     return txt
Esempio n. 12
0
 def onRenameProfile(self):
     name = getOnlyText(_("New name:"), default=self.pm.name)
     if not name:
         return
     if name == self.pm.name:
         return
     if name in self.pm.profiles():
         return showWarning(_("Name exists."))
     if not self.profileNameOk(name):
         return
     self.pm.rename(name)
     self.refreshProfilesList()
Esempio n. 13
0
 def addGroup(self):
     name = getOnlyText(_("New options group name:"))
     if not name:
         return
     # first, save currently entered data to current conf
     self.saveConf()
     # then clone the conf
     id = self.mw.col.decks.confId(name, cloneFrom=self.conf)
     # set the deck to the new conf
     self.deck['conf'] = id
     # then reload the conf list
     self.loadConfs()
Esempio n. 14
0
 def _rename(self, did):
     self.mw.checkpoint(_("Rename Deck"))
     deck = self.mw.col.decks.get(did)
     oldName = deck['name']
     newName = getOnlyText(_("New deck name:"), default=oldName)
     newName = newName.replace('"', "")
     if not newName or newName == oldName:
         return
     try:
         self.mw.col.decks.rename(deck, newName)
     except DeckRenameError, e:
         return showWarning(e.description)
Esempio n. 15
0
 def onAddDeck(self):
     row = self.form.list.currentRow()
     if row < 0:
         default = self.form.filter.text()
     else:
         default = self.names[self.form.list.currentRow()]
     n = getOnlyText(_("New deck name:"), default=default)
     if n:
         self.mw.col.decks.id(n)
         self.name = n
         # make sure we clean up reset hook when manually exiting
         remHook('reset', self.onReset)
         QDialog.accept(self)
Esempio n. 16
0
def addtemplate():
    '''Dialog to add a new template file.'''
    name = getOnlyText("Please choose a name for your new LilyPond template:")

    if not lilypondNameRegexp.match(name):
        showInfo("Empty template name or invalid characters.")
        return

    if os.path.exists(tpl_file(name)):
        showInfo("A template with that name already exists.")

    setTemplate(name, lilypondTemplate)
    mw.addonManager.onEdit(tpl_file(name))
Esempio n. 17
0
    def onDelimiter(self):
        str = getOnlyText(_("""\
By default, Anki will detect the character between fields, such as
a tab, comma, and so on. If Anki is detecting the character incorrectly,
you can enter it here. Use \\t to represent tab."""),
                self, help="importing") or "\t"
        str = str.replace("\\t", "\t")
        str = str.encode("ascii")
        self.hideMapping()
        def updateDelim():
            self.importer.delimiter = str
            self.importer.updateDelimiter()
        self.showMapping(hook=updateDelim)
        self.updateDelimiterButtonText()
Esempio n. 18
0
 def onReorder(self):
     n = len(self.cards)
     cur = self.card.template()["ord"] + 1
     pos = getOnlyText(_("Enter new card position (1...%s):") % n, default=str(cur))
     if not pos:
         return
     try:
         pos = int(pos)
     except ValueError:
         return
     if pos < 1 or pos > n:
         return
     if pos == cur:
         return
     pos -= 1
     self.mm.moveTemplate(self.model, self.card.template(), pos)
     self.ord = pos
     self.redraw()
Esempio n. 19
0
 def onPosition(self, delta=-1):
     l = len(self.model['flds'])
     txt = getOnlyText(_("New position (1...%d):") % l)
     if not txt:
         return
     try:
         pos = int(txt)
     except ValueError:
         return
     if not 0 < pos <= l:
         return
     self.saveField()
     f = self.model['flds'][self.currentIdx]
     self.mw.progress.start()
     self.mm.moveField(self.model, f, pos-1)
     self.mw.progress.finish()
     self.fillFields()
     self.form.fieldList.setCurrentRow(pos-1)
Esempio n. 20
0
    def onDelimiter(self):
        str = getOnlyText(_("""\
By default, Anki will detect the character between fields, such as
a tab, comma, and so on. If Anki is detecting the character incorrectly,
you can enter it here. Use \\t to represent tab."""),
                self, help="importing") or "\t"
        str = str.replace("\\t", "\t")
        if len(str) > 1:
            showWarning(_(
                "Multi-character separators are not supported. "
                "Please enter one character only."))
            return
        self.hideMapping()
        def updateDelim():
            self.importer.delimiter = str
            self.importer.updateDelimiter()
        self.showMapping(hook=updateDelim)
        self.updateDelimiterButtonText()
Esempio n. 21
0
def copyCards(nids):
    mw.checkpoint("Copy Cards")
    mw.progress.start()

    # Get desired deck name from input box
    deckName = getOnlyText(_("New deck name:"), default="Copied Cards")
    if not deckName:
        return
    deckName = deckName.replace('"', "")

    # Create new deck with name from input box
    deck = mw.col.decks.get(mw.col.decks.id(deckName))

    # Copy notes
    for nid in nids:
        #print "Found note: %s" % (nid)
        note = mw.col.getNote(nid)
        model = note.model()

        # Assign model to deck
        mw.col.decks.select(deck['id'])
        mw.col.decks.get(deck)['mid'] = model['id']
        mw.col.decks.save(deck)

        # Assign deck to model
        mw.col.models.setCurrent(model)
        mw.col.models.current()['did'] = deck['id']
        mw.col.models.save(model)

        # Create new note
        note_copy = mw.col.newNote()
        # Copy tags and fields (all model fields) from original note
        note_copy.tags = note.tags
        note_copy.fields = note.fields

        # Refresh note and add to database
        note_copy.flush()
        mw.col.addNote(note_copy)

    # Reset collection and main window
    mw.col.reset()
    mw.reset()
    mw.progress.finish()
Esempio n. 22
0
 def onPosition(self, delta=-1):
     idx = self.currentIdx
     l = len(self.model['flds'])
     txt = getOnlyText(_("New position (1...%d):") % l, default=str(idx+1))
     if not txt:
         return
     try:
         pos = int(txt)
     except ValueError:
         return
     if not 0 < pos <= l:
         return
     self.saveField()
     f = self.model['flds'][self.currentIdx]
     self.mw.progress.start()
     self.mm.moveField(self.model, f, pos-1)
     self.mw.progress.finish()
     self.fillFields()
     self.form.fieldList.setCurrentRow(pos-1)
Esempio n. 23
0
 def onReorder(self):
     n = len(self.cards)
     cur = self.card.template()['ord'] + 1
     pos = getOnlyText(_("Enter new card position (1...%s):") % n,
                       default=str(cur))
     if not pos:
         return
     try:
         pos = int(pos)
     except ValueError:
         return
     if pos < 1 or pos > n:
         return
     if pos == cur:
         return
     pos -= 1
     self.mm.moveTemplate(self.model, self.card.template(), pos)
     self.ord = pos
     self.redraw()
Esempio n. 24
0
 def onCram(self, search=""):
     import aqt.dyndeckconf
     n = 1
     decks = self.col.decks.allNames()
     while _("Filtered Deck %d") % n in decks:
         n += 1
     name = _("Filtered Deck %d") % n
     name = getOnlyText(_("New deck name:"), default=name)
     if not name:
         return
     if name in decks:
         showWarning(_("The provided name was already in use."))
         return
     did = self.col.decks.newDyn(name)
     diag = aqt.dyndeckconf.DeckConf(self, first=True, search=search)
     if not diag.ok:
         # user cancelled first config
         self.col.decks.rem(did)
     else:
         self.moveToState("overview")
Esempio n. 25
0
 def onCram(self, search=""):
     import aqt.dyndeckconf
     n = 1
     decks = self.col.decks.allNames()
     while _("Filtered Deck %d") % n in decks:
         n += 1
     name = _("Filtered Deck %d") % n
     name = getOnlyText(_("New deck name:"), default=name)
     if not name:
         return
     if name in decks:
         showWarning(_("The provided name was already in use."))
         return
     did = self.col.decks.newDyn(name)
     diag = aqt.dyndeckconf.DeckConf(self, first=True, search=search)
     if not diag.ok:
         # user cancelled first config
         self.col.decks.rem(did)
     else:
         self.moveToState("overview")
Esempio n. 26
0
 def onReorder(self):
     """Asks user for a new position for current template. Move to this position if it is a valid position."""
     n = len(self.cards)
     cur = self.card.template()['ord'] + 1
     pos = getOnlyText(_("Enter new card position (1...%s):") % n,
                       default=str(cur))
     if not pos:
         return
     try:
         pos = int(pos)
     except ValueError:
         return
     if pos < 1 or pos > n:
         return
     if pos == cur:
         return
     pos -= 1
     self.mm.moveTemplate(self.model, self.card.template(), pos)
     self.ord = pos
     self.redraw()
Esempio n. 27
0
 def _uniqueName(
     self, prompt: str, ignoreOrd: Optional[int] = None, old: str = ""
 ) -> Optional[str]:
     txt = getOnlyText(prompt, default=old).replace('"', "").strip()
     if not txt:
         return None
     if txt[0] in "#^/":
         showWarning(tr(TR.FIELDS_NAME_FIRST_LETTER_NOT_VALID))
         return None
     for letter in """:{"}""":
         if letter in txt:
             showWarning(tr(TR.FIELDS_NAME_INVALID_LETTER))
             return None
     for f in self.model["flds"]:
         if ignoreOrd is not None and f["ord"] == ignoreOrd:
             continue
         if f["name"] == txt:
             showWarning(tr(TR.FIELDS_THAT_FIELD_NAME_IS_ALREADY_USED))
             return None
     return txt
Esempio n. 28
0
 def _linkHandler(self, url):
     if ":" in url:
         (cmd, arg) = url.split(":")
     else:
         cmd = url
     if cmd == "open":
         self._selDeck(arg)
     elif cmd == "opts":
         self._showOptions(arg)
     elif cmd == "shared":
         self._onShared()
     elif cmd == "import":
         self.mw.onImport()
     elif cmd == "lots":
         openHelp("using-decks-appropriately")
     elif cmd == "hidelots":
         self.mw.pm.profile['hideDeckLotsMsg'] = True
         self.refresh()
     elif cmd == "create":
         deck = getOnlyText(_("Name for deck:"))
         if deck:
             self.mw.col.decks.id(deck)
             self.refresh()
     elif cmd == "drag":
         draggedDeckDid, ontoDeckDid = arg.split(',')
         self._dragDeckOnto(draggedDeckDid, ontoDeckDid)
     elif cmd == "collapse":
         self._collapse(arg)
     elif cmd == "add_from_text":
         print(cmd, arg)
         self._add_from_text(arg)
     elif cmd == "add_from_file":
         print(cmd)
         self._add_from_file()
     elif cmd == "import_model":
         self._import_model()
     elif cmd == 'change_model':
         self._change_model(arg)
     elif cmd == 'smart_add':
         self._smart_add()
     return False
Esempio n. 29
0
    def onDelimiter(self):
        str = getOnlyText(_("""\
By default, Anki will detect the character between fields, such as
a tab, comma, and so on. If Anki is detecting the character incorrectly,
you can enter it here. Use \\t to represent tab."""),
                          self,
                          help="importing") or "\t"
        str = str.replace("\\t", "\t")
        if len(str) > 1:
            showWarning(
                _("Multi-character separators are not supported. "
                  "Please enter one character only."))
            return
        self.hideMapping()

        def updateDelim():
            self.importer.delimiter = str
            self.importer.updateDelimiter()

        self.showMapping(hook=updateDelim)
        self.updateDelimiterButtonText()
Esempio n. 30
0
 def _uniqueName(self,
                 prompt: str,
                 ignoreOrd: Optional[int] = None,
                 old: str = "") -> Optional[str]:
     txt = getOnlyText(prompt, default=old).replace('"', "").strip()
     if not txt:
         return None
     if txt[0] in "#^/":
         showWarning(tr.fields_name_first_letter_not_valid())
         return None
     for letter in """:{"}""":
         if letter in txt:
             showWarning(tr.fields_name_invalid_letter())
             return None
     for f in self.model["flds"]:
         if ignoreOrd is not None and f["ord"] == ignoreOrd:
             continue
         if f["name"] == txt:
             showWarning(tr.fields_that_field_name_is_already_used())
             return None
     return txt
Esempio n. 31
0
    def onDelimiter(self):
        str = (getOnlyText(
            tr(TR.IMPORTING_BY_DEFAULT_ANKI_WILL_DETECT_THE),
            self,
            help="importing",
        ) or "\t")
        str = str.replace("\\t", "\t")
        if len(str) > 1:
            showWarning(
                tr(TR.
                   IMPORTING_MULTICHARACTER_SEPARATORS_ARE_NOT_SUPPORTED_PLEASE
                   ))
            return
        self.hideMapping()

        def updateDelim():
            self.importer.delimiter = str
            self.importer.updateDelimiter()

        self.showMapping(hook=updateDelim)
        self.updateDelimiterButtonText()
Esempio n. 32
0
def _rename(self, did, newName=None):
    self.mw.checkpoint(_("Rename Deck"))
    deck = self.mw.col.decks.get(did)
    oldName = deck['name']
    if newName is None:
        newName = getOnlyText(_("New deck name:"), default=oldName)
        newName = newName.replace('"', "")
    if not newName or newName == oldName:
        return
    try:
        if newName in self.mw.col.decks.allNames():
            merge = askUser(
                _("The deck %s already exists. Do you want to merge %s in it ?"
                  ) % (newName, oldName))
            if merge:
                self.mw.col.decks.rename(deck, newName)
        else:
            self.mw.col.decks.rename(deck, newName)

    except DeckRenameError as e:
        return showWarning(e.description)
    self.show()
Esempio n. 33
0
 def onAddDeck(self) -> None:
     row = self.form.list.currentRow()
     if row < 0:
         default = self.form.filter.text()
     else:
         default = self.names[self.form.list.currentRow()]
     n = getOnlyText(tr(TR.DECKS_NEW_DECK_NAME), default=default)
     n = n.strip()
     if n:
         try:
             did = self.mw.col.decks.id(n)
         except DeckIsFilteredError as err:
             showWarning(str(err))
             return
         # deck name may not be the same as user input. ex: ", ::
         self.name = self.mw.col.decks.name(did)
         # make sure we clean up reset hook when manually exiting
         gui_hooks.state_did_reset.remove(self.onReset)
         if self.mw.state == "deckBrowser":
             self.mw.deckBrowser.refresh()
         gui_hooks.sidebar_should_refresh_decks()
         QDialog.accept(self)
Esempio n. 34
0
 def onReorder(self):
     n = len(self.templates)
     template = self.current_template()
     current_pos = self.templates.index(template) + 1
     pos = getOnlyText(_("Enter new card position (1...%s):") % n,
                       default=str(current_pos))
     if not pos:
         return
     try:
         pos = int(pos)
     except ValueError:
         return
     if pos < 1 or pos > n:
         return
     if pos == current_pos:
         return
     new_idx = pos - 1
     if not self.change_tracker.mark_schema():
         return
     self.mm.reposition_template(self.model, template, new_idx)
     self.ord = new_idx
     self.redraw_everything()
Esempio n. 35
0
 def _linkHandler(self, url):
     if ":" in url:
         (cmd, arg) = url.split(":")
     else:
         cmd = url
     if cmd == "open":
         self._selDeck(arg)
     elif cmd == "opts":
         self._showOptions(arg)
     elif cmd == "shared":
         self._onShared()
     elif cmd == "import":
         self.mw.onImport()
     elif cmd == "create":
         deck = getOnlyText(_("Name for deck:"))
         if deck:
             self.mw.col.decks.id(deck)
             self.refresh()
     elif cmd == "drag":
         draggedDeckDid, ontoDeckDid = arg.split(',')
         self._dragDeckOnto(draggedDeckDid, ontoDeckDid)
     elif cmd == "collapse":
         self._collapse(arg)
Esempio n. 36
0
 def _linkHandler(self, url):
     if ":" in url:
         (cmd, arg) = url.split(":")
     else:
         cmd = url
     if cmd == "open":
         self._selDeck(arg)
     elif cmd == "opts":
         self._showOptions(arg)
     elif cmd == "shared":
         self._onShared()
     elif cmd == "import":
         self.mw.onImport()
     elif cmd == "create":
         deck = getOnlyText(_("New deck name:"))
         if deck:
             self.mw.col.decks.id(deck)
             self.refresh()
     elif cmd == "drag":
         draggedDeckDid, ontoDeckDid = arg.split(',')
         self._dragDeckOnto(draggedDeckDid, ontoDeckDid)
     elif cmd == "collapse":
         self._collapse(arg)
def addPrefix(cids):
    mw.checkpoint("Add prefix")
    mw.progress.start()

    prefix = getOnlyText(_("Prefix to add:"), default="prefix")
    # Copy notes
    for cid in cids:
        print "Found card: %s" % (cid)
        card = mw.col.getCard(cid)
        did = card.odid or card.did
        deckName = mw.col.decks.name(did)
        deck = mw.col.decks.get(did, default=False)
        assert deck
        newDeckName = "%s::%s" % (prefix, deckName)
        newDid = mw.col.decks.id(newDeckName, type=deck)
        card.did = newDid
        card.flush()

    # Reset collection and main window
    mw.col.decks.flush()
    mw.col.reset()
    mw.reset()
    tooltip(_("""Prefix added."""))
Esempio n. 38
0
def onReorder(self):
    n = len(self.cards)
    cur = self.ord + 1
    pos = getOnlyText(_("Enter new card position (1...%s):") % n,
                      default=str(cur))
    idx = self.ord
    originalMeta = self.newTemplatesData[idx]
    if not pos:
        return
    try:
        pos = int(pos)
    except ValueError:
        return
    if pos < 1 or pos > n:
        return
    if pos == cur:
        return
    pos -= 1
    self.mm.moveTemplate(self.model, self.card.template(), pos)
    del self.newTemplatesData[idx]
    self.newTemplatesData.insert(pos, originalMeta)
    self.ord = pos
    self.redraw()
Esempio n. 39
0
    def _rename_tag(self, item: "aqt.browser.SidebarItem") -> None:
        old_name = item.name
        new_name = getOnlyText(tr(TR.ACTIONS_NEW_NAME), default=old_name)
        if new_name == old_name or not new_name:
            return

        def do_rename():
            return self.col.tags.rename_tag(old_name, new_name)

        def on_done(fut: Future):
            self.mw.requireReset(reason=ResetReason.BrowserAddTags, context=self)
            self.browser.model.endReset()

            count = fut.result()
            if not count:
                showInfo(tr(TR.BROWSING_TAG_RENAME_WARNING_EMPTY))
                return

            self.browser.clearUnusedTags()

        self.mw.checkpoint(tr(TR.ACTIONS_RENAME_TAG))
        self.browser.model.beginReset()
        self.mw.taskman.run_in_background(do_rename, on_done)
Esempio n. 40
0
 def onReorder(self) -> None:
     n = len(self.templates)
     template = self.current_template()
     current_pos = self.templates.index(template) + 1
     pos_txt = getOnlyText(
         tr(TR.CARD_TEMPLATES_ENTER_NEW_CARD_POSITION_1, val=n),
         default=str(current_pos),
     )
     if not pos_txt:
         return
     try:
         pos = int(pos_txt)
     except ValueError:
         return
     if pos < 1 or pos > n:
         return
     if pos == current_pos:
         return
     new_idx = pos - 1
     if not self.change_tracker.mark_schema():
         return
     self.mm.reposition_template(self.model, template, new_idx)
     self.ord = new_idx
     self.redraw_everything()
Esempio n. 41
0
def onDeckBrowserDelayCards(did):
    deckManager = mw.col.decks
    deck_name = deckManager.name(did)
    cids = deckManager.cids(did, children=True)
    if not cids:
        tooltip("Deck contains no cards.")
        return
    cards = [Card(mw.col, cid) for cid in cids]

    days_to_delay = calculate_delay(did, cards)
    days_text = "days"

    if days_to_delay == 1:
        days_text = "day"

    confirm_response = askUser("The oldest card is {0} {1} overdue."
                               " Delay all cards by {0} {1}?"
                               "<br><br>If you press 'No' you will be able to manually enter"
                               " how many days to delay by.".format(days_to_delay, days_text),
                               defaultno=True, title="Confirm Delay")

    if not confirm_response:
        days_to_delay = getOnlyText("How many days would you like to delay? (Negative numbers will bring days forward)")

        if not days_to_delay:
            return
        try:
            days_to_delay = int(days_to_delay)
            if type(days_to_delay) != int:
                raise ValueError('Not a valid int')
                return
        except:
            showWarning("Please only enter whole numbers")
            return

    delay_cards(did, deckManager, cards, days_to_delay)
Esempio n. 42
0
def onReorder(self):
    """Asks user for a new position for current template. Move to this position if it is a valid position."""
    # difference: remove current position from list newTemplatesData and insert it in new position.
    n = len(self.cards)
    cur = self.ord + 1
    pos = getOnlyText(_("Enter new card position (1...%s):") % n,
                      default=str(cur))
    if not pos:
        return
    try:
        pos = int(pos)
    except ValueError:
        return
    if pos < 1 or pos > n:
        return
    if pos == cur:
        return
    pos -= 1
    self.mm.moveTemplate(self.model, self.card.template(), pos)
    originalMeta = self.newTemplatesData[self.ord]  # new
    del self.newTemplatesData[self.ord]  #new
    self.newTemplatesData.insert(pos, originalMeta)  #new
    self.ord = pos
    self.redraw()
def formatAbbr(editor):
    text = html.escape(getOnlyText(_("Full name:"), default=""))
    if not text:
        return
    editor.web.eval("""wrap("<abbr title='{}'>", "</abbr>")""".format(text))
Esempio n. 44
0
def abbr(editor):
    title = getOnlyText(_("Full text for the abbreviation:"), default="")
    title = html.escape(title)
    editor.web.eval("""wrap("<abbr title='{}'>", "</abbr>")""".format(title))
Esempio n. 45
0
 def renameGroup(self):
     name = getOnlyText(_("New name:"))
     if not name:
         return
     self.conf['name'] = name
     self.loadConfs()
Esempio n. 46
0
def getDelay():
    return RepresentsInt(
        getOnlyText(
            "How many day to add to cards ? (negative number to substract days)"
        ))
Esempio n. 47
0
def add_by_tag():
    tag = getOnlyText("Enter tag")
    add_cards(tag)
Esempio n. 48
0
 def renameGroup(self):
     name = getOnlyText(_("New name:"))
     if not name:
         return
     self.conf['name'] = name
     self.loadConfs()
Esempio n. 49
0
 def _onTreeFavModify(self, item):
     act = mw.col.conf['savedFilters'].get(item.fullname)
     if not act: return
     act = getOnlyText(_("New Search:"), default=act)
     if act:
         mw.col.conf['savedFilters'][item.fullname] = act
Esempio n. 50
0
            filt = conf[old_name]
        except KeyError:
            return
        if new_name in conf and not askUser(
                tr.browsing_confirm_saved_search_overwrite(name=new_name)):
            return
        conf[new_name] = filt
        del conf[old_name]
        self._set_saved_searches(conf)
        item.name = new_name
        self.refresh()

    def save_current_search(self) -> None:
        if (search := self._get_current_search()) is None:
            return
        name = getOnlyText(tr.browsing_please_give_your_filter_a_name())
        if not name:
            return
        self._save_search(name, search)

    def update_saved_search(self, item: SidebarItem) -> None:
        if (search := self._get_current_search()) is None:
            return
        self._save_search(item.name, search, update=True)

    # Notetypes and templates
    ####################################

    def manage_notetype(self, item: SidebarItem) -> None:
        Models(
            self.mw,
Esempio n. 51
0
            filt = conf[old_name]
        except KeyError:
            return
        if new_name in conf and not askUser(
                tr(TR.BROWSING_CONFIRM_SAVED_SEARCH_OVERWRITE, name=new_name)):
            return
        conf[new_name] = filt
        del conf[old_name]
        self._set_saved_searches(conf)
        self.refresh(lambda item: item.item_type == SidebarItemType.
                     SAVED_SEARCH and item.name == new_name)

    def save_current_search(self) -> None:
        if (search := self._get_current_search()) is None:
            return
        name = getOnlyText(tr(TR.BROWSING_PLEASE_GIVE_YOUR_FILTER_A_NAME))
        if not name:
            return
        self._save_search(name, search)

    def update_saved_search(self, item: SidebarItem) -> None:
        if (search := self._get_current_search()) is None:
            return
        self._save_search(item.name, search, update=True)

    # Notetypes and templates
    ####################################

    def manage_notetype(self, item: SidebarItem) -> None:
        Models(
            self.mw,
Esempio n. 52
0
def button_pressed(self):
    text = getOnlyText('Word definition')
    get_definition(self, text)