From 1a56e5c2a20649d7123eb2fb6c3325c400879008 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 23 Dec 2012 17:50:49 -0800 Subject: [PATCH] Removing state from anki host class --- yomi_base/anki_host.py | 22 ++++++---------------- yomi_base/preferences.py | 6 +++--- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/yomi_base/anki_host.py b/yomi_base/anki_host.py index a19ef5b..f10a594 100644 --- a/yomi_base/anki_host.py +++ b/yomi_base/anki_host.py @@ -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']] diff --git a/yomi_base/preferences.py b/yomi_base/preferences.py index 477b60d..8e56cf1 100644 --- a/yomi_base/preferences.py +++ b/yomi_base/preferences.py @@ -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)