WIP
This commit is contained in:
parent
cee629407c
commit
19d4bf922f
@ -187,11 +187,15 @@ class AjaxServer:
|
|||||||
class AnkiBridge:
|
class AnkiBridge:
|
||||||
def addNote(self, deckName, modelName, fields, tags=[]):
|
def addNote(self, deckName, modelName, fields, tags=[]):
|
||||||
note = self.createNote(deckName, modelName, fields, tags)
|
note = self.createNote(deckName, modelName, fields, tags)
|
||||||
if note is not None:
|
if note is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
self.startEditing()
|
||||||
|
|
||||||
collection = self.collection()
|
collection = self.collection()
|
||||||
collection.addNote(note)
|
collection.addNote(note)
|
||||||
collection.autosave()
|
collection.autosave()
|
||||||
self.startEditing()
|
|
||||||
return note.id
|
return note.id
|
||||||
|
|
||||||
|
|
||||||
@ -202,11 +206,11 @@ class AnkiBridge:
|
|||||||
def createNote(self, deckName, modelName, fields, tags=[]):
|
def createNote(self, deckName, modelName, fields, tags=[]):
|
||||||
model = self.models().byName(modelName)
|
model = self.models().byName(modelName)
|
||||||
if model is None:
|
if model is None:
|
||||||
return None
|
return
|
||||||
|
|
||||||
deck = self.decks().byName(deckName)
|
deck = self.decks().byName(deckName)
|
||||||
if deck is None:
|
if deck is None:
|
||||||
return None
|
return
|
||||||
|
|
||||||
note = anki.notes.Note(self.collection(), model)
|
note = anki.notes.Note(self.collection(), model)
|
||||||
note.model()['did'] = deck['id']
|
note.model()['did'] = deck['id']
|
||||||
@ -239,10 +243,6 @@ class AnkiBridge:
|
|||||||
return aqt.mw
|
return aqt.mw
|
||||||
|
|
||||||
|
|
||||||
def addUiAction(self, action):
|
|
||||||
self.window().form.menuTools.addAction(action)
|
|
||||||
|
|
||||||
|
|
||||||
def collection(self):
|
def collection(self):
|
||||||
return self.window().col
|
return self.window().col
|
||||||
|
|
||||||
@ -294,6 +294,28 @@ class AnkiConnect:
|
|||||||
return getattr(self, action)(**request.get('params', {}))
|
return getattr(self, action)(**request.get('params', {}))
|
||||||
|
|
||||||
|
|
||||||
|
def api_deckNames(self):
|
||||||
|
return self.anki.deckNames()
|
||||||
|
|
||||||
|
|
||||||
|
def api_modelNames(self):
|
||||||
|
return self.anki.modelNames()
|
||||||
|
|
||||||
|
|
||||||
|
def api_modelFieldNames(self, modelName):
|
||||||
|
return self.anki.modelFieldNames(modelName)
|
||||||
|
|
||||||
|
|
||||||
|
def api_features(self):
|
||||||
|
features = {}
|
||||||
|
for name in dir(self):
|
||||||
|
method = getattr(self, name)
|
||||||
|
if name.startswith('api_') and callable(method):
|
||||||
|
features[name[4:]] = list(method.func_code.co_varnames[1:])
|
||||||
|
|
||||||
|
return features
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Entry
|
# Entry
|
||||||
#
|
#
|
||||||
|
Loading…
Reference in New Issue
Block a user