コード例 #1
0
ファイル: stdmodels.py プロジェクト: typerlc/ankice-deps
def HeisigModel():
    m = Model(_("Heisig"),
              _("""
A format suitable for Heisig's "Remembering the Kanji".
You are tested from the keyword to the kanji.

Layout of the test is based on the great work at
http://kanji.koohii.com/

The link in the question will list user-contributed
stories. A free login is required.""".strip()))
    font = u"Mincho"
    f = FieldModel(u'Kanji')
    f.quizFontSize = 150
    f.quizFontFamily = font
    f.editFontFamily = font
    m.addFieldModel(f)
    m.addFieldModel(FieldModel(u'Keyword'))
    m.addFieldModel(FieldModel(u'Story', u"", False, False))
    m.addFieldModel(FieldModel(u'Stroke count', u"", False, False))
    m.addFieldModel(FieldModel(u'Heisig number', required=False))
    m.addFieldModel(FieldModel(u'Lesson number', u"", False, False))
    m.addCardModel(CardModel(
        u"Production", _("From the keyword to the Kanji."),
        u"<a href=\"http://kanji.koohii.com/study?framenum="
        u"%(text:Heisig number)s\">%(Keyword)s</a><br>",
        u"%(Kanji)s<br><table width=150><tr><td align=left>"
        u"画数%(Stroke count)s</td><td align=right>"
        u"%(Heisig number)s</td></tr></table>"))
    m.tags = u"Heisig"
    return m
コード例 #2
0
ファイル: stdmodels.py プロジェクト: typerlc/ankice-deps
def MandarinModel():
    m = Model(_("Mandarin"),
              u"")
    f = FieldModel(u'Expression',
                   _('A word or expression written in Hanzi.'))
    f.quizFontSize = 72
    f.features = u"Reading source"
    m.addFieldModel(f)
    m.addFieldModel(FieldModel(
        u'Meaning', _(
        'A description in your native language, or Mandarin')))
    f = FieldModel(u'Reading',
                   _('Automatically generated by default.'),
                   False, False)
    f.features = u"Reading destination"
    m.addFieldModel(f)
    m.addCardModel(CardModel(u"Production", _(
        "Actively test your recall by producing the target expression"),
                             u"%(Meaning)s",
                             u"%(Expression)s<br>%(Reading)s"))
    m.addCardModel(CardModel(u"Recognition", _(
        "Test your ability to recognize the target expression"),
                             u"%(Expression)s",
                             u"%(Reading)s<br>%(Meaning)s"))
    m.features = u"Mandarin"
    m.tags = u"Mandarin"
    return m
コード例 #3
0
def RecoveryModel():
    m = Model(_('Recovery'))
    m.addFieldModel(FieldModel(u'Question', False, False))
    m.addFieldModel(FieldModel(u'Answer', False, False))
    m.addCardModel(CardModel(u'Single', u'{{{Question}}}', u'{{{Answer}}}'))
    m.tags = u"Recovery"
    return m
コード例 #4
0
ファイル: modelproperties.py プロジェクト: scout-zz/ankiqt
 def addField(self):
     f = FieldModel(required=False, unique=False)
     f.name = _("Field %d") % (len(self.m.fieldModels) + 1)
     self.deck.addFieldModel(self.m, f)
     self.updateFields()
     self.dialog.fieldList.setCurrentRow(len(self.m.fieldModels)-1)
     self.dialog.fieldName.setFocus()
     self.dialog.fieldName.selectAll()
コード例 #5
0
def doImport():
    # add an iknow model
    if not [m for m in mw.deck.models if m.name == 'Smart.fm']:
        m = Model(u'Smart.fm')
        m.addFieldModel(FieldModel(u'Expression', False, False))
        m.addFieldModel(FieldModel(u'Meaning', False, False))
        m.addFieldModel(FieldModel(u'Reading', False, False))
        m.addFieldModel(FieldModel(u'Audio', False, False))
        m.addFieldModel(FieldModel(u'Image', False, False))
        m.addCardModel(CardModel(
            u'Listening',
            u'Listen.%(Audio)s',
            u'%(Expression)s<br>%(Reading)s<br>%(Meaning)s<br>%(Image)s'))
        mw.deck.addModel(m)
    while 1:
        mw.reset()
        url = getOnlyText("Enter list URL:")
        if not url:
            return
        id = re.search("/lists/(\d+)", url).group(1)
        # get sentences
        f = urllib2.urlopen(
            "http://api.smart.fm/lists/%s/sentences.json" % id)
        d = simplejson.load(f)
        # add facts
        diag = QProgressDialog(_("Importing..."), "", 0, 0, mw)
        diag.setCancelButton(None)
        diag.setMaximum(len(d))
        diag.setMinimumDuration(0)
        for i, sen in enumerate(d):
            diag.setValue(i)
            diag.setLabelText(sen['text'])
            mw.app.processEvents()
            f = mw.deck.newFact()
            f['Expression'] = sen['text']
            f['Meaning'] = sen['translations'] and sen['translations'][0]['text'] or u""
            try:
                f['Reading'] = sen['transliterations']['Hrkt'] or u""
                # reading is sometimes missing
                if not f['Reading'] and kakasi:
                    f['Reading'] = kakasi.toFurigana(f['Expression'])
            except KeyError:
                f['Reading'] = u""
            if includeSounds and sen['sound']:
                (file, headers) = urllib.urlretrieve(sen['sound'])
                path = mw.deck.addMedia(file)
                f['Audio'] = u'[sound:%s]' % path
            else:
                f['Audio'] = u""
            if includeImages and sen['image']:
                (file, headers) = urllib.urlretrieve(sen['image'])
                path = mw.deck.addMedia(file)
                f['Image'] = u'<img src="%s">' % path
            else:
                f['Image'] = u""
            mw.deck.addFact(f)
        diag.cancel()
        mw.deck.save()
