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:
def __init__(self, modelName=None):
self.setModelName(modelName)
def setModelName(self, modelName):
self.modelName = modelName
def addNote(self, fields, tags=unicode()):
note = self.createNote(fields, tags)
if not note:
@ -103,13 +95,11 @@ class Anki:
return self.models().allNames()
def currentModel(self):
def modelFieldNames(self, model):
return [field['name'] for field in model['flds']]
def findModel(self, name):
for model in self.models().models.values():
if model['name'] == self.modelName:
if model['name'] == name:
return model
def currentModelFieldNames(self):
model = self.currentModel()
if model is not None:
return [field['name'] for field in model['flds']]

View File

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