getting closer to being able to add facts
This commit is contained in:
parent
cd58fcfad4
commit
96ebd208fd
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
|
|
||||||
import aqt
|
import aqt
|
||||||
|
import anki.hooks
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
||||||
@ -26,51 +27,43 @@ class Anki:
|
|||||||
if not note:
|
if not note:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
note.model()['did'] = self.currentDeck()['id']
|
||||||
|
|
||||||
self.collection().addNote(note)
|
self.collection().addNote(note)
|
||||||
self.window().requireReset()
|
self.window().requireReset()
|
||||||
|
|
||||||
return note.id
|
return note.id
|
||||||
|
|
||||||
|
|
||||||
def canAddNote(self, fields):
|
def canAddNote(self, modelName, fields):
|
||||||
return bool(self.createNote(fields))
|
return bool(self.createNote(modelName, fields))
|
||||||
|
|
||||||
|
|
||||||
def createNote(self, deckName, modelName, fields, tags=unicode()):
|
def createNote(self, modelName, fields, tags=unicode()):
|
||||||
deck = self.findDeck(deckName)
|
|
||||||
if deck is None:
|
|
||||||
return None
|
|
||||||
|
|
||||||
model = self.findModel(modelName)
|
model = self.findModel(modelName)
|
||||||
if model is None:
|
if model is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
conf = self.collection().conf
|
||||||
|
deck = self.currentDeck()
|
||||||
|
|
||||||
|
if conf['curModel'] != model['id'] or deck['mid'] != model['id']:
|
||||||
|
conf['curModel'] = deck['mid'] = model['id']
|
||||||
|
self.collection().decks.save(deck)
|
||||||
|
anki.hooks.runHook('currentModelChanged')
|
||||||
|
self.window().reset()
|
||||||
|
|
||||||
note = self.collection().newNote()
|
note = self.collection().newNote()
|
||||||
note.tags = re.split('[;,\s]', tags)
|
note.tags = re.split('[;,\s]', tags)
|
||||||
note.model()['did'] = deck['id']
|
|
||||||
|
|
||||||
for name, value in fields.items():
|
for name, value in fields.items():
|
||||||
note[name] = value
|
note[name] = value
|
||||||
|
|
||||||
return None if note.dumpOrEmpty() else note
|
return None if note.dupeOrEmpty() else note
|
||||||
|
|
||||||
|
|
||||||
def setCurrentModel(self, modelName):
|
def browseNote(self, noteId):
|
||||||
#m = self.deck.models.byName(ret.name)
|
|
||||||
#self.deck.conf['curModel'] = m['id']
|
|
||||||
#cdeck = self.deck.decks.current()
|
|
||||||
#cdeck['mid'] = m['id']
|
|
||||||
#self.deck.decks.save(cdeck)
|
|
||||||
#runHook("currentModelChanged")
|
|
||||||
#self.mw.reset()
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def setCurrentDeck(self, deckName):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
#def browseNote(self, noteId):
|
|
||||||
#browser = ui.dialogs.get('CardList', self.window())
|
#browser = ui.dialogs.get('CardList', self.window())
|
||||||
#browser.dialog.filterEdit.setText('fid:' + str(noteId))
|
#browser.dialog.filterEdit.setText('fid:' + str(noteId))
|
||||||
#browser.updateSearch()
|
#browser.updateSearch()
|
||||||
|
@ -448,7 +448,7 @@ class MainWindowReader(QtGui.QMainWindow):
|
|||||||
self.comboTags.insertItem(0, tags)
|
self.comboTags.insertItem(0, tags)
|
||||||
self.preferences.updateFactTags(tags)
|
self.preferences.updateFactTags(tags)
|
||||||
|
|
||||||
factId = self.anki.addFact(fields, tags)
|
factId = self.anki.addNote(self.preferences.ankiDeck, self.preferences.ankiModel, fields, tags)
|
||||||
if not factId:
|
if not factId:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -471,7 +471,7 @@ class MainWindowReader(QtGui.QMainWindow):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
fields = reader_util.replaceMarkupInFields(self.preferences.ankiFields, markup)
|
fields = reader_util.replaceMarkupInFields(self.preferences.ankiFields, markup)
|
||||||
return self.anki.canAddFact(fields)
|
return self.anki.canAddNote(self.preferences.ankiModel, fields)
|
||||||
|
|
||||||
|
|
||||||
def updateSampleMouseEvent(self, event):
|
def updateSampleMouseEvent(self, event):
|
||||||
|
Loading…
Reference in New Issue
Block a user