コード例 #6
0
ファイル: stdmodels.py プロジェクト: hobodrifterdavid/libanki
def BasicModel():
    m = Model(_('Basic'))
    m.addFieldModel(FieldModel(u'Front', True, True))
    m.addFieldModel(FieldModel(u'Back', False, False))
    m.addCardModel(CardModel(u'Forward', u'%(Front)s', u'%(Back)s'))
    m.addCardModel(CardModel(u'Reverse', u'%(Back)s', u'%(Front)s',
                             active=False))
    m.tags = u"Basic"
    return m
コード例 #7
0
ファイル: test_deck.py プロジェクト: hobodrifterdavid/libanki
def test_modelChange():
    deck = DeckStorage.Deck()
    m = Model(u"Japanese")
    m1 = m
    f = FieldModel(u'Expression', True, True)
    m.addFieldModel(f)
    m.addFieldModel(FieldModel(u'Meaning', False, False))
    f = FieldModel(u'Reading', False, False)
    m.addFieldModel(f)
    m.addCardModel(
        CardModel(u"Recognition", u"%(Expression)s",
                  u"%(Reading)s<br>%(Meaning)s"))
    m.addCardModel(
        CardModel(u"Recall",
                  u"%(Meaning)s",
                  u"%(Expression)s<br>%(Reading)s",
                  active=False))
    m.tags = u"Japanese"
    m1.cardModels[1].active = True
    deck.addModel(m1)
    f = deck.newFact()
    f['Expression'] = u'e'
    f['Meaning'] = u'm'
    f['Reading'] = u'r'
    f = deck.addFact(f)
    f2 = deck.newFact()
    f2['Expression'] = u'e2'
    f2['Meaning'] = u'm2'
    f2['Reading'] = u'r2'
    deck.addFact(f2)
    m2 = BasicModel()
    m2.cardModels[1].active = True
    deck.addModel(m2)
    # convert to basic
    assert deck.modelUseCount(m1) == 2
    assert deck.modelUseCount(m2) == 0
    assert deck.cardCount == 4
    assert deck.factCount == 2
    fmap = {
        m1.fieldModels[0]: m2.fieldModels[0],
        m1.fieldModels[1]: None,
        m1.fieldModels[2]: m2.fieldModels[1]
    }
    cmap = {m1.cardModels[0]: m2.cardModels[0], m1.cardModels[1]: None}
    deck.changeModel([f.id], m2, fmap, cmap)
    assert deck.modelUseCount(m1) == 1
    assert deck.modelUseCount(m2) == 1
    assert deck.cardCount == 3
    assert deck.factCount == 2
    (q, a) = deck.s.first("""
select question, answer from cards where factId = :id""",
                          id=f.id)
    assert stripHTML(q) == u"e"
    assert stripHTML(a) == u"r"
コード例 #8
0
ファイル: stdmodels.py プロジェクト: scout-zz/libanki
def MandarinModel():
    m = Model(_("Mandarin"))
    f = FieldModel(u"Expression")
    f.quizFontSize = 72
    m.addFieldModel(f)
    m.addFieldModel(FieldModel(u"Meaning", False, False))
    m.addFieldModel(FieldModel(u"Reading", False, False))
    m.addCardModel(CardModel(u"Recognition", u"%(Expression)s", u"%(Reading)s<br>%(Meaning)s"))
    m.addCardModel(CardModel(u"Recall", u"%(Meaning)s", u"%(Expression)s<br>%(Reading)s", active=False))
    m.tags = u"Mandarin"
    return m
