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
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
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)
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()
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
def getModel(self, id, create=True): "Return a local model with same ID, or create." for l in self.deck.models: if l.id == id: return l if not create: return m = Model() self.deck.models.append(m) return m
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"
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
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
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
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)
def ClozeModel(deck): m = Model(deck) m.name = _("Cloze") fm = m.newField() fm['name'] = _("Text") fm['req'] = True fm['uniq'] = True m.addField(fm) fm = m.newField() fm['name'] = _("Notes") m.addField(fm) for i in range(8): n = i+1 t = m.newTemplate() t['name'] = _("Cloze") + " %d" % n t['qfmt'] = ("{{#cloze:%d:Text}}<br>{{cloze:%d:%s}}<br>"+ "{{/cloze:%d:Text}}") % (n, n, _("Text"), n) t['afmt'] = ("{{cloze:%d:" + _("Text") + "}}") % n t['afmt'] += "<br>{{" + _("Notes") + "}}" m.addTemplate(t) return m
def BasicModel(deck): m = Model(deck) m.name = _("Basic") fm = m.newField() fm['name'] = _("Front") fm['req'] = True fm['uniq'] = True m.addField(fm) fm = m.newField() fm['name'] = _("Back") m.addField(fm) t = m.newTemplate() t['name'] = _("Forward") t['qfmt'] = "{{" + _("Front") + "}}" t['afmt'] = "{{" + _("Back") + "}}" m.addTemplate(t) t = m.newTemplate() t['name'] = _("Reverse") t['qfmt'] = "{{" + _("Back") + "}}" t['afmt'] = "{{" + _("Front") + "}}" t['actv'] = False m.addTemplate(t) return m
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