1

Removing state from anki host class

This commit is contained in:
Alex Yatskov 2012-12-23 17:50:49 -08:00
parent ce4b150848
commit 1a56e5c2a2
2 changed files with 9 additions and 19 deletions

View File

@ -21,14 +21,6 @@ import re
class Anki: class Anki:
def __init__(self, modelName=None):
self.setModelName(modelName)
def setModelName(self, modelName):
self.modelName = modelName
def addNote(self, fields, tags=unicode()): def addNote(self, fields, tags=unicode()):
note = self.createNote(fields, tags) note = self.createNote(fields, tags)
if not note: if not note:
@ -103,13 +95,11 @@ class Anki:
return self.models().allNames() return self.models().allNames()
def currentModel(self): def modelFieldNames(self, model):
for model in self.models().models.values():
if model['name'] == self.modelName:
return model
def currentModelFieldNames(self):
model = self.currentModel()
if model is not None:
return [field['name'] for field in model['flds']] return [field['name'] for field in model['flds']]
def findModel(self, name):
for model in self.models().models.values():
if model['name'] == name:
return model

View File

@ -146,6 +146,6 @@ class DialogPreferences(QtGui.QDialog):
def onAnkiModelChanged(self, index): def onAnkiModelChanged(self, index):
self.preferences.ankiModel = self.comboBoxAnkiModel.currentText() model = self.anki.findModel(self.comboBoxAnkiModel.currentText())
self.anki.setModelName(self.preferences.ankiModel) fieldNames = list() if model is None else self.anki.modelFieldNames(model)
self.setAnkiFields(self.anki.currentModelFieldNames(), self.preferences.ankiFields) self.setAnkiFields(fieldNames, self.preferences.ankiFields)