コード例 #9
0
ファイル: chinese.py プロジェクト: TianYuanChu/AnkiCPRP
def CantoneseModel():
    m = Model(_("Cantonese"))
    f = FieldModel(u'Expression')
    f.quizFontSize = 72
    m.addFieldModel(f)
    m.addFieldModel(FieldModel(u'Meaning', False, False))
    m.addFieldModel(FieldModel(u'Reading', False, False))
    m.addCardModel(CardModel(u"Recognition",
                             u"%(Expression)s",
                             u"%(Reading)s<br>%(Meaning)s"))
    m.addCardModel(CardModel(u"Recall",
                             u"%(Meaning)s",
                             u"%(Expression)s<br>%(Reading)s",
                             active=False))
    m.tags = u"Cantonese"
    return m
コード例 #10
0
 def getFieldModel(self, model, remote):
     for fm in model.fieldModels:
         if fm.id == remote['id']:
             return fm
     fm = FieldModel()
     model.addFieldModel(fm)
     return fm
コード例 #11
0
 def MandarinModel():
    m = Model(_("Mandarin"))
    f = FieldModel(u'Expression')
    f.quizFontSize = 72
    m.addFieldModel(f)
    m.addFieldModel(FieldModel(u'Meaning', False, False))
    m.addFieldModel(FieldModel(u'Reading', False, False))
    m.addCardModel(CardModel(u"Recognition",
                             u"%(Expression)s",
                             u"%(Reading)s<br>%(Meaning)s"))
    m.addCardModel(CardModel(u"Recall",
                             u"%(Meaning)s",
                             u"%(Expression)s<br>%(Reading)s",
                             active=False))
    m.tags = u"Mandarin"
    return m
コード例 #12
0
ファイル: vocabModel.py プロジェクト: fenildf/gloss2deck
def VocabModel():
    m = Model(_("Vocab"))
    m.addFieldModel(FieldModel(u'Expression', True, False))
    m.addFieldModel(FieldModel(u'Reading', False, False))
    m.addFieldModel(FieldModel(u'Meaning', False, False))
    m.addFieldModel(FieldModel(u'From', False, False))
    
    m.addCardModel(CardModel(u"Recognition",
                             #Question side
                             u"%(Expression)s",
                             #Answer side
                             u"%(Reading)s<br>"+
                             u"%(Meaning)s<br>"+
                             u"%(From)s"))
    
    m.tags = u"Japanese Vocab Vocabulary"
    return m
コード例 #13
0
 def createModel(self, modelName, production, listening, reading):
     model = Model(modelName)
     model.addFieldModel(FieldModel(u'Expression', True, False))
     model.addFieldModel(FieldModel(u'Meaning', True, False))
     model.addFieldModel(FieldModel(u'Reading', False, False))
     model.addFieldModel(FieldModel(u'Audio', False, False))
     model.addFieldModel(FieldModel(u'Image_URI', False, False))
     model.addFieldModel(FieldModel(u'iKnowID', True, True))
     model.addFieldModel(FieldModel(u'iKnowType', False, False))
     if listening:
         model.addCardModel(CardModel(
             u'Listening',
             u'Listen.%(Audio)s',
             u'%(Expression)s<br>%(Reading)s<br>%(Meaning)s'))
     if production:
         model.addCardModel(CardModel(
             u'Production',
             u'%(Meaning)s<br>%(Image_URI)s',
             u'%(Expression)s<br>%(Reading)s<br>%(Audio)s'))
     if reading:
         model.addCardModel(CardModel(
             u'Reading',
             u'%(Expression)s',
             u'%(Reading)s<br>%(Meaning)s<br>%(Audio)s'))
     mw.deck.addModel(model)
コード例 #14
0
ファイル: dingsbums.py プロジェクト: hobodrifterdavid/libanki
    def createModel(self, attrs):
        """Makes a new Anki (fact) model from an entry type.
        The card models are made each time from scratch in order that evt. model specific fields (attributes) can make part."""
        m = Model(attrs["n"])
        # field model for standard fields
        m.addFieldModel(
            FieldModel(self.labels["b"], True,
                       False))  #there is no uniqueness check in DingsBums?!
        m.addFieldModel(FieldModel(self.labels["t"], True, False))
        for aField in ["exp", "ex", "pro", "rel"]:
            if self.visibility[aField] in "012":
                m.addFieldModel(FieldModel(self.labels[aField], False, False))
        # field models for attributes
        for attr in ["a1", "a2" "a3", "a4"]:
            if attr in attrs.keys():
                m.addFieldModel(
                    FieldModel(self.attributes[attrs[attr]], False, False))
                self.typeAttributes[attrs["eid"] + "_" +
                                    attr] = self.attributes[attrs[attr]]

        # card model for front
        frontStrings = ["%(" + self.labels["b"] + ")s"]
        backStrings = ["%(" + self.labels["t"] + ")s"]
        for aField in ["exp", "ex", "pro", "rel"]:
            if self.visibility[aField] in "01":
                frontStrings.append("%(" + self.labels[aField] + ")s")
            if self.visibility[aField] in "02":
                backStrings.append("%(" + self.labels[aField] + ")s")
        m.addCardModel(
            CardModel(u'Forward', "<br>".join(frontStrings),
                      "<br>".join(backStrings)))
        # card model for back
        m.addCardModel(
            CardModel(u'Reverse', unicode("%(" + self.labels["t"] + ")s"),
                      unicode("%(" + self.labels["b"] + ")s")))
        # tags is just the name without spaces
        m.tags = self.prepareTag(m.name)

        # link
        self.models[attrs["eid"]] = m
        self.deck.addModel(m)
コード例 #15
0
def test_localsync_models():
    client.sync()
    # add a model
    deck1.addModel(BasicModel())
    assert len(deck1.models) == 3
    assert len(deck2.models) == 2
    client.sync()
    assert len(deck2.models) == 3
    assert deck1.currentModel.id == deck2.currentModel.id
    # delete the recently added model
    deck2.deleteModel(deck2.currentModel)
    assert len(deck2.models) == 2
    client.sync()
    assert len(deck1.models) == 2
    assert deck1.currentModel.id == deck2.currentModel.id
    # make a card model inactive
    assert deck1.currentModel.cardModels[1].active == True
    deck2.currentModel.cardModels[1].active = False
    deck2.currentModel.setModified()
    deck2.setModified()
    client.sync()
    assert deck1.currentModel.cardModels[1].active == False
    # remove a card model
    deck1.deleteCardModel(deck1.currentModel, deck1.currentModel.cardModels[1])
    deck1.currentModel.setModified()
    deck1.setModified()
    assert len(deck1.currentModel.cardModels) == 1
    client.sync()
    assert len(deck2.currentModel.cardModels) == 1
    # add a field
    c = deck1.getCard()
    deck1.addFieldModel(c.fact.model, FieldModel(u"yo"))
    deck1.s.refresh(c.fact)
    assert len(c.fact.fields) == 3
    assert c.fact['yo'] == u""
    client.sync()
    c2 = deck2.s.query(Card).get(c.id)
    deck2.s.refresh(c2.fact)
    assert c2.fact['yo'] == u""
    # remove the field
    assert "yo" in c2.fact.keys()
    deck2.deleteFieldModel(c2.fact.model, c2.fact.model.fieldModels[2])
    deck2.s.refresh(c2.fact)
    assert "yo" not in c2.fact.keys()
    client.sync()
    deck1.s.refresh(c.fact)
    assert "yo" not in c.fact.keys()
    # rename a field
    assert u"Front" in c.fact.keys()
    deck1.renameFieldModel(deck1.currentModel,
                           deck1.currentModel.fieldModels[0], u"Sideways")
    client.sync()
    assert deck2.currentModel.fieldModels[0].name == u"Sideways"
コード例 #16
0
ファイル: stdmodels.py プロジェクト: typerlc/ankice-deps
def JapaneseModel():
    m = Model(_("Japanese"),
              _("""
The reading field is automatically generated by default,
and shows the reading for the expression. For words that
are normally written in hiragana or katakana and don't
need a reading, you can put the word in the expression
field, and leave the reading field blank. A reading will
will not automatically be generated for words written
in only hiragana or katakana.

Note that the automatic generation of meaning is not
perfect, and should be checked before adding cards.""".strip()))
    # expression
    f = FieldModel(u'Expression',
                   _('A word or expression written in Kanji.'), True, True)
    font = u"Mincho"
    f.quizFontSize = 72
    f.quizFontFamily = font
    f.editFontFamily = font
    f.features = u"Reading source"
    m.addFieldModel(f)
    # meaning
    m.addFieldModel(FieldModel(
        u'Meaning',
        _('A description in your native language, or Japanese'), True, True))
    # reading
    f = FieldModel(u'Reading',
                   _('Automatically generated by default.'), False, False)
    f.quizFontFamily = font
    f.editFontFamily = font
    f.features = u"Reading destination"
    m.addFieldModel(f)
    m.addCardModel(CardModel(u"Production", _(
        "Actively test your recall by producing the target expression"),
                             u"%(Meaning)s",
                             u"%(Expression)s<br>%(Reading)s"))
    m.addCardModel(CardModel(u"Recognition", _(
        "Test your ability to recognize the target expression"),
                        u"%(Expression)s",
                        u"%(Reading)s<br>%(Meaning)s"))
    m.features = u"Japanese"
    m.tags = u"Japanese"
    return m
コード例 #17
0
def EnglishModel():
    m = Model(_("English"))

    tempFieldModel = FieldModel(u'English Word', False, False)
    tempFieldModel.editFontSize = 14
    m.addFieldModel(tempFieldModel)
    tempFieldModel = FieldModel(u'Chinese Definition', False, False)
    tempFieldModel.editFontSize = 16
    m.addFieldModel(tempFieldModel)
    tempFieldModel = FieldModel(u'English Definition', False, False)
    tempFieldModel.editFontSize = 14
    m.addFieldModel(tempFieldModel)
    tempFieldModel = FieldModel(u'English Pronunciation', False, False)
    tempFieldModel.editFontSize = 14
    m.addFieldModel(tempFieldModel)
    tempFieldModel = FieldModel(u'Example Sentence', False, False)
    tempFieldModel.editFontSize = 14
    m.addFieldModel(tempFieldModel)
    m.addCardModel(CardModel(u"Recognition",
                             u"%(English Word)s",
                             u"%(Chinese Definition)s<br />%(English Definition)s<br />%(English Pronunciation)s \
                                <br /><font color='red'>%(Example Sentence)s</font>"))
    m.tags = u"English"
    return m
コード例 #18
0
 def ensureKanjiModelExists(self):
     model = None
     for m in mw.deck.models:
         if m.name.lower() == RTKImportDialog.KANJI_MODEL.lower():
             return m
     if not model:
         model = Model(RTKImportDialog.KANJI_MODEL)
         model.addFieldModel(FieldModel(u'Kanji', True, True))
         model.addFieldModel(FieldModel(u'HeisigFrameID', True, True))
         model.addFieldModel(FieldModel(u'Keyword', True, True))
         model.addFieldModel(FieldModel(u'Story', True, True))
         model.addFieldModel(FieldModel(u'PrimitiveMeanings', False, False))
         model.addFieldModel(
             FieldModel(u'Image_StrokeOrderDiagram', False, False))
         model.addFieldModel(
             FieldModel(u'Image_StrokeOrderAnimation', False, False))
         model.addCardModel(
             CardModel(
                 u'Remembering', u'%(Keyword)s',
                 u'%(Kanji)s<br>%(Story)s<br>%(PrimitiveMeanings)s<br>%(Image_StrokeOrderAnimation)s<br>%(Image_StrokeOrderDiagram)s'
             ))
         mw.deck.addModel(model)
     return model
コード例 #19
0
ファイル: model.py プロジェクト: fqhuy/JpEnVi_Anki
def JpEnViModel():
    m = Model(_("JpEnVi"))
    # expression
    f = FieldModel(u'Japanese', True, True)
    font = u"Mincho"
    f.quizFontSize = 50
    f.quizFontFamily = font
    f.editFontFamily = font
    m.addFieldModel(f)
    # meaning
    f = FieldModel(u'English', False, False)
    font = u"Mincho"
    f.quizFontSize = 20
    f.quizFontFamily = font
    f.editFontFamily = font
    m.addFieldModel(f)
    # reading
    f = FieldModel(u'Sino-Vietnamese', False, False)  #for Kanji only (?)
    font = u"Arial"
    f.quizFontSize = 20
    f.quizFontFamily = font
    f.editFontFamily = font
    m.addFieldModel(f)
    #vietnamese
    f = FieldModel(u'Vietnamese', False, False)
    font = u"Mincho"
    f.quizFontSize = 20
    f.quizFontFamily = font
    f.editFontFamily = font
    m.addFieldModel(f)

    f = FieldModel(u'Example', False, False)
    font = u"Mincho"
    f.quizFontSize = 20
    f.quizFontFamily = font
    f.editFontFamily = font
    m.addFieldModel(f)

    m.addCardModel(
        CardModel(
            u"Recognition", u"%(Japanese)s",
            u"<div align='left'>English</div><hr> <br> %(English)s <div align='left'>Sino-Vietnamese</div><hr><br>%(Sino-Vietnamese)s <div align='left'>Vietnamese</div><hr><br>%(Vietnamese)s <div align='left'>Examples from tratu.vn</div><hr><br>%(Example)s"
        ))
    m.addCardModel(
        CardModel(u"Recall", u"%(Vietnamese)s", u"%(Japanese)s", active=False))

    m.tags = u"JpEnVi, JpEnVi_offline"
    return m
コード例 #20
0
ファイル: anki03.py プロジェクト: typerlc/ankice-deps
 def doImport(self):
     oldDeck = load(self.file)
     maybeUpgrade(oldDeck)
     # mappings for old->new ids
     cardModels = {}
     fieldModels = {}
     # start with the models
     s = self.deck.s
     deck = self.deck
     import types
     def uni(txt):
         if txt is None:
             return txt
         if not isinstance(txt, types.UnicodeType):
             txt = unicode(txt, "utf-8")
         return txt
     for oldModel in oldDeck.facts.models:
         model = Model(uni(oldModel.name), uni(oldModel.description))
         model.id = oldModel.id
         model.tags = u", ".join(oldModel.tags)
         model.features = u", ".join(oldModel.decorators)
         model.created = oldModel.created
         model.modified = oldModel.modified
         deck.newCardOrder = min(1, oldModel.position)
         deck.addModel(model)
         # fields
         for oldField in oldModel.fields:
             fieldModel = FieldModel(uni(oldField.name),
                                     uni(oldField.description),
                                     oldField.name in oldModel.required,
                                     oldField.name in oldModel.unique)
             fieldModel.features = u", ".join(oldField.features)
             fieldModel.quizFontFamily = uni(oldField.display['quiz']['fontFamily'])
             fieldModel.quizFontSize = oldField.display['quiz']['fontSize']
             fieldModel.quizFontColour = uni(oldField.display['quiz']['fontColour'])
             fieldModel.editFontFamily = uni(oldField.display['edit']['fontFamily'])
             fieldModel.editFontSize = oldField.display['edit']['fontSize']
             fieldModel.id = oldField.id
             model.addFieldModel(fieldModel)
             s.flush() # we need the id
             fieldModels[id(oldField)] = fieldModel
         # card models
         for oldCard in oldModel.allcards:
             cardModel = CardModel(uni(oldCard.name),
                                   uni(oldCard.description),
                                   uni(oldCard.qformat),
                                   uni(oldCard.aformat))
             cardModel.active = oldCard in oldModel.cards
             cardModel.questionInAnswer = oldCard.questionInAnswer
             cardModel.id = oldCard.id
             model.spacing = 0.25
             cardModel.questionFontFamily = uni(oldCard.display['question']['fontFamily'])
             cardModel.questionFontSize = oldCard.display['question']['fontSize']
             cardModel.questionFontColour = uni(oldCard.display['question']['fontColour'])
             cardModel.questionAlign = oldCard.display['question']['align']
             cardModel.answerFontFamily = uni(oldCard.display['answer']['fontFamily'])
             cardModel.answerFontSize = oldCard.display['answer']['fontSize']
             cardModel.answerFontColour = uni(oldCard.display['answer']['fontColour'])
             cardModel.answerAlign = oldCard.display['answer']['align']
             cardModel.lastFontFamily = uni(oldCard.display['last']['fontFamily'])
             cardModel.lastFontSize = oldCard.display['last']['fontSize']
             cardModel.lastFontColour = uni(oldCard.display['last']['fontColour'])
             cardModel.editQuestionFontFamily = (
                 uni(oldCard.display['editQuestion']['fontFamily']))
             cardModel.editQuestionFontSize = (
                 oldCard.display['editQuestion']['fontSize'])
             cardModel.editAnswerFontFamily = (
                 uni(oldCard.display['editAnswer']['fontFamily']))
             cardModel.editAnswerFontSize = (
                 oldCard.display['editAnswer']['fontSize'])
             model.addCardModel(cardModel)
             s.flush() # we need the id
             cardModels[id(oldCard)] = cardModel
     # facts
     def getSpace(lastCard, lastAnswered):
         if not lastCard:
             return 0
         return lastAnswered + lastCard.delay
     def getLastCardId(fact):
         if not fact.lastCard:
             return None
         ret = [c.id for c in fact.cards if c.model.id == fact.lastCard.id]
         if ret:
             return ret[0]
     d = [{'id': f.id,
           'modelId': f.model.id,
           'created': f.created,
           'modified': f.modified,
           'tags': u",".join(f.tags),
           'spaceUntil': getSpace(f.lastCard, f.lastAnswered),
           'lastCardId': getLastCardId(f)
           } for f in oldDeck.facts]
     if d:
         s.execute(factsTable.insert(), d)
     self.total = len(oldDeck.facts)
     # fields in facts
     toAdd = []
     for oldFact in oldDeck.facts:
         for field in oldFact.model.fields:
             toAdd.append({'factId': oldFact.id,
                           'id': genID(),
                           'fieldModelId': fieldModels[id(field)].id,
                           'ordinal': fieldModels[id(field)].ordinal,
                           'value': uni(oldFact.get(field.name, u""))})
     if toAdd:
         s.execute(fieldsTable.insert(), toAdd)
     # cards
     class FakeObj(object):
         pass
     fake = FakeObj()
     fake.fact = FakeObj()
     fake.fact.model = FakeObj()
     fake.cardModel = FakeObj()
     def renderQA(c, type):
         fake.tags = u", ".join(c.tags)
         fake.fact.tags = u", ".join(c.fact.tags)
         fake.fact.model.tags = u", ".join(c.fact.model.tags)
         fake.cardModel.name = c.model.name
         return cardModels[id(c.model)].renderQA(fake, c.fact, type)
     d = [{'id': c.id,
           'created': c.created,
           'modified': c.modified,
           'factId': c.fact.id,
           'ordinal': cardModels[id(c.model)].ordinal,
           'cardModelId': cardModels[id(c.model)].id,
           'tags': u", ".join(c.tags),
           'factor': 2.5,
           'firstAnswered': c.firstAnswered,
           'interval': c.interval,
           'lastInterval': c.lastInterval,
           'modified': c.modified,
           'due': c.nextTime,
           'lastDue': c.lastTime,
           'reps': c.total,
           'question': renderQA(c, 'question'),
           'answer': renderQA(c, 'answer'),
           'averageTime': c.stats['averageTime'],
           'reviewTime': c.stats['totalTime'],
           'yesCount': (c.stats['new']['yes'] +
                        c.stats['young']['yes'] +
                        c.stats['old']['yes']),
           'noCount': (c.stats['new']['no'] +
                       c.stats['young']['no'] +
                       c.stats['old']['no']),
           'successive': c.stats['successivelyCorrect']}
          for c in oldDeck]
     if d:
         s.execute(cardsTable.insert(), d)
     # scheduler
     deck.description = uni(oldDeck.description)
     deck.created = oldDeck.created
     deck.maxScheduleTime = oldDeck.sched.maxScheduleTime
     deck.hardIntervalMin = oldDeck.sched.hardInterval[0]
     deck.hardIntervalMax = oldDeck.sched.hardInterval[1]
     deck.midIntervalMin = oldDeck.sched.midInterval[0]
     deck.midIntervalMax = oldDeck.sched.midInterval[1]
     deck.easyIntervalMin = oldDeck.sched.easyInterval[0]
     deck.easyIntervalMax = oldDeck.sched.easyInterval[1]
     deck.delay0 = oldDeck.sched.delay0
     deck.delay1 = oldDeck.sched.delay1
     deck.delay2 = oldDeck.sched.delay2
     deck.collapseTime = 3600 # oldDeck.sched.collapse
     deck.highPriority = u", ".join(oldDeck.sched.highPriority)
     deck.medPriority = u", ".join(oldDeck.sched.medPriority)
     deck.lowPriority = u", ".join(oldDeck.sched.lowPriority)
     deck.suspended = u", ".join(oldDeck.sched.suspendedTags)
     # scheduler global stats
     stats = Stats(STATS_LIFE)
     stats.day = datetime.date.fromtimestamp(oldDeck.created)
     stats.averageTime = oldDeck.sched.globalStats['averageTime']
     stats.reviewTime = oldDeck.sched.globalStats['totalTime']
     stats.distractedTime = 0
     stats.distractedReps = 0
     stats.newEase0 = oldDeck.sched.easeStats.get('new', {}).get(0, 0)
     stats.newEase1 = oldDeck.sched.easeStats.get('new', {}).get(1, 0)
     stats.newEase2 = oldDeck.sched.easeStats.get('new', {}).get(2, 0)
     stats.newEase3 = oldDeck.sched.easeStats.get('new', {}).get(3, 0)
     stats.newEase4 = oldDeck.sched.easeStats.get('new', {}).get(4, 0)
     stats.youngEase0 = oldDeck.sched.easeStats.get('young', {}).get(0, 0)
     stats.youngEase1 = oldDeck.sched.easeStats.get('young', {}).get(1, 0)
     stats.youngEase2 = oldDeck.sched.easeStats.get('young', {}).get(2, 0)
     stats.youngEase3 = oldDeck.sched.easeStats.get('young', {}).get(3, 0)
     stats.youngEase4 = oldDeck.sched.easeStats.get('young', {}).get(4, 0)
     stats.matureEase0 = oldDeck.sched.easeStats.get('old', {}).get(0, 0)
     stats.matureEase1 = oldDeck.sched.easeStats.get('old', {}).get(1, 0)
     stats.matureEase2 = oldDeck.sched.easeStats.get('old', {}).get(2, 0)
     stats.matureEase3 = oldDeck.sched.easeStats.get('old', {}).get(3, 0)
     stats.matureEase4 = oldDeck.sched.easeStats.get('old', {}).get(4, 0)
     yesCount = (oldDeck.sched.globalStats['new']['yes'] +
                 oldDeck.sched.globalStats['young']['yes'] +
                 oldDeck.sched.globalStats['old']['yes'])
     noCount = (oldDeck.sched.globalStats['new']['no'] +
                oldDeck.sched.globalStats['young']['no'] +
                oldDeck.sched.globalStats['old']['no'])
     stats.reps = yesCount + noCount
     s.save(stats)
     # ignore daily stats & history, they make no sense on new version
     s.flush()
     deck.updateAllPriorities()
     # save without updating mod time
     deck.modified = oldDeck.modified
     deck.lastLoaded = deck.modified
     deck.s.commit()
     deck.save()
コード例 #21
0
ファイル: model.py プロジェクト: lahorichargha/ankiplugins
def JapaneseModel():
    m = Model(_("Japanese"))
    # expression
    f = FieldModel(u'Expression', True, True)
    font = u"Mincho"
    f.quizFontSize = 50
    f.quizFontFamily = font
    f.editFontFamily = font
    m.addFieldModel(f)
    # meaning
    m.addFieldModel(FieldModel(u'Meaning', False, False))
    # reading
    f = FieldModel(u'Reading', False, False)
    font = u"Arial"
    f.quizFontSize = 50
    f.quizFontFamily = font
    f.editFontFamily = font
    m.addFieldModel(f)
    m.addCardModel(CardModel(u"Recognition",
                   u"%(Expression)s",
                   u"%(Reading)s<br>%(Meaning)s"))
    m.addCardModel(CardModel(u"Recall",
                             u"%(Meaning)s",
                             u"%(Reading)s",
                             active=False))
    m.tags = u"Japanese"
    return m
コード例 #22
0
    def saveConfig(self):
        
        interface = self.interface
        
        if interface.languageCombo.currentIndex() <= 0:
            # Error : marked in red + Error message
            return
        if interface.expressionCombo.currentIndex() <= 0:
            # Error : marked in red + Error message
            return
        
        if interface.defintionCB.isChecked() and interface.definitionCombo.currentIndex() <= 0:
            # Error : ...
            return
        
        mainVBox = interface.mainVBox
        deck = interface.deck
        realDeck = AnkiHelper.getDeck(deck.path)
        
        # Save Fields
        for fieldsGrid in interface.fieldsComponents:
            
            isEnabled = fieldsGrid[0].isChecked()
            value = str(fieldsGrid[1].text())
            key = str(fieldsGrid[0].text())
            
            numeric = deck.fields[key][2]

            models = realDeck.models
            
            deck.fields[key] = (value, isEnabled, numeric)
            
            if isEnabled:
                for model in models:
                    
                    field = FieldModel(unicode(value, "utf-8"), False, False)
                    font = u"Arial"
                    field.quizFontSize = 22
                    field.quizFontFamily = font
                    field.editFontSize = 20
                    field.editFontFamily = font
                    field.numeric = numeric

                    log("add fields")
                    try:
                        fieldModelAlreadyAdded = False
                        for fieldModel in model.fieldModels:
                            if fieldModel.name == value:
                                fieldModelAlreadyAdded = True
                                break
                            
                        if not fieldModelAlreadyAdded:
                            realDeck.addFieldModel(model, field) 
                    except Exception as e:
                        log(e)
            else:
                for model in models:
                    try:
                        fieldToDelete = None
                        for fieldModel in model.fieldModels:
                            if fieldModel.name == value:
                                fieldToDelete = fieldModel
                                break
                            
                        if fieldToDelete != None:
                            realDeck.deleteFieldModel(model, fieldToDelete)
                    except Exception as e:
                        log(e)
        
        self.decksService.changeLanguage(interface.deck, unicode(interface.languageCombo.currentText()))
        
        deck.matureTreshold = int(str(interface.matureEdit.text()))
        deck.knownTreshold = int(str(interface.knownEdit.text()))
        deck.learnTreshold = int(str(interface.learnEdit.text()))
        deck.expressionField = str(interface.expressionCombo.currentText())
        
        bsPosListWidget = interface.bsPosListWidget
        disabledPosList = list()
        items = bsPosListWidget.findItems("*", Qt.MatchWrap | Qt.MatchWildcard)
        for item in items:
            log(item)
            disabledPosList.append(unicode(item.text()))
        deck.posOptions["disabledPos"] = disabledPosList
        
        if interface.defintionCB.isChecked():
            deck.definitionField = str(interface.definitionCombo.currentText())
            if interface.definitionKeyCombo.currentIndex() > 0:
                deck.definitionKeyField = str(interface.definitionKeyCombo.currentText())
            else:
                deck.definitionKeyField = None
        
        self.decksService.updateDeck(deck)
        
        realDeck.save()
        realDeck.close()
        
        interface.parent.refreshAll()
        interface.